Skip to content

Commit

Permalink
Only prompt students when the --interactive flag is set
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Aug 15, 2024
1 parent 0063ab1 commit a929631
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ func runConfigure(configuration config.Config, flags *pflag.FlagSet) error {
return nil
}

// If the command is run 'bare' and we have no token,
// prompt the user to provide the token.
if flags.NFlag() == 0 && cfg.GetString("token") == "" {
// Interactive configuration.
interactive, err := flags.GetBool("interactive")
if err != nil {
return err
}
if interactive {
tokenURL := config.SettingsURL(cfg.GetString("apibaseurl"))
fmt.Println("Find your token on", tokenURL)

Expand All @@ -83,6 +86,13 @@ func runConfigure(configuration config.Config, flags *pflag.FlagSet) error {
flags.Set("token", token)
}

// 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 @@ -250,6 +260,7 @@ func setupConfigureFlags(flags *pflag.FlagSet) {
flags.StringP("workspace", "w", "", "directory for exercism exercises")
flags.StringP("api", "a", "", "API base url")
flags.BoolP("show", "s", false, "show the current configuration")
flags.BoolP("interactive", "i", false, "set configuration values with interactive prompts")
flags.BoolP("no-verify", "", false, "skip online token authorization check")
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestBareConfigure(t *testing.T) {

err = runConfigure(cfg, flags)
if assert.Error(t, err) {
assert.Regexp(t, "no token provided", err.Error())
assert.Regexp(t, "no token configured", err.Error())
}
}

Expand Down

0 comments on commit a929631

Please sign in to comment.