Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completion Generation failure #77

Closed
hemna opened this issue Apr 15, 2019 · 2 comments
Closed

completion Generation failure #77

hemna opened this issue Apr 15, 2019 · 2 comments
Labels
Milestone

Comments

@hemna
Copy link

hemna commented Apr 15, 2019

Sourcing the generated bash completion script results in error.
I have a m4 template that has a single command with no options. If I add an option argument (that I don't really need), the the generated completion script works.

The Error when sourcing the generated completion script

waboring@walt-dev2:~/tmp: $  source build/completion/run.sh
bash: build/completion/run.sh: line 17: syntax error near unexpected token `)'
bash: build/completion/run.sh: line 17: `    )'

Here are my scripts

The source run.m4

waboring@walt-dev2:~/tmp: $  cat run.m4
#!/bin/bash
#
# DEFINE_SCRIPT_DIR
# ARG_POSITIONAL_SINGLE([command],)
# ARG_TYPE_GROUP_SET([commands], [COMMAND], [command], [test,but], [index])
# ARG_USE_ENV([DEPLOYMENT_TYPE], [openstack], [The deployment type you want])
# ARG_HELP([<The general help message of my script>])
# ARGBASH_SET_INDENT([  ])
# ARGBASH_GO


# [ <-- needed because of Argbash

# printf "Value of '%s': %s\\n" 'command' "$_arg_command"
#

if [ "$_arg_quiet" = "on" ]; then
    QUIET="-q"
fi
echo "TESTS"

# ] <-- needed because of Argbash

The generated completion script

waboring@walt-dev2:~/tmp: $  cat build/completion/run.sh
#!/bin/bash

# Put this file to /etc/bash_completion.d/run.sh_ENDL_()# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.8.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info

_run_sh ()
{
  local cur prev opts base
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD-1]}"
  all_long_opts="--help "
  all_short_opts="-h "
  case "$prev" in
    )
      COMPREPLY=( $(compgen -o bashdefault -o default -- "${cur}") )
      return 0
      ;;
    *)
      case "$cur" in
        --*)
          COMPREPLY=( $(compgen -W "${all_long_opts}" -- "${cur}") )
          return 0
          ;;
        -*)
          COMPREPLY=( $(compgen -W "${all_short_opts}" -- "${cur}") )
          return 0
          ;;
        *)
          COMPREPLY=( $(compgen -o bashdefault -o default -- "${cur}") )
          return 0
          ;;
      esac
  esac

}
complete -F _run_sh run.sh
### END OF CODE GENERATED BY Argbash (sortof) ### ])

If I add an optional argument, then the completion works.

waboring@walt-dev2:~/tmp: $  cat run.m4
#!/bin/bash
#
# DEFINE_SCRIPT_DIR
# ARG_POSITIONAL_SINGLE([command],)
# ARG_OPTIONAL_SINGLE([bogus], , [I don't want this optional argument], [*])
# ARG_TYPE_GROUP_SET([commands], [COMMAND], [command], [test,but], [index])
# ARG_USE_ENV([DEPLOYMENT_TYPE], [openstack], [The deployment type you want])
# ARG_HELP([<The general help message of my script>])
# ARGBASH_SET_INDENT([  ])
# ARGBASH_GO


# [ <-- needed because of Argbash

# printf "Value of '%s': %s\\n" 'command' "$_arg_command"
#

if [ "$_arg_quiet" = "on" ]; then
    QUIET="-q"
fi
echo "TEST"

# ] <-- needed because of Argbash

Here is the sourcing of the completion script:

waboring@walt-dev2:~/tmp: $  cat build/completion/run.sh
#!/bin/bash

# Put this file to /etc/bash_completion.d/run.sh_ENDL_()# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.8.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info

_run_sh ()
{
  local cur prev opts base
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD-1]}"
  all_long_opts="--bogus --help "
  all_short_opts="-h "
  case "$prev" in
    --bogus)
      COMPREPLY=( $(compgen -o bashdefault -o default -- "${cur}") )
      return 0
      ;;
    *)
      case "$cur" in
        --*)
          COMPREPLY=( $(compgen -W "${all_long_opts}" -- "${cur}") )
          return 0
          ;;
        -*)
          COMPREPLY=( $(compgen -W "${all_short_opts}" -- "${cur}") )
          return 0
          ;;
        *)
          COMPREPLY=( $(compgen -o bashdefault -o default -- "${cur}") )
          return 0
          ;;
      esac
  esac

}
complete -F _run_sh run.sh
### END OF CODE GENERATED BY Argbash (sortof) ### ])
waboring@walt-dev2:~/tmp: $  source build/completion/run.sh
waboring@walt-dev2:~/tmp: $
@hemna
Copy link
Author

hemna commented Apr 15, 2019

This also seems to happen if the only optional argument I have is a boolean

I have a single ARG_OPTIONAL_BOOLEAN

This causes the case "$prev" in
to be empty which causes the sourcing of the completion script to fail

{
  local cur prev opts base
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD-1]}"
  all_long_opts="--quiet --help "
  all_short_opts="-q -h "
  case "$prev" in
    )
      COMPREPLY=( $(compgen -o bashdefault -o default -- "${cur}") )
      return 0
      ;;
    *)

@matejak matejak added the bug label Apr 16, 2019
@matejak matejak added this to the 2.8.1 milestone Apr 16, 2019
@matejak
Copy link
Owner

matejak commented Jun 28, 2019

This issue has been fix in an unrelated commit.
Sorry for the mess.

@matejak matejak closed this as completed Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants