Skip to content

Commit 15bbe1d

Browse files
committed
improve guided setup wizard
- No longer crash if user hits ^D - No longer error out on simple input errors - Leading and trailing spaces are now skipped - Number of questions is dramatically reduced without `--advanced` flag Fixes: #530 Fixes: #531
1 parent 76ef940 commit 15bbe1d

File tree

4 files changed

+189
-138
lines changed

4 files changed

+189
-138
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# AWS SSO CLI Changelog
22

3+
## Unreleased
4+
5+
### Bugs
6+
7+
* No longer crash during guided setup if user presses `<Del>` #531
8+
* No longer error out on simple input errors during guided setup
9+
10+
### Changes
11+
12+
* Guided setup is now more simple unless user provides the `--advanced` flag #530
13+
* Guided setup now strips leading and trailing spaces
14+
315
## [v1.12.0] - 2023-08-12
416

517
### Bugs

cmd/aws-sso/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ type CLI struct {
129129
ConfigProfiles ConfigProfilesCmd `kong:"cmd,help='Update ~/.aws/config with AWS SSO profiles from the cache'"`
130130
Config ConfigCmd `kong:"cmd,help='Run the configuration wizard'"`
131131
Ecs EcsCmd `kong:"cmd,help='ECS Server commands'"`
132-
Setup SetupCmd `kong:"cmd,hidden"` // need this so variables are visisble.
133132
Version VersionCmd `kong:"cmd,help='Print version and exit'"`
134133
}
135134

@@ -171,7 +170,7 @@ func main() {
171170

172171
if _, err := os.Stat(cli.ConfigFile); errors.Is(err, os.ErrNotExist) {
173172
log.Warnf("No config file found! Will now prompt you for a basic config...")
174-
if err = setupWizard(&runCtx, false, false); err != nil {
173+
if err = setupWizard(&runCtx, false, false, runCtx.Cli.Config.Advanced); err != nil {
175174
log.Fatalf("%s", err.Error())
176175
}
177176
} else if err != nil {

cmd/aws-sso/setup_cmd.go

+42-39
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,20 @@ import (
3333

3434
var ranSetup = false
3535

36-
// SetupCmd defines the Kong args for the setup command (which currently doesn't exist)
37-
type SetupCmd struct{}
38-
39-
// Run executes the setup command
40-
func (cc *SetupCmd) Run(ctx *RunContext) error {
41-
return setupWizard(ctx, false, false)
42-
}
43-
4436
type ConfigCmd struct {
4537
// AddSSO bool `kong:"help='Add a new AWS SSO instance'"`
38+
Advanced bool `kong:"help='Enable advanced configuration'"`
4639
}
4740

4841
func (cc *ConfigCmd) Run(ctx *RunContext) error {
4942
if err := backupConfig(ctx.Cli.ConfigFile); err != nil {
5043
return err
5144
}
5245

53-
return setupWizard(ctx, true, false) // ctx.Cli.Config.AddSSO)
46+
return setupWizard(ctx, true, false, ctx.Cli.Config.Advanced) // ctx.Cli.Config.AddSSO)
5447
}
5548

56-
func setupWizard(ctx *RunContext, reconfig, addSSO bool) error {
49+
func setupWizard(ctx *RunContext, reconfig, addSSO, advanced bool) error {
5750
var s = ctx.Settings
5851

5952
// Don't run setup twice
@@ -87,17 +80,24 @@ func setupWizard(ctx *RunContext, reconfig, addSSO bool) error {
8780
// - StartUrl/startHostname
8881
// - InstanceName
8982
} else {
90-
instanceName := promptSsoInstance("")
83+
instanceName := "Default"
84+
if advanced {
85+
instanceName = promptSsoInstance("")
86+
}
9187
startHostname := promptStartUrl("")
9288
ssoRegion := promptAwsSsoRegion("")
93-
defaultRegion := promptDefaultRegion(ssoRegion)
89+
90+
defaultRegion := ""
91+
if advanced {
92+
defaultRegion = promptDefaultRegion(ssoRegion)
93+
}
9494

9595
s = &sso.Settings{
9696
SSO: map[string]*sso.SSOConfig{},
9797
UrlAction: "open",
9898
LogLevel: "error",
9999
DefaultRegion: defaultRegion,
100-
ConsoleDuration: 60,
100+
ConsoleDuration: 720,
101101
CacheRefresh: 168,
102102
AutoConfigCheck: false,
103103
FullTextSearch: true,
@@ -113,38 +113,41 @@ func setupWizard(ctx *RunContext, reconfig, addSSO bool) error {
113113
}
114114
}
115115

116-
// first, caching
117-
s.CacheRefresh = promptCacheRefresh(s.CacheRefresh)
116+
if advanced {
117+
// first, caching
118+
s.CacheRefresh = promptCacheRefresh(s.CacheRefresh)
118119

119-
if s.CacheRefresh > 0 {
120-
s.AutoConfigCheck = promptAutoConfigCheck(s.AutoConfigCheck)
121-
}
120+
if s.CacheRefresh > 0 {
121+
s.AutoConfigCheck = promptAutoConfigCheck(s.AutoConfigCheck)
122+
}
122123

123-
// full text search?
124-
s.FullTextSearch = promptFullTextSearch(s.FullTextSearch)
124+
// full text search?
125+
s.FullTextSearch = promptFullTextSearch(s.FullTextSearch)
125126

126-
// next how we open URLs
127-
s.UrlAction = promptUrlAction(s.UrlAction)
128-
s.ConfigProfilesUrlAction = promptConfigProfilesUrlAction(s.ConfigProfilesUrlAction, s.UrlAction)
127+
// next how we open URLs
128+
s.UrlAction = promptUrlAction(s.UrlAction)
129129

130-
// do we need urlExecCommand?
131-
if s.UrlAction == url.Exec {
132-
s.UrlExecCommand = promptUrlExecCommand(s.UrlExecCommand)
133-
} else if s.UrlAction.IsContainer() {
134-
s.UrlExecCommand = promptUseFirefox(s.UrlExecCommand)
135-
} else {
136-
s.UrlExecCommand = []string{}
137-
}
130+
s.ConfigProfilesUrlAction = promptConfigProfilesUrlAction(s.ConfigProfilesUrlAction, s.UrlAction)
138131

139-
// should we prompt user to override default browser?
140-
if s.UrlAction == url.Open || s.ConfigProfilesUrlAction == url.ConfigProfilesOpen {
141-
s.Browser = promptDefaultBrowser(s.Browser)
142-
}
132+
// do we need urlExecCommand?
133+
if s.UrlAction == url.Exec {
134+
s.UrlExecCommand = promptUrlExecCommand(s.UrlExecCommand)
135+
} else if s.UrlAction.IsContainer() {
136+
s.UrlExecCommand = promptUseFirefox(s.UrlExecCommand)
137+
} else {
138+
s.UrlExecCommand = []string{}
139+
}
143140

144-
s.ConsoleDuration = promptConsoleDuration(s.ConsoleDuration)
145-
s.HistoryLimit = promptHistoryLimit(s.HistoryLimit)
146-
s.HistoryMinutes = promptHistoryMinutes(s.HistoryMinutes)
147-
s.LogLevel = promptLogLevel(s.LogLevel)
141+
// should we prompt user to override default browser?
142+
if s.UrlAction == url.Open || s.ConfigProfilesUrlAction == url.ConfigProfilesOpen {
143+
s.Browser = promptDefaultBrowser(s.Browser)
144+
}
145+
146+
s.ConsoleDuration = promptConsoleDuration(s.ConsoleDuration)
147+
s.HistoryLimit = promptHistoryLimit(s.HistoryLimit)
148+
s.HistoryMinutes = promptHistoryMinutes(s.HistoryMinutes)
149+
s.LogLevel = promptLogLevel(s.LogLevel)
150+
}
148151

149152
if err := s.Validate(); err != nil {
150153
return err

0 commit comments

Comments
 (0)