cloudposse / atmos

👽 Terraform Orchestration Tool for DevOps. Keep environment configuration DRY with hierarchical imports of configurations, inheritance, and WAY more. Native support for Terraform and Helmfile.
https://atmos.tools
Apache License 2.0
777 stars 96 forks source link

Shell / Tab completion for atmos stacks and components #45

Open nitrocode opened 3 years ago

nitrocode commented 3 years ago

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

nitrocode commented 2 years ago

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 commented 1 year ago

@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>
mcalhoun commented 1 year ago

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.

nitrocode commented 6 months ago

"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