Skip to content

Commit

Permalink
Added completion to profiles (#159)
Browse files Browse the repository at this point in the history
* Added completion to profiles
* fixed the problem when aws files are not present
  • Loading branch information
padilo authored and simcap committed Nov 3, 2017
1 parent beed8c4 commit c2ba09d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&awsRegionGlobalFlag, "aws-region", "r", "", "Override AWS region temporarily for the current command")
RootCmd.PersistentFlags().SetAnnotation("aws-region", cobra.BashCompCustom, []string{"__awless_region_list"})
RootCmd.PersistentFlags().StringVarP(&awsProfileGlobalFlag, "aws-profile", "p", "", "Override AWS profile temporarily for the current command")
RootCmd.PersistentFlags().SetAnnotation("aws-profile", cobra.BashCompCustom, []string{"__awless_profile_list"})
RootCmd.PersistentFlags().StringVar(&awsColorGlobalFlag, "color", "auto", "Force enabling/disabling colors in display (auto, never, always)")
RootCmd.PersistentFlags().BoolVar(&networkMonitorFlag, "network-monitor", false, "Debug requests with network monitor")
RootCmd.PersistentFlags().MarkHidden("network-monitor")
Expand Down Expand Up @@ -181,5 +182,12 @@ __awless_region_list()
COMPREPLY=( $(compgen -W "${regions}" -- ${cur}) )
}
__awless_profile_list()
{
cur="${COMP_WORDS[COMP_CWORD]#*=}"
profiles="$((egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' ~/.aws/credentials 2>/dev/null; grep '\[profile' ~/.aws/config 2>/dev/null | sed 's|\[profile ||g') | tr -d '[]' | sort | uniq)"
COMPREPLY=( $(compgen -W "${profiles}" -- ${cur}) )
}
`
)

0 comments on commit c2ba09d

Please sign in to comment.