Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions shtab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ def recurse(parser, prefix):
new_nargs,
) = recurse(
positional.choices[choice],
prefix + "_" + wordify(choice),
f"{prefix}_{wordify(choice)}",
)

sub_subparsers.extend(new_subparsers)
sub_option_strings.extend(new_option_strings)
sub_compgens.extend(new_compgens)
Expand Down Expand Up @@ -421,10 +422,16 @@ def complete_bash(parser, root_prefix=None, preamble="", choice_functions=None):
COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") )
else
# use choices & compgen
# call current_action_compgen without a subshell to support compopt
local IFS=$'\\n'
tmpfile="$(mktemp)"
[ -n "${current_action_compgen}" ] && \\
"${current_action_compgen}" "${completing_word}" > "$tmpfile"
mapfile current_action_compreply < "$tmpfile"
rm "$tmpfile"

COMPREPLY=( $(compgen -W "${current_action_choices}" -- "${completing_word}") \\
$([ -n "${current_action_compgen}" ] \\
&& "${current_action_compgen}" "${completing_word}") )
${current_action_compreply[@]} )
fi

return 0
Expand Down Expand Up @@ -524,7 +531,7 @@ def recurse(parser, prefix, paths=None):
format_positional(opt) for opt in subparser._get_positional_actions()
if not isinstance(opt.choices, dict) if opt.help != SUPPRESS)

new_pref = prefix + "_" + wordify(cmd)
new_pref = f"{prefix}_{wordify(cmd)}"
options = all_commands[new_pref] = {
"cmd": cmd, "help": (subparser.description or "").strip().split("\n")[0],
"arguments": arguments, "paths": [*paths, cmd]}
Expand Down