Nike-Inc / gimme-aws-creds

A CLI that utilizes Okta IdP via SAML to acquire temporary AWS credentials
Apache License 2.0
920 stars 262 forks source link

Add CLI auto-completion #376

Closed jcreyf closed 1 year ago

jcreyf commented 1 year ago

This is a feature request to get auto-completion added to gimme-aws-creds.

Expected Behavior

Pressing the tab-key twice after the gimme-aws-creds command shows a list of supported arguments:

/> gimme-aws-creds -<tab><tab>
--action-configure      --configure             --list-profiles         --resolve
--action-list-profiles  --help                  --output-format         --version
--action-list-roles     --insecure              --profile               -keep

The list of possible arguments is shorter as the user enters more characters:

/> gimme-aws-creds --action-<tab><tab>
--action-configure      --action-list-profiles  --action-list-roles

Auto-completion will automatically type the remained of the selected argument if only 1 single choice is left:

/> gimme-aws-creds --action-c<tab>

gimme-aws-creds will automatically complete the CLI to:

/> gimme-aws-creds --action-configure

If an argument supports specific values, then have auto-complete show those values:

/> gimme-aws-creds --output-format <tab><tab>
export  json

the same auto-complete should happen here when the user types e or j and then hits tab.

The auto-completion can also show the available profiles from the ~/.okta_aws_login_config file when the --profile argument is selected:

/> gimme-aws-creds --profile <tab><tab>
DEFAULT      eap-preprod  eap-prod     waffle       waffle-nsp

with same auto-completion of the selected profile name as the user enters more characters.

Current Behavior

There's no auto-complete available in the current version.

Possible Solution

I have this exact described behavior implemented in my fork: https://github.com/jcreyf/gimme-aws-creds/blob/autocomplete/bin/gimme-aws-creds-autocomplete.sh

Steps to Reproduce (for bugs)

This is not a bug. Just a nice to have to reduce typing anxiety and lack of memory to memorize the supported arguments.

Context

This is reducing the chance of typos and you don't have to open another shell to run gimme-aws-creds --help to get a list of supported arguments while trying to compose the command line.

Your Environment

epierce commented 1 year ago

The autocomplete scripts will be extra maintenance going forward, so I'd like to get feedback from the community on whether this feature will be useful for large numbers of users or not.

jcreyf commented 1 year ago

Thanks @epierce ! The maintenance overhead is minimal though. It's basically only when an argument changes in gimme-aws-creds. I think most of the value of this autocomplete sits in no longer needing to memorize the profiles you created in ~/.okta_aws_login_config. Some of us have quite a few profiles. Especially when you have quite a few AWS Accounts to manage using multiple IAM roles at different access levels. I have a dozen or so profiles at this point and it will most probably grow even more. Autocomplete dynamically pulls the profile names out of the config-file and shows them to you as you are generating the command.

epierce commented 1 year ago

Just merged #379