diff --git a/cli/cli.go b/cli/cli.go index 44d980f..db4e140 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -128,18 +128,22 @@ func (c *CLI) Run(opt Options) error { const tokenGenerateURL = "https://github.com/settings/tokens/new?description=Vin" //nolint:gosec // AskGitHubAccessToken prompts for the GitHub access token. -func (c *CLI) AskGitHubAccessToken() error { - tokenPath, err := c.defaultTokenPath() - if err != nil { - return err - } - +func (c *CLI) AskGitHubAccessToken() (string, error) { fmt.Println(tokenGenerateURL) var token string prompt := &survey.Input{ Message: "input your token:", } if err := survey.AskOne(prompt, &token); err != nil { + return "", err + } + return token, nil +} + +// StoreAccessToken stores the GitHub access token. +func (c *CLI) StoreAccessToken(token string) error { + tokenPath, err := c.defaultTokenPath() + if err != nil { return err } diff --git a/cmd/vin/cmd/cmd_token.go b/cmd/vin/cmd/cmd_token.go index 592b98e..9a53d6b 100644 --- a/cmd/vin/cmd/cmd_token.go +++ b/cmd/vin/cmd/cmd_token.go @@ -7,7 +7,11 @@ import ( func runToken(cmd *cobra.Command, args []string) error { c := cli.New() - return c.AskGitHubAccessToken() + token, err := c.AskGitHubAccessToken() + if err != nil { + return err + } + return c.StoreAccessToken(token) } var tokenCmd = &cobra.Command{