Open jelleklaver opened 4 years ago
I've hit a similar issue with groups:
#!/usr/bin/env python3
import fire
class Sub1(object):
def command1(self, param1):
print('command {}'.format(param1))
class Sub2(object):
def command2(self, param2):
print('command {}'.format(param2))
class CLI(object):
def __init__(self):
self.group1 = Sub1()
self.group2 = Sub2()
if __name__ == '__main__':
fire.Fire(CLI)
the generated autocompletion script looks like just a skeleton without my commands:
# bash completion support for cli2
# DO NOT EDIT.
# This script is autogenerated by fire/completion.py.
_complete-cli2()
{
local cur prev opts lastcommand
COMPREPLY=()
prev="${COMP_WORDS[COMP_CWORD-1]}"
cur="${COMP_WORDS[COMP_CWORD]}"
lastcommand=$(get_lastcommand)
opts=""
GLOBAL_OPTIONS=""
case "${lastcommand}" in
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
get_lastcommand()
{
local lastcommand i
lastcommand=
for ((i=0; i < ${#COMP_WORDS[@]}; ++i)); do
if [[ ${COMP_WORDS[i]} != -* ]] && [[ -n ${COMP_WORDS[i]} ]] && [[
${COMP_WORDS[i]} != $cur ]]; then
lastcommand=${COMP_WORDS[i]}
fi
done
echo $lastcommand
}
filter_options()
{
local opts
opts=""
for opt in "$@"
do
if ! option_already_entered $opt; then
opts="$opts $opt"
fi
done
echo $opts
}
option_already_entered()
{
local opt
for opt in ${COMP_WORDS[@]:0:COMP_CWORD}
do
if [ $1 == $opt ]; then
return 0
fi
done
return 1
}
is_prev_global()
{
local opt
for opt in $GLOBAL_OPTIONS
do
if [ $opt == $prev ]; then
return 0
fi
done
return 1
}
I'm trying to create a CLI which consists of several command groups. Commands within the command group share some common flags. In my example that is e.g. the
--namespace
flag in thesub
command group.I got this working. However, it breaks some fire functionality like generating command completion and a proper
--help
output.Note that I use the class object in stead of class instances for the command groups (in contrast to the documentation):
Running a command works properly (you can even rearrange the flag):
However, when running
mycli -- --completion
it will just print a completion script without any actual command completions.It seems that my use-case is either not supported, or I have implemented it quite wrong. I'm quite new to fire and python cli tools, so I suppose the latter could definitely be the case ;-).