Skip to content

Shell / Tab completion for atmos stacks and components #45

Closed

Description

@nitrocode

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

Activity

  1. nitrocode commented on Dec 27, 2021

    @nitrocode
    MemberAuthor

    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>
    
  2. changed the title [-]Tab completion[/-] [+]Shell / Tab completion[/+] on Nov 16, 2022
  3. nitrocode commented on Nov 16, 2022

    @nitrocode
    MemberAuthor

    Matt Calhoun (@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>
  4. mcalhoun commented on Nov 16, 2022

    @mcalhoun
    Contributor

    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.

  5. nitrocode commented on May 10, 2024

    @nitrocode
    MemberAuthor

    "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
  6. changed the title [-]Shell / Tab completion[/-] [+]Shell / Tab completion for atmos stacks and components[/+] on May 10, 2024
  7. RoseSecurity commented on Nov 13, 2024

    @RoseSecurity
    Member

    I think this would be even easier if we had a command for atmos list where users can list the stacks, components, and variables associated with each stack. We could repurpose this function to provide some autocompletion for the command line parameters like you mentioned. In the meantime, would something like the following be suitable for the terraform options?

    var validArgs = []string{"init", "plan", "apply", "deploy", "destroy", "state", "import"} // and more as needed
    
    // terraformCmd represents the base command for all terraform sub-commands
    var terraformCmd = &cobra.Command{
    	Use:                "terraform",
    	Aliases:            []string{"tf"},
    	Short:              "Execute Terraform commands",
    	Long:               `This command executes Terraform commands`,
    	FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: true},
    	ValidArgs:          validArgs,
    	Run: func(cmd *cobra.Command, args []string) {

    which produces the following:

    ❯ atmos terraform <tab>
    generate            -- Execute 'terraform generate' commands
    apply               deploy              destroy             dns-delegated-move  import              init                plan                state
  8. samtholiya commented on Feb 4, 2025

    @samtholiya
    Contributor

    #959

    This pr will only add completions for atmos inbuilt command, stack names and components

    For custom commands we will have to

    1. Fix the issue that shadows commands in case custom command includes a command that atmos already has DEV-469
    2. We will have to probably modify the completion script that is generate so that it always defaults to dynamic suggestion instead of static suggestions that it stores for efficiency. So that we always read the config to suggest the commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions