diff --git a/cmd/bk/main.go b/cmd/bk/main.go index ee921c9..3b0942c 100644 --- a/cmd/bk/main.go +++ b/cmd/bk/main.go @@ -18,13 +18,13 @@ func main() { func mainRun() int { ctx := context.Background() - viper := viper.New() - viper.SetConfigFile(config.ConfigFile()) - viper.AutomaticEnv() + v := viper.New() + v.SetConfigFile(config.ConfigFile()) + v.AutomaticEnv() // attempt to read in config file but it might not exist - _ = viper.ReadInConfig() + _ = v.ReadInConfig() - rootCmd, err := root.NewCmdRoot(viper, build.Version) + rootCmd, err := root.NewCmdRoot(v, build.Version) if err != nil { fmt.Fprintf(os.Stderr, "failed to create root command: %s\n", err) return 1 diff --git a/pkg/cmd/auth/auth.go b/pkg/cmd/auth/auth.go deleted file mode 100644 index df219ef..0000000 --- a/pkg/cmd/auth/auth.go +++ /dev/null @@ -1,18 +0,0 @@ -package auth - -import ( - initCmd "github.com/buildkite/cli/v3/pkg/cmd/auth/init" - "github.com/spf13/cobra" - "github.com/spf13/viper" -) - -func NewCmdAuth(viper *viper.Viper) *cobra.Command { - cmd := &cobra.Command{ - Use: "auth ", - Short: "Manage authentication for bk", - } - - cmd.AddCommand(initCmd.NewCmdInit(viper)) - - return cmd -} diff --git a/pkg/cmd/auth/init/init.go b/pkg/cmd/configure/configure.go similarity index 79% rename from pkg/cmd/auth/init/init.go rename to pkg/cmd/configure/configure.go index 62ed3e1..0ad63b0 100644 --- a/pkg/cmd/auth/init/init.go +++ b/pkg/cmd/configure/configure.go @@ -1,4 +1,4 @@ -package init +package configure import ( "errors" @@ -9,13 +9,13 @@ import ( "github.com/spf13/viper" ) -func NewCmdInit(viper *viper.Viper) *cobra.Command { +func NewCmdConfigure(v *viper.Viper) *cobra.Command { var force bool cmd := &cobra.Command{ - Use: "init", + Use: "configure", Args: cobra.ExactArgs(0), - Short: "Initialise authentication token", + Short: "Configure Buildkite API token", RunE: func(cmd *cobra.Command, args []string) error { // if the token already exists and --force is not used if !force && viper.IsSet(config.APIToken) { @@ -32,12 +32,11 @@ func NewCmdInit(viper *viper.Viper) *cobra.Command { return err } - viper.Set(config.APIToken, token) - return viper.WriteConfig() + v.Set(config.APIToken, token) + return v.WriteConfig() }, } cmd.Flags().BoolVar(&force, "force", false, "Force setting a new token") - return cmd } diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index 1965694..23d3217 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -2,7 +2,7 @@ package root import ( "github.com/MakeNowJust/heredoc" - authCmd "github.com/buildkite/cli/v3/pkg/cmd/auth" + configureCmd "github.com/buildkite/cli/v3/pkg/cmd/configure" versionCmd "github.com/buildkite/cli/v3/pkg/cmd/version" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -22,7 +22,7 @@ func NewCmdRoot(viper *viper.Viper, version string) (*cobra.Command, error) { } cmd.AddCommand(versionCmd.NewCmdVersion()) - cmd.AddCommand(authCmd.NewCmdAuth(viper)) + cmd.AddCommand(configureCmd.NewCmdConfigure(viper)) return cmd, nil }