Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

command line completion #116

Closed
josacar opened this issue Feb 3, 2019 · 2 comments
Closed

command line completion #116

josacar opened this issue Feb 3, 2019 · 2 comments

Comments

@josacar
Copy link
Contributor

josacar commented Feb 3, 2019

It would be nice to add completion for the login and exec command to list the profiles over there.

I can do it in bash/zsh for I ask here if I should bake it in the CLI itself.

@josacar
Copy link
Contributor Author

josacar commented Feb 3, 2019

Bash completion can be like this:

#!/usr/bin/env bash

__debug()
{
    if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
        echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
    fi
}

_aws-okta () {

  local cur
  cur=${COMP_WORDS[COMP_CWORD]}
  local cmd
  cmd=${COMP_WORDS[1]}
  local prev
  prev=${COMP_WORDS[COMP_CWORD-1]}
  local profiles
  profiles=$(awk '/profile/ {print $2}' ~/.aws/config |tr -d \])
  local params
  params="--backend --debug --help --"
  local commands
  commands="add exec help login version"

  COMPREPLY=()

  case "$cmd" in
    exec)
        COMPREPLY=( $(compgen -W "${profiles}" -- "${cur}") )
        ;;
    -*)
        COMPREPLY=( $(compgen -W "${params}" -- "${cur}") )
        ;;
     *)
        COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
        ;;
  esac
  return 0
}

complete -F _aws-okta aws-okta

@alberts
Copy link
Contributor

alberts commented Feb 3, 2019

awsless has a nice completion story that I think we should emulate.

See https://github.com/wallix/awless/blob/8c1a034197b873414f5f4733e14752ca6a7a7198/commands/autocompletion.go

Lets users just add something like this to their .bashrc:

source <(awless completion bash)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants