Merge branch 'remove-config-init' into 'main'

chore: remove deprecated `config init` command

See merge request https://gitlab.com/gitlab-org/cli/-/merge_requests/1384

Merged-by: Oscar Tovar <otovar@gitlab.com>
Approved-by: Gary Holtz <gholtz@gitlab.com>
Approved-by: Amy Qualls <aqualls@gitlab.com>
Approved-by: Oscar Tovar <otovar@gitlab.com>
Co-authored-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
This commit is contained in:
Oscar Tovar 2023-12-14 17:51:26 +00:00
commit b84ce07873
4 changed files with 0 additions and 115 deletions

View File

@ -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
}

View File

@ -50,5 +50,4 @@ conf
## Subcommands
- [`get`](get.md)
- [`init`](init.md)
- [`set`](set.md)

View File

@ -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
}

View File

@ -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, "")
})
}