Skip to content

Commit

Permalink
Simple prompt for token with cli configure.
Browse files Browse the repository at this point in the history
Works with manual tests, but will require
refactoring to work with automated tests.

Progress towards exercism#961
  • Loading branch information
byarbrough committed Dec 20, 2020
1 parent ba48dcd commit 266bc2d
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ func runConfigure(configuration config.Config, flags *pflag.FlagSet) error {
return nil
}

// If the command is run 'bare' and we have no token,
// explain how to set the token.
if flags.NFlag() == 0 && cfg.GetString("token") == "" {
tokenURL := config.SettingsURL(cfg.GetString("apibaseurl"))
return fmt.Errorf("There is no token configured. Find your token on %s, and call this command again with --token=<your-token>.", tokenURL)
}

// Determine the base API URL.
baseURL, err := flags.GetString("api")
if err != nil {
Expand Down Expand Up @@ -109,9 +102,11 @@ func runConfigure(configuration config.Config, flags *pflag.FlagSet) error {

tokenURL := config.SettingsURL(cfg.GetString("apibaseurl"))

// If we don't have a token then explain how to set it and bail.
// If we don't have a token then prompt for it and read from stdin
if token == "" {
return fmt.Errorf("There is no token configured. Find your token on %s, and call this command again with --token=<your-token>.", tokenURL)
fmt.Printf("There is no token configured. Find your token on %s.\n", tokenURL)
fmt.Print("Token: ")
fmt.Scanf("%s", &token)
}

// Verify that the token is valid.
Expand Down

0 comments on commit 266bc2d

Please sign in to comment.