diff --git a/commands/config/config.go b/commands/config/config.go index f315d02f..dbc879b5 100644 --- a/commands/config/config.go +++ b/commands/config/config.go @@ -7,8 +7,6 @@ import ( "github.com/spf13/cobra" "gitlab.com/gitlab-org/cli/commands/cmdutils" - "gitlab.com/gitlab-org/cli/internal/config" - "gitlab.com/gitlab-org/cli/pkg/glinstance" ) var isGlobal bool @@ -38,10 +36,6 @@ Current respected settings: configCmd.AddCommand(NewCmdConfigGet(f)) configCmd.AddCommand(NewCmdConfigSet(f)) - configCmd.AddCommand(NewCmdConfigInit(f)) - - // TODO: deprecate `config init` command since it's been replaced by `auth login` - // targetedVersion: 1.12.0 return configCmd } @@ -136,64 +130,3 @@ Specifying the --hostname flag also saves in the global config file cmd.Flags().BoolVarP(&isGlobal, "global", "g", false, "Write to global ~/.config/glab-cli/config.yml file rather than the repository .git/glab-cli/config.yml file") return cmd } - -func NewCmdConfigInit(f *cmdutils.Factory) *cobra.Command { - configInitCmd := &cobra.Command{ - Use: "init", - Short: "Shows a prompt to set basic glab configuration", - Long: heredoc.Docf(` - Update the configuration by setting a key to a value. - - Examples: - - %[1]splaintext - $ glab config init - ? Enter default GitLab Host (Current Value: https://gitlab.com): - %[1]s -`, "```"), - RunE: func(cmd *cobra.Command, args []string) error { - return configInit(f) - }, - } - configInitCmd.Deprecated = "use `glab auth login` which is secure and has additional options." - return configInitCmd -} - -func configInit(f *cmdutils.Factory) error { - var host string - cfg, err := f.Config() - if err != nil { - return err - } - baseRepo, err := f.BaseRepo() - if err != nil { - host = glinstance.Default() - } else { - host = baseRepo.RepoHost() - } - host, err = config.Prompt(fmt.Sprintf("Enter Gitlab Host (Current Value: %s): ", host), host) //nolint:staticcheck - if err != nil { - return err - } - host, protocol := glinstance.StripHostProtocol(host) - err = cfg.Set(host, "api_protocol", protocol) - if err != nil { - return err - } - - token, _ := cfg.Get(host, "token") - token, err = config.Prompt("Enter Gitlab Token: ", token) //nolint:staticcheck - if err != nil { - return err - } - err = cfg.Set(host, "token", token) - if err != nil { - return nil - } - - if cfg.Write() != nil { - return err - } - fmt.Fprintf(f.IO.StdOut, "%s Configuration updated", f.IO.Color().GreenCheck()) - return nil -} diff --git a/docs/source/config/index.md b/docs/source/config/index.md index 3fe19213..7c2e8206 100644 --- a/docs/source/config/index.md +++ b/docs/source/config/index.md @@ -50,5 +50,4 @@ conf ## Subcommands - [`get`](get.md) -- [`init`](init.md) - [`set`](set.md) diff --git a/internal/config/config.go b/internal/config/config.go index af422e78..ff9ca962 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -9,7 +9,6 @@ import ( "github.com/zalando/go-keyring" "gitlab.com/gitlab-org/cli/pkg/glinstance" - "gitlab.com/gitlab-org/cli/pkg/prompt" "gopkg.in/yaml.v3" ) @@ -518,14 +517,3 @@ func GetFromEnvWithSource(key string) (value, source string) { } return } - -// Prompt prompts user for value and returns default value if empty -// -// Deprecated: only used by the `config init` command which is deprecated -func Prompt(question, defaultVal string) (envVal string, err error) { - err = prompt.AskQuestionWithInput(&envVal, "config", question, defaultVal, false) - if err != nil { - return - } - return -} diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 627aa038..c385d3e8 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -2,7 +2,6 @@ package config import ( "bytes" - "errors" "path/filepath" "testing" @@ -10,7 +9,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/zalando/go-keyring" - "gitlab.com/gitlab-org/cli/pkg/prompt" "gopkg.in/yaml.v3" ) @@ -146,36 +144,3 @@ func Test_config_Get_NotFoundError(t *testing.T) { require.Error(t, err) assert.True(t, isNotFoundError(err)) } - -func Test_Prompt(t *testing.T) { - t.Run("success", func(t *testing.T) { - ask, teardown := prompt.InitAskStubber() - defer teardown() - - ask.Stub([]*prompt.QuestionStub{ - { - Name: "config", - Value: "profclems/glab", - }, - }) - - got, err := Prompt("pick a repo", "defaultValue") - assert.NoError(t, err) - assert.Equal(t, "profclems/glab", got) - }) - t.Run("failed", func(t *testing.T) { - ask, teardown := prompt.InitAskStubber() - defer teardown() - - ask.Stub([]*prompt.QuestionStub{ - { - Name: "config", - Value: errors.New("failed"), - }, - }) - - got, err := Prompt("pick a repo", "defaultValue") - assert.EqualError(t, err, "failed") - assert.Equal(t, got, "") - }) -}