diff --git a/pkg/configure/configure_test.go b/pkg/configure/configure_test.go index f22b4beb6..3b9af3598 100644 --- a/pkg/configure/configure_test.go +++ b/pkg/configure/configure_test.go @@ -54,8 +54,9 @@ func TestConfigure(t *testing.T) { }, wantOutput: []string{ "Fastly API endpoint (via --endpoint): http://local.dev", - "Fastly API token (via --token): abcdef", + "Fastly API token provided via --token", "Validating token...", + "Persisting configuration...", "Configured the Fastly CLI", "You can find your configuration file at", }, @@ -77,8 +78,9 @@ func TestConfigure(t *testing.T) { }, wantOutput: []string{ "Fastly API endpoint (via --endpoint): http://staging.dev", - "Fastly API token (via --token): abcdef", + "Fastly API token provided via --token", "Validating token...", + "Persisting configuration...", "Configured the Fastly CLI", "You can find your configuration file at", }, @@ -97,8 +99,9 @@ func TestConfigure(t *testing.T) { GetUserFn: goodUser, }, wantOutput: []string{ - "Fastly API token (via --token): abcdef", + "Fastly API token provided via --token", "Validating token...", + "Persisting configuration...", "Configured the Fastly CLI", "You can find your configuration file at", }, @@ -122,6 +125,7 @@ func TestConfigure(t *testing.T) { "https://manage.fastly.com/account/personal/tokens", "Fastly API token: ", "Validating token...", + "Persisting configuration...", "Configured the Fastly CLI", "You can find your configuration file at", }, @@ -133,7 +137,7 @@ func TestConfigure(t *testing.T) { }, }, { - name: "token from flag", + name: "token from environment", args: []string{"configure"}, env: config.Environment{Token: "hello"}, api: mock.API{ @@ -141,8 +145,9 @@ func TestConfigure(t *testing.T) { GetUserFn: goodUser, }, wantOutput: []string{ - "Fastly API token (via FASTLY_API_TOKEN): hello", + "Fastly API token provided via FASTLY_API_TOKEN", "Validating token...", + "Persisting configuration...", "Configured the Fastly CLI", "You can find your configuration file at", }, @@ -167,6 +172,7 @@ func TestConfigure(t *testing.T) { "https://manage.fastly.com/account/personal/tokens", "Fastly API token: ", "Validating token...", + "Persisting configuration...", "Configured the Fastly CLI", "You can find your configuration file at", }, @@ -185,7 +191,7 @@ func TestConfigure(t *testing.T) { GetUserFn: badUser, }, wantOutput: []string{ - "Fastly API token (via --token): abcdef", + "Fastly API token provided via --token", "Validating token...", }, wantError: "error validating token: bad token", diff --git a/pkg/configure/root.go b/pkg/configure/root.go index 00d49dd41..a2aae4efa 100644 --- a/pkg/configure/root.go +++ b/pkg/configure/root.go @@ -56,9 +56,9 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error { token, source := c.Globals.Token() switch source { // TODO(pb): this can be duplicate output if --verbose is passed case config.SourceFlag: - text.Output(out, "Fastly API token (via --token): %s", token) + text.Output(out, "Fastly API token provided via --token") case config.SourceEnvironment: - text.Output(out, "Fastly API token (via %s): %s", config.EnvVarToken, token) + text.Output(out, "Fastly API token provided via %s", config.EnvVarToken) default: text.Output(out, ` An API token is used to authenticate requests to the Fastly API. @@ -70,10 +70,12 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error { if err != nil { return err } + text.Break(out) } - text.Break(out) - text.Output(out, "Validating token...") + text.Break(out) + progress := text.NewQuietProgress(out) + progress.Step("Validating token...") client, err := c.clientFactory(token, endpoint) if err != nil { @@ -90,6 +92,8 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error { return fmt.Errorf("error fetching token user: %w", err) } + progress.Step("Persisting configuration...") + // Set everything in the File struct based on provided user input. c.Globals.File.Token = token c.Globals.File.Email = user.Login @@ -117,8 +121,12 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error { // Escape any spaces in filepath before output. filePath := strings.ReplaceAll(c.configFilePath, " ", `\ `) + progress.Done() + text.Break(out) + text.Description(out, "You can find your configuration file at", filePath) + text.Success(out, "Configured the Fastly CLI") - fmt.Fprintf(out, "\nYou can find your configuration file at\n\n %s\n\n", filePath) + return nil }