atmos icon indicating copy to clipboard operation
atmos copied to clipboard

Shell / Tab completion for atmos stacks and components

Open nitrocode opened this issue 4 years ago • 4 comments

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

Tab completion for atmos commands

Expected Behavior

$ atmos<tab>
helm helmfile help istioctl stack terraform vendor version workflow
$ atmos terraform<tab>
apply backend clean console deploy destroy import init output plan show workspace
$ atmos terraform plan<tab>
tfstate-backend aws-sso github-runners # etc
$ atmos terraform plan github-runners --stack<tab>
gbl-root gbl-prod gbl-staging

Use Case

I want the command and stacks to complete using tab instead of having to type it in each time

Describe Ideal Solution

It's implemented

Alternatives Considered

None

Additional Context

  • https://stackoverflow.com/questions/5570795/how-does-bash-tab-completion-work
  • https://github.com/perlpunk/shell-completions

nitrocode avatar Jul 02 '21 16:07 nitrocode

I did notice there is a new completion subcommand.

⨠ eval $(atmos completion bash)
⨠ atmos<tab>
completion  (generate the autocompletion script for the specified shell)
describe    (describe)
helmfile    (helmfile command)
help        (Help about any command)
terraform   (terraform command)
version     (version command)

This seems to be off

⨠ atmos terraform <tab>
--stack               -s                    generate  (generate)

That should show plan/apply/deploy/destroy

This returns a - when hitting tab instead of showing the list of components

⨠ atmos terraform plan <tab>

This returns another - when it should show the list of stacks

⨠ atmos terraform plan efs --stack <tab>

nitrocode avatar Dec 27 '21 18:12 nitrocode

@mcalhoun

I reopened this ticket because I was hoping we could do something like this

# get components
atmos terraform plan <tab>
# get root stack
atmos terraform plan ecr --stack <tab>

nitrocode avatar Nov 16 '22 21:11 nitrocode

Yeah, I just realized I only implemented the base-level (atmos commands) and not stack completion. Figuring out how to do that will be a bit more tricky.

mcalhoun avatar Nov 16 '22 21:11 mcalhoun

"real" (not abstract) component completion and root stack completion would be very handy here.

I also noticed that subcommands are missing.

✗ atmos terraform<tab>
generate   -- Execute 'terraform generate' commands
provision  -- This command provisions terraform components

I was expecting plan, deploy, apply, etc


Here's a way to get all the stacks using yq

✗ atmos describe stacks | yq e '. | keys'
- gbl-corp
- gbl-identity
- gbl-root
...

An even easier way is using it natively in atmos

✗ atmos list stacks
gbl-corp
gbl-identity
gbl-root

Here's how to get all the real components using yq

✗ atmos describe stacks | yq e '. | to_entries | .[].value.components.terraform | with_entries(select(.value.metadata.type != "abstract")) | keys' | grep -v '\[\]' | sort | uniq
- aws-team-roles
- aws-teams
- account
- account-map
- aws-team-roles
- github-oidc-provider
- vpc

nitrocode avatar May 10 '24 05:05 nitrocode