Skip to content

Commit

Permalink
aws.ActionProfiles should be a callback action
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Sep 3, 2020
1 parent 5c423bb commit c118bd4
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions actions/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,31 @@ func ActionRegions() carapace.Action {
}

func ActionProfiles() carapace.Action {
profiles := []string{}
return carapace.ActionCallback(func(args []string) carapace.Action {
profiles := []string{}

// TODO support windows
if path, err := homedir.Expand("~/.aws/config"); err != nil {
return carapace.ActionMessage(err.Error())
} else {
if cfg, err := ini.Load(path); err != nil {
// TODO support windows
if path, err := homedir.Expand("~/.aws/config"); err != nil {
return carapace.ActionMessage(err.Error())
} else {
for _, section := range cfg.Sections() {
if strings.HasPrefix(section.Name(), "profile ") {
profiles = append(profiles, strings.TrimPrefix(section.Name(), "profile "))
if key, err := section.GetKey("region"); err != nil {
profiles = append(profiles, "")
} else {
profiles = append(profiles, key.String())
if cfg, err := ini.Load(path); err != nil {
return carapace.ActionMessage(err.Error())
} else {
for _, section := range cfg.Sections() {
if strings.HasPrefix(section.Name(), "profile ") {
profiles = append(profiles, strings.TrimPrefix(section.Name(), "profile "))
if key, err := section.GetKey("region"); err != nil {
profiles = append(profiles, "")
} else {
profiles = append(profiles, key.String())
}
}
}
if len(profiles) == 0 {
profiles = append(profiles, "default", "")
}
return carapace.ActionValuesDescribed(profiles...)
}
if len(profiles) == 0 {
profiles = append(profiles, "default", "")
}
return carapace.ActionValuesDescribed(profiles...)
}
}
})
}

0 comments on commit c118bd4

Please sign in to comment.