API-CLI

 view release on metacpan or  search on metacpan

examples/bash/digitaloceancl.bash  view on Meta::CPAN

#!bash

# http://stackoverflow.com/questions/7267185/bash-autocompletion-add-description-for-possible-completions

_digitaloceancl() {

    COMPREPLY=()
    local program=digitaloceancl
    local cur=${COMP_WORDS[$COMP_CWORD]}
#    echo "COMP_CWORD:$COMP_CWORD cur:$cur" >>/tmp/comp
    declare -a FLAGS
    declare -a OPTIONS
    declare -a MYWORDS

    local INDEX=`expr $COMP_CWORD - 1`
    MYWORDS=("${COMP_WORDS[@]:1:$COMP_CWORD}")

    FLAGS=('--debug' 'debug' '-d' 'debug' '--verbose' 'verbose' '-v' 'verbose' '--help' 'Show command help' '-h' 'Show command help')
    OPTIONS=('--data-file' 'File with data for POST/PUT/PATCH/DELETE requests')
    __digitaloceancl_handle_options_flags

    case $INDEX in

    0)
        __comp_current_options || return
        __digitaloceancl_dynamic_comp 'commands' 'GET'$'\t''GET call'$'\n''POST'$'\t''POST call'$'\n''help'$'\t''Show command help'

    ;;
    *)
    # subcmds
    case ${MYWORDS[0]} in
      GET)
        FLAGS+=()
        OPTIONS+=()
        __digitaloceancl_handle_options_flags
        case $INDEX in

        1)
            __comp_current_options || return
            __digitaloceancl_dynamic_comp 'commands' '/account'$'\t''Account information'$'\n''/droplets'$'\t''List all droplets'$'\n''/droplets/:id'$'\t''Retrieve a droplet by id'

        ;;
        *)
        # subcmds
        case ${MYWORDS[1]} in
          /account)
            FLAGS+=()
            OPTIONS+=()
            __digitaloceancl_handle_options_flags
            __comp_current_options true || return # no subcmds, no params/opts
          ;;
          /droplets)
            FLAGS+=()
            OPTIONS+=()
            __digitaloceancl_handle_options_flags
            __comp_current_options true || return # no subcmds, no params/opts
          ;;
          /droplets/:id)
            FLAGS+=()
            OPTIONS+=()
            __digitaloceancl_handle_options_flags
              case $INDEX in
              2)
                  __comp_current_options || return
              ;;
              *)
                __comp_current_options true || return # after parameters
                case ${MYWORDS[$INDEX-1]} in
                  --data-file)
                  ;;

                esac
                ;;
            esac
          ;;
        esac

        ;;
        esac
      ;;
      POST)
        FLAGS+=()
        OPTIONS+=()
        __digitaloceancl_handle_options_flags
        case $INDEX in

        1)
            __comp_current_options || return
            __digitaloceancl_dynamic_comp 'commands' '/droplets/:id/actions'$'\t''Trigger droplet action'

        ;;
        *)
        # subcmds
        case ${MYWORDS[1]} in
          /droplets/:id/actions)
            FLAGS+=()
            OPTIONS+=()
            __digitaloceancl_handle_options_flags
            __comp_current_options true || return # no subcmds, no params/opts
          ;;
        esac

        ;;
        esac
      ;;
      _meta)
        FLAGS+=()
        OPTIONS+=()
        __digitaloceancl_handle_options_flags
        case $INDEX in

        1)
            __comp_current_options || return
            __digitaloceancl_dynamic_comp 'commands' 'completion'$'\t''Shell completion functions'$'\n''pod'$'\t''Pod documentation'

        ;;
        *)
        # subcmds
        case ${MYWORDS[1]} in
          completion)
            FLAGS+=()
            OPTIONS+=()
            __digitaloceancl_handle_options_flags
            case $INDEX in

            2)
                __comp_current_options || return
                __digitaloceancl_dynamic_comp 'commands' 'generate'$'\t''Generate self completion'

            ;;
            *)
            # subcmds
            case ${MYWORDS[2]} in
              generate)
                FLAGS+=('--zsh' 'for zsh' '--bash' 'for bash')
                OPTIONS+=('--name' 'name of the program (optional, override name in spec)')
                __digitaloceancl_handle_options_flags
                  case $INDEX in
                  *)
                    __comp_current_options true || return # after parameters
                    case ${MYWORDS[$INDEX-1]} in
                      --data-file)
                      ;;
                      --name)
                      ;;

                    esac
                    ;;
                esac
              ;;
            esac

            ;;
            esac
          ;;
          pod)
            FLAGS+=()
            OPTIONS+=()
            __digitaloceancl_handle_options_flags
            case $INDEX in

            2)
                __comp_current_options || return
                __digitaloceancl_dynamic_comp 'commands' 'generate'$'\t''Generate self pod'

            ;;
            *)
            # subcmds
            case ${MYWORDS[2]} in
              generate)
                FLAGS+=()
                OPTIONS+=()
                __digitaloceancl_handle_options_flags
                __comp_current_options true || return # no subcmds, no params/opts
              ;;
            esac

            ;;
            esac
          ;;
        esac

        ;;
        esac
      ;;
      help)
        FLAGS+=('--all' '')
        OPTIONS+=()
        __digitaloceancl_handle_options_flags
        case $INDEX in

        1)
            __comp_current_options || return
            __digitaloceancl_dynamic_comp 'commands' 'GET'$'\n''POST'

        ;;
        *)
        # subcmds
        case ${MYWORDS[1]} in
          GET)
            FLAGS+=()
            OPTIONS+=()



( run in 0.469 second using v1.01-cache-2.11-cpan-f6376fbd888 )