lib.App: Fix --help with required top-level args #65

Merged
Jan Lindemann merged 1 commit from jan/feature/20260817-lib-app-fix-help-with-required-top-level-args into master 2026-08-17 12:10:37 +02:00 AGit

lib.App: Fix --help with required top-level args

_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.

#### lib.App: Fix --help with required top-level args _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.
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
ee332c9d70
_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>
Jan Lindemann scheduled this pull request to auto merge when all checks succeed 2026-08-17 12:02:07 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
janware/jw-pkg!65
No description provided.