Skip to content

Commit

Permalink
refactor: separate func to ask token and store token
Browse files Browse the repository at this point in the history
  • Loading branch information
5n7-sk committed Dec 9, 2020
1 parent f1e0b83 commit 08c7406
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/vin/cmd/cmd_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 08c7406

Please sign in to comment.