🐛 Ensure that `options_metavar` is passed through correctly (#816)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Garrett Smith · committed by GitHub · parent f61933c · Browse files · 2 files·+36 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: svlandeg <svlandeg@github.com>
- Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
- Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Diff stats
2 files+36 added−6 removed
- tests:+18 added−0 removed
- other:+18 added−6 removed
Provenance
- Commit
10f23a4- Tree
c7e49e3- Author
Garrett Smith <garrett@placeon.earth>- Committer
GitHub <noreply@github.com>- Parent
f61933c
2 files changed+36 added−6 removed
modified:tests/test_others.py+18 added
319 unmodified lines320 321 prefix, opt = _split_opt("verbose")322 assert prefix == ""323 assert opt == "verbose"324+325+326+def test_options_metadata_typer_default():327+ app = typer.Typer(options_metavar="[options]")328+329+ @app.command()330+ def c1():331+ pass # pragma: no cover332+333+ @app.command(options_metavar="[OPTS]")334+ def c2():335+ pass # pragma: no cover336+337+ result = runner.invoke(app, ["c1", "--help"])338+ assert "Usage: root c1 [options]" in result.stdout339+340+ result = runner.invoke(app, ["c2", "--help"])341+ assert "Usage: root c2 [OPTS]" in result.stdoutmodified:typer/main.py+18 added-6 removed
183 unmodified lines184 context_settings: Optional[Dict[Any, Any]] = Default(None),185 help: Optional[str] = Default(None),186 epilog: Optional[str] = Default(None),187 short_help: Optional[str] = Default(None),188- options_metavar: str = Default("[OPTIONS]"),188+ options_metavar: Optional[str] = Default(None),189 add_help_option: bool = Default(True),190 hidden: bool = Default(False),191 deprecated: bool = Default(False),192 # Rich settings11 unmodified lines204 callback=f,205 help=help,206 epilog=epilog,207 short_help=short_help,208- options_metavar=options_metavar,208+ options_metavar=(209+ options_metavar or self._info_val_str("options_metavar")210+ ),211 add_help_option=add_help_option,212 hidden=hidden,213 deprecated=deprecated,214 rich_help_panel=rich_help_panel,10 unmodified lines225 context_settings: Optional[Dict[Any, Any]] = None,226 help: Optional[str] = None,227 epilog: Optional[str] = None,228 short_help: Optional[str] = None,227- options_metavar: str = "[OPTIONS]",229+ options_metavar: Optional[str] = None,230 add_help_option: bool = True,231 no_args_is_help: bool = False,232 hidden: bool = False,233 deprecated: bool = False,12 unmodified lines246 callback=f,247 help=help,248 epilog=epilog,249 short_help=short_help,248- options_metavar=options_metavar,250+ options_metavar=(251+ options_metavar or self._info_val_str("options_metavar")252+ ),253 add_help_option=add_help_option,254 no_args_is_help=no_args_is_help,255 hidden=hidden,256 deprecated=deprecated,21 unmodified lines278 callback: Optional[Callable[..., Any]] = Default(None),279 help: Optional[str] = Default(None),280 epilog: Optional[str] = Default(None),281 short_help: Optional[str] = Default(None),278- options_metavar: str = Default("[OPTIONS]"),282+ options_metavar: Optional[str] = Default(None),283 add_help_option: bool = Default(True),284 hidden: bool = Default(False),285 deprecated: bool = Default(False),286 # Rich settings13 unmodified lines300 callback=callback,301 help=help,302 epilog=epilog,303 short_help=short_help,300- options_metavar=options_metavar,304+ options_metavar=(305+ options_metavar or self._info_val_str("options_metavar")306+ ),307 add_help_option=add_help_option,308 hidden=hidden,309 deprecated=deprecated,310 rich_help_panel=rich_help_panel,22 unmodified lines333 ),334 )335 raise e336 337+ def _info_val_str(self, name: str) -> str:338+ val = getattr(self.info, name)339+ val_str = val.value if isinstance(val, DefaultPlaceholder) else val340+ assert isinstance(val_str, str)341+ return val_str342 343+344 def get_group(typer_instance: Typer) -> TyperGroup:345 group = get_group_from_info(346 TyperInfo(typer_instance),347 pretty_exceptions_short=typer_instance.pretty_exceptions_short,809 unmodified lines