lib.App: Fix --help with required top-level args
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m11s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m17s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m53s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 6m49s
CI / Packaging test (push) Successful in 0s
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m11s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m17s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m53s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 6m49s
CI / Packaging test (push) Successful in 0s
_build_parser() does an early parse_known_args() to configure logging from the command line, but that call also enforces the top-level required arguments. --help is registered only after the early parse so the subcommands are present in the rendered help, so an app with a required top-level positional, such as a root Cmd that takes a config-file, exits with "required: config-file" on --help before the final parse_args() in __run() can handle it. Skip the early parse when help or shell completion is requested (the add_all_parsers flag, already set for -h, --help, and argcomplete). The subcommands and --help are still registered, and the final parse_args() shows the help without enforcing the required arguments. The log-flag configuration and the running-command debug line move inside the guard; neither help nor completion logs, so they do not need them. Assisted-by: pi <unsloth/Qwen3.8-27B-GGUF:Q4_K_M> Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
afe4a0a7c1
commit
ee332c9d70
1 changed files with 10 additions and 5 deletions
|
|
@ -229,11 +229,16 @@ class App: # export
|
|||
)
|
||||
self._add_arguments(self.__parser)
|
||||
|
||||
args, _ = self.__parser.parse_known_args(argv)
|
||||
set_log_flags(args.log_flags)
|
||||
set_log_level(args.log_level)
|
||||
|
||||
log(DEBUG, f'-------------- Running: >{pretty_cmd(cmdline)}<')
|
||||
if not add_all_parsers:
|
||||
# Parse known args and configure logging, but only if we're not on
|
||||
# an interactive usage mission. The problem with parse_known_args()
|
||||
# is that it fails over missing but required arguments, and we
|
||||
# don't want that to happen and never get to the point where
|
||||
# '--help' is registered.
|
||||
args, _ = self.__parser.parse_known_args(argv)
|
||||
set_log_flags(args.log_flags)
|
||||
set_log_level(args.log_level)
|
||||
log(DEBUG, f'-------------- Running: >{pretty_cmd(cmdline)}<')
|
||||
|
||||
add_cmds_to_parser(self, self.__parser, self.__cmds, all = add_all_parsers)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue