Skip to content

Commit c0e7cc2

Browse files
committed
Improve input prompt for AWS profile
1 parent 34aebaa commit c0e7cc2

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

internal/awsconfig/awsconfig.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"net/url"
99
"os"
1010
"path/filepath"
11-
"strings"
1211

1312
"gopkg.in/ini.v1"
1413

@@ -220,10 +219,9 @@ func Setup(ctx context.Context, sink output.Sink, interactive bool, resolvedHost
220219
return nil
221220
}
222221

223-
files := strings.Join(status.filesToModify(), " and ")
224222
responseCh := make(chan output.InputResponse, 1)
225223
output.EmitUserInputRequest(sink, output.UserInputRequestEvent{
226-
Prompt: fmt.Sprintf("Set up LocalStack AWS profile in %s?", files),
224+
Prompt: "Configure AWS profile in ~/.aws/?",
227225
Options: []output.InputOption{{Key: "y", Label: "Y"}, {Key: "n", Label: "n"}},
228226
ResponseCh: responseCh,
229227
})
@@ -245,7 +243,7 @@ func Setup(ctx context.Context, sink output.Sink, interactive bool, resolvedHost
245243
return nil
246244
}
247245
}
248-
output.EmitSuccess(sink, fmt.Sprintf("LocalStack AWS profile written to %s", files))
246+
output.EmitSuccess(sink, "AWS profile successfully configured")
249247
output.EmitNote(sink, fmt.Sprintf("Try: aws s3 mb s3://test --profile %s", profileName))
250248
case <-ctx.Done():
251249
return ctx.Err()

internal/ui/components/input_prompt.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package components
22

33
import (
4+
"fmt"
5+
"strings"
6+
47
"github.com/localstack/lstk/internal/output"
58
"github.com/localstack/lstk/internal/ui/styles"
69
)
@@ -36,5 +39,38 @@ func (p InputPrompt) View() string {
3639
return ""
3740
}
3841

39-
return styles.SecondaryMessage.Render(output.FormatPrompt(p.prompt, p.options))
42+
lines := strings.Split(p.prompt, "\n")
43+
firstLine := lines[0]
44+
45+
var sb strings.Builder
46+
47+
// "?" prefix in secondary color
48+
sb.WriteString(styles.Secondary.Render("? "))
49+
50+
// Style trailing "?" with secondary color
51+
if before, found := strings.CutSuffix(firstLine, "?"); found {
52+
sb.WriteString(styles.Message.Render(before + "?"))
53+
} else {
54+
sb.WriteString(styles.Message.Render(firstLine))
55+
}
56+
57+
// Style option labels with secondary color
58+
labels := make([]string, 0, len(p.options))
59+
for _, opt := range p.options {
60+
if opt.Label != "" {
61+
labels = append(labels, opt.Label)
62+
}
63+
}
64+
if len(labels) == 1 {
65+
sb.WriteString(styles.Secondary.Render(fmt.Sprintf(" (%s)", labels[0])))
66+
} else if len(labels) > 1 {
67+
sb.WriteString(styles.Secondary.Render(fmt.Sprintf(" [%s]", strings.Join(labels, "/"))))
68+
}
69+
70+
if len(lines) > 1 {
71+
sb.WriteString("\n")
72+
sb.WriteString(styles.SecondaryMessage.Render(strings.Join(lines[1:], "\n")))
73+
}
74+
75+
return sb.String()
4076
}

test/integration/awsconfig_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestStartPromptsToCreateAWSProfileWhenMissing(t *testing.T) {
5757

5858
// Wait for the AWS profile prompt.
5959
require.Eventually(t, func() bool {
60-
return bytes.Contains(out.Bytes(), []byte("Set up LocalStack AWS profile"))
60+
return bytes.Contains(out.Bytes(), []byte("Configure AWS profile in"))
6161
}, 2*time.Minute, 200*time.Millisecond, "AWS profile prompt should appear")
6262

6363
// Press Y to confirm.
@@ -66,7 +66,7 @@ func TestStartPromptsToCreateAWSProfileWhenMissing(t *testing.T) {
6666

6767
// Wait for the success message.
6868
require.Eventually(t, func() bool {
69-
return bytes.Contains(out.Bytes(), []byte("LocalStack AWS profile written"))
69+
return bytes.Contains(out.Bytes(), []byte("AWS profile successfully configured"))
7070
}, 10*time.Second, 200*time.Millisecond, "success message should appear")
7171

7272
// Verify files were written to the isolated home dir, not the real one.
@@ -133,7 +133,7 @@ func TestStartSkipsAWSProfilePromptWhenAlreadyConfigured(t *testing.T) {
133133
_ = cmd.Wait()
134134
<-outputCh
135135

136-
assert.NotContains(t, out.String(), "Set up LocalStack AWS profile",
136+
assert.NotContains(t, out.String(), "Configure AWS profile in",
137137
"profile prompt should not appear when profile is already correctly configured")
138138
}
139139

0 commit comments

Comments
 (0)