Skip to content

Commit 121f349

Browse files
committed
kepctl: Update references to refactored packages
Signed-off-by: Stephen Augustus <[email protected]>
1 parent 6e7b0e1 commit 121f349

File tree

9 files changed

+257
-209
lines changed

9 files changed

+257
-209
lines changed

cmd/kepctl/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ limitations under the License.
1616

1717
package main
1818

19-
import "k8s.io/enhancements/cmd/kepctl/cmd"
19+
import "k8s.io/enhancements/pkg/kepctl/commands"
2020

2121
func main() {
22-
cmd.Execute()
22+
commands.New().Execute()
2323
}

pkg/kepctl/commands/commands.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,51 @@ import (
2020
"fmt"
2121
"os"
2222

23-
"github.com/sirupsen/logrus"
2423
"github.com/spf13/cobra"
2524

26-
"k8s.io/enhancements/pkg/repo"
25+
"k8s.io/enhancements/pkg/kepctl"
2726
"k8s.io/release/pkg/log"
2827
)
2928

30-
// rootCmd represents the base command when called without any subcommands
31-
var rootCmd = &cobra.Command{
32-
Use: "kepctl",
33-
Short: "kepctl helps you build KEPs",
34-
PersistentPreRunE: initLogging,
35-
}
36-
37-
var rootOpts = &repo.Options{}
29+
var rootOpts = &kepctl.Options{}
3830

39-
// Execute adds all child commands to the root command and sets flags appropriately.
40-
// This is called by main.main(). It only needs to happen once to the rootCmd.
41-
func Execute() {
42-
if err := rootCmd.Execute(); err != nil {
43-
logrus.Fatal(err)
31+
func New() *cobra.Command {
32+
cmd := &cobra.Command{
33+
Use: "kepctl",
34+
Short: "kepctl helps you build KEPs",
35+
PersistentPreRunE: initLogging,
4436
}
45-
}
4637

47-
func init() {
48-
rootCmd.PersistentFlags().StringVar(
38+
cmd.PersistentFlags().StringVar(
4939
&rootOpts.LogLevel,
5040
"log-level",
5141
"info",
5242
fmt.Sprintf("the logging verbosity, either %s", log.LevelNames()),
5343
)
5444

5545
// TODO: This should be defaulted in the package instead
56-
rootCmd.PersistentFlags().StringVar(
46+
cmd.PersistentFlags().StringVar(
5747
&rootOpts.RepoPath,
5848
"repo-path",
5949
os.Getenv("ENHANCEMENTS_PATH"),
6050
"path to kubernetes/enhancements",
6151
)
6252

63-
rootCmd.PersistentFlags().StringVar(
53+
cmd.PersistentFlags().StringVar(
6454
&rootOpts.TokenPath,
6555
"gh-token-path",
6656
"",
6757
"path to a file with a GitHub API token",
6858
)
59+
60+
AddCommands(cmd)
61+
return cmd
62+
}
63+
64+
func AddCommands(topLevel *cobra.Command) {
65+
addCreate(topLevel)
66+
addPromote(topLevel)
67+
addQuery(topLevel)
6968
}
7069

7170
func initLogging(*cobra.Command, []string) error {

pkg/kepctl/commands/create.go

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,84 +24,85 @@ import (
2424
"k8s.io/enhancements/pkg/repo"
2525
)
2626

27-
// TODO: Struct literal instead?
28-
var createOpts = proposal.CreateOpts{}
29-
30-
var createCmd = &cobra.Command{
31-
Use: "create [KEP]",
32-
Short: "Create a new KEP",
33-
Long: "Create a new KEP using the current KEP template for the given type",
34-
Example: ` kepctl create sig-architecture/000-mykep`,
35-
SilenceUsage: true,
36-
SilenceErrors: true,
37-
PreRunE: func(cmd *cobra.Command, args []string) error {
38-
return createOpts.Validate(args)
39-
},
40-
RunE: func(*cobra.Command, []string) error {
41-
return runCreate(&createOpts)
42-
},
43-
}
27+
func addCreate(topLevel *cobra.Command) {
28+
co := proposal.CreateOpts{}
29+
30+
cmd := &cobra.Command{
31+
Use: "create [KEP]",
32+
Short: "Create a new KEP",
33+
Long: "Create a new KEP using the current KEP template for the given type",
34+
Example: ` kepctl create sig-architecture/000-mykep`,
35+
SilenceUsage: true,
36+
SilenceErrors: true,
37+
PreRunE: func(cmd *cobra.Command, args []string) error {
38+
return co.Validate(args)
39+
},
40+
RunE: func(*cobra.Command, []string) error {
41+
return runCreate(&co)
42+
},
43+
}
4444

45-
func init() {
4645
// TODO: Should these all be global args?
47-
createCmd.PersistentFlags().StringVar(
48-
&createOpts.Title,
46+
cmd.PersistentFlags().StringVar(
47+
&co.Title,
4948
"title",
5049
"",
5150
"KEP Title",
5251
)
5352

54-
createCmd.PersistentFlags().StringArrayVar(
55-
&createOpts.Authors,
53+
cmd.PersistentFlags().StringArrayVar(
54+
&co.Authors,
5655
"authors",
5756
[]string{},
5857
"Authors",
5958
)
6059

61-
createCmd.PersistentFlags().StringArrayVar(
62-
&createOpts.Reviewers,
60+
cmd.PersistentFlags().StringArrayVar(
61+
&co.Reviewers,
6362
"reviewers",
6463
[]string{},
6564
"Reviewers",
6665
)
6766

68-
createCmd.PersistentFlags().StringVar(
69-
&createOpts.Type,
67+
cmd.PersistentFlags().StringVar(
68+
&co.Type,
7069
"type",
7170
"feature",
7271
"KEP Type",
7372
)
7473

75-
createCmd.PersistentFlags().StringVarP(
76-
&createOpts.State,
74+
cmd.PersistentFlags().StringVarP(
75+
&co.State,
7776
"state",
7877
"s",
7978
"provisional",
8079
"KEP State",
8180
)
8281

83-
createCmd.PersistentFlags().StringArrayVar(
84-
&createOpts.SIGS,
82+
cmd.PersistentFlags().StringArrayVar(
83+
&co.SIGS,
8584
"sigs",
8685
[]string{},
8786
"Participating SIGs",
8887
)
8988

90-
createCmd.PersistentFlags().StringArrayVar(
91-
&createOpts.PRRApprovers,
89+
cmd.PersistentFlags().StringArrayVar(
90+
&co.PRRApprovers,
9291
"prr-approver",
9392
[]string{},
9493
"PRR Approver",
9594
)
9695

97-
rootCmd.AddCommand(createCmd)
96+
topLevel.AddCommand(cmd)
9897
}
9998

10099
func runCreate(opts *proposal.CreateOpts) error {
101-
rc, err := repo.New(opts.Repo.BasePath)
100+
rc, err := repo.New(rootOpts.RepoPath)
102101
if err != nil {
103102
return errors.Wrap(err, "creating repo client")
104103
}
105104

106-
return proposal.Create(rc, opts)
105+
opts.Repo = rc
106+
107+
return proposal.Create(opts)
107108
}

pkg/kepctl/commands/promote.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,50 +24,51 @@ import (
2424
"k8s.io/enhancements/pkg/repo"
2525
)
2626

27-
// TODO: Struct literal instead?
28-
var promoteOpts = proposal.PromoteOpts{}
27+
func addPromote(topLevel *cobra.Command) {
28+
po := proposal.PromoteOpts{}
2929

30-
var promoteCmd = &cobra.Command{
31-
Use: "promote [KEP]",
32-
Short: "Promote a KEP",
33-
Long: "Promote a KEP to a new stage for a target release",
34-
Example: ` kepctl promote sig-architecture/000-mykep --stage beta --release v1.20`,
35-
SilenceUsage: true,
36-
SilenceErrors: true,
37-
PreRunE: func(cmd *cobra.Command, args []string) error {
38-
return promoteOpts.Validate(args)
39-
},
40-
RunE: func(*cobra.Command, []string) error {
41-
return runPromote(&promoteOpts)
42-
},
43-
}
30+
cmd := &cobra.Command{
31+
Use: "promote [KEP]",
32+
Short: "Promote a KEP",
33+
Long: "Promote a KEP to a new stage for a target release",
34+
Example: ` kepctl promote sig-architecture/000-mykep --stage beta --release v1.20`,
35+
SilenceUsage: true,
36+
SilenceErrors: true,
37+
PreRunE: func(cmd *cobra.Command, args []string) error {
38+
return po.Validate(args)
39+
},
40+
RunE: func(*cobra.Command, []string) error {
41+
return runPromote(&po)
42+
},
43+
}
4444

45-
func init() {
4645
// TODO: Should these all be global args?
47-
promoteCmd.PersistentFlags().StringVarP(
48-
&promoteOpts.Stage,
46+
cmd.PersistentFlags().StringVarP(
47+
&po.Stage,
4948
"stage",
5049
"s",
5150
"",
5251
"KEP Stage",
5352
)
5453

55-
promoteCmd.PersistentFlags().StringVarP(
56-
&promoteOpts.Release,
54+
cmd.PersistentFlags().StringVarP(
55+
&po.Release,
5756
"release",
5857
"r",
5958
"",
6059
"Target Release",
6160
)
6261

63-
rootCmd.AddCommand(promoteCmd)
62+
topLevel.AddCommand(cmd)
6463
}
6564

6665
func runPromote(opts *proposal.PromoteOpts) error {
67-
rc, err := repo.New(opts.RepoOpts.RepoPath)
66+
rc, err := repo.New(rootOpts.RepoPath)
6867
if err != nil {
6968
return errors.Wrap(err, "creating repo client")
7069
}
7170

72-
return proposal.Promote(rc, opts)
71+
opts.Repo = rc
72+
73+
return proposal.Promote(opts)
7374
}

0 commit comments

Comments
 (0)