Skip to content

Commit

Permalink
more subcommands
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Downs <[email protected]>
  • Loading branch information
briandowns committed Jan 11, 2024
1 parent d074530 commit 0ac25d8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 35 deletions.
47 changes: 27 additions & 20 deletions cmd/release/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,36 @@ var generateCmd = &cobra.Command{
rootCmd.Help()
os.Exit(0)
}
},
}

var k3sGenerateSubCmd = &cobra.Command{
Use: "k3s",
Short: "",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

var (
owner string
repo string
)

switch args[0] {
case "k3s":
if args[1] == "release-notes" {
owner = "k3s-io"
repo = "k3s"
}
case "rke2":
if args[1] == "release-notes" {
owner = "rancher"
repo = "rke2"
}
default:
rootCmd.Help()
os.Exit(0)
notes, err := release.GenReleaseNotes(ctx, "k3s-io", "k3s", *milestone, *prevMilestone, client)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

notes, err := release.GenReleaseNotes(ctx, owner, repo, *milestone, *prevMilestone, client)
fmt.Print(notes.String())
},
}

var rke2GenerateSubCmd = &cobra.Command{
Use: "rke2",
Short: "",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

notes, err := release.GenReleaseNotes(ctx, "rancher", "rke2", *milestone, *prevMilestone, client)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -63,6 +67,9 @@ var generateCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(generateCmd)

generateCmd.AddCommand(k3sGenerateSubCmd)
generateCmd.AddCommand(rke2GenerateSubCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand Down
38 changes: 25 additions & 13 deletions cmd/release/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,44 @@ var tagCmd = &cobra.Command{
rootCmd.Help()
os.Exit(0)
}
},
}

var k3sTagSubCmd = &cobra.Command{
Use: "k3s",
Short: "",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Here we are!")
},
}

var rke2TagSubCmd = &cobra.Command{
Use: "rke2",
Short: "",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

switch args[0] {
case "k3s":
case "rke2":
switch args[1] {
case "image-build-kubernetes":
if err := rke2.ImageBuildBaseRelease(ctx, client, *alpineVersion, false); err != nil {
fmt.Println(err)
os.Exit(1)
}

fmt.Println("Successfully tagged")
case "image-build-kubernetes":
if err := rke2.ImageBuildBaseRelease(ctx, client, *alpineVersion, false); err != nil {
fmt.Println(err)
os.Exit(1)
}
default:
rootCmd.Help()
os.Exit(0)

fmt.Println("Successfully tagged")
}
},
}

func init() {
rootCmd.AddCommand(tagCmd)

tagCmd.AddCommand(k3sTagSubCmd)
tagCmd.AddCommand(rke2TagSubCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ require (

require (
github.com/MetalBlueberry/go-plotly v0.4.0
github.com/spf13/cobra v1.8.0
github.com/urfave/cli/v2 v2.25.7
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)

Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down

0 comments on commit 0ac25d8

Please sign in to comment.