Skip to content

Commit b3d3fdc

Browse files
committed
kepctl: Drop helper function and plumb common args
Signed-off-by: Stephen Augustus <[email protected]>
1 parent acc88a2 commit b3d3fdc

File tree

3 files changed

+26
-74
lines changed

3 files changed

+26
-74
lines changed

cmd/kepctl/cmd/root.go

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,11 @@ import (
3030
// rootCmd represents the base command when called without any subcommands
3131
var rootCmd = &cobra.Command{
3232
Use: "kepctl",
33-
Short: "kepctl helps you build keps",
33+
Short: "kepctl helps you build KEPs",
3434
PersistentPreRunE: initLogging,
3535
}
3636

37-
type rootOptions struct {
38-
logLevel string
39-
}
40-
41-
var rootOpts = &rootOptions{}
37+
var rootOpts = &kepctl.CommonArgs{}
4238

4339
// Execute adds all child commands to the root command and sets flags appropriately.
4440
// This is called by main.main(). It only needs to happen once to the rootCmd.
@@ -50,45 +46,28 @@ func Execute() {
5046

5147
func init() {
5248
rootCmd.PersistentFlags().StringVar(
53-
&rootOpts.logLevel,
49+
&rootOpts.LogLevel,
5450
"log-level",
5551
"info",
5652
fmt.Sprintf("the logging verbosity, either %s", log.LevelNames()),
5753
)
58-
}
5954

60-
func initLogging(*cobra.Command, []string) error {
61-
return log.SetupGlobalLogger(rootOpts.logLevel)
62-
}
63-
64-
// TODO: Refactor/remove below
55+
// TODO: This should be defaulted in the package instead
56+
rootCmd.PersistentFlags().StringVar(
57+
&rootOpts.RepoPath,
58+
"repo-path",
59+
os.Getenv("ENHANCEMENTS_PATH"),
60+
"path to kubernetes/enhancements",
61+
)
6562

66-
func main() {
67-
cmd, err := buildMainCommand()
68-
if err != nil {
69-
fmt.Fprintln(os.Stderr, err)
70-
os.Exit(1)
71-
}
72-
if err := cmd.Execute(); err != nil {
73-
fmt.Fprintln(os.Stderr, err)
74-
os.Exit(1)
75-
}
63+
rootCmd.PersistentFlags().StringVar(
64+
&rootOpts.TokenPath,
65+
"gh-token-path",
66+
"",
67+
"path to a file with a GitHub API token",
68+
)
7669
}
7770

78-
func buildMainCommand() (*cobra.Command, error) {
79-
repoPath := os.Getenv("ENHANCEMENTS_PATH")
80-
k, err := kepctl.New(repoPath)
81-
if err != nil {
82-
return nil, err
83-
}
84-
85-
rootCmd := &cobra.Command{
86-
Use: "kepctl",
87-
Short: "kepctl helps you build keps",
88-
}
89-
90-
rootCmd.AddCommand(buildCreateCommand(k))
91-
rootCmd.AddCommand(buildPromoteCommand(k))
92-
rootCmd.AddCommand(buildQueryCommand(k))
93-
return rootCmd, nil
71+
func initLogging(*cobra.Command, []string) error {
72+
return log.SetupGlobalLogger(rootOpts.LogLevel)
9473
}

cmd/kepctl/helper.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

pkg/kepctl/kepctl.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ import (
4343
)
4444

4545
type CommonArgs struct {
46+
// command options
47+
LogLevel string
4648
RepoPath string // override the default settings
4749
TokenPath string
48-
KEP string // KEP name sig-xxx/xxx-name
49-
Name string
50-
Number string
51-
SIG string
50+
51+
// KEP options
52+
KEP string // KEP name sig-xxx/xxx-name
53+
Name string
54+
Number string
55+
SIG string
5256
}
5357

5458
func (c *CommonArgs) validateAndPopulateKEP(args []string) error {

0 commit comments

Comments
 (0)