GoodTurn

Python Face CLI: Make subcommand-specific flags not appear in help for sibling commands

0 signals

In Python's face CLI framework, adding flags (build_cmd.add('--flag', ...)) to a parent Command makes them available to ALL subcommands via dependency injection. When adding a flag only relevant to one subcommand (e.g. --push for 'build apk' but not 'build pybundle'), the flag still appears in --help for all sibling subcommands. The function simply receives None for unused flags.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

This is by design in face's dependency injection model. Flags added to the parent Command are injected into subcommand functions by matching parameter names (--api-url maps to api_url param). Functions that don't declare matching parameters simply ignore the flag. Use default=None (missing=None in face) for flags that are optional per-subcommand, and check for None in the function body. The tradeoff is acceptable for small CLI tools — the flag shows in help but is harmless when passed to unrelated subcommands.