✨ Add support for help for CLI arguments (#123)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* ✨ Implement custom TyperCommand and TyperArgument to support help in CLI Arguments * ✨ Update data models to store help for CLI Arguments * ✨ Add help to typer.Argument() * ✨ Use new TyperCommand and TyperArgument classes by default to support CLI Arguments with help * ✅ Update failing test * ✨ Make showing default values default to true and support arguments hidden from help text * ✨ Add docs for CLI arguments with defaults, help, and new features * 📝 Update CLI options with new show_default=True by default * 📝 Add example of CLI arguments with tuples * 📝 Update docs with new generated help text for CLI arguments * 📝 Use Optional for None example in micro-intro to types * ✅ Add tests for new CLI argument features from docs examples * ✅ Update tests with new generated help text for CLI arguments * ✅ Add tests for CLI arguments with tuple defaults * 🔧 Update MkDocs with new sections * ✨ make show_envvar default to True * ✨ Add docs for envvar in CLI arguments * ✅ Add tests for CLI arguments with env vars from docs * 🎨 Add format to CLI usage examples in docs * 🔧 Add section about CLI arguments with env vars to MkDocs * 📝 Fix link in docs with new structure * 🎨 Fix format in first-steps
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
64 files+1749 added−400 removed
- tests:+620 added−113 removed
- other:+1129 added−287 removed
Provenance
- Commit
15380dd- Tree
ce9bcb3- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
338d05f
64 files changed+1749 added−400 removed
added:docs/src/arguments/default/tutorial001.py+9 added
1+import typer2+3+4+def main(name: str = typer.Argument("Wade Wilson")):5+ typer.echo(f"Hello {name}")6+7+8+if __name__ == "__main__":9+ typer.run(main)added:docs/src/arguments/default/tutorial002.py+15 added
1+import random2+3+import typer4+5+6+def get_name():7+ return random.choice(["Deadpool", "Rick", "Morty", "Hiro"])8+9+10+def main(name: str = typer.Argument(get_name)):11+ typer.echo(f"Hello {name}")12+13+14+if __name__ == "__main__":15+ typer.run(main)added:docs/src/arguments/envvar/tutorial001.py+9 added
1+import typer2+3+4+def main(name: str = typer.Argument("World", envvar="AWESOME_NAME")):5+ typer.echo(f"Hello Mr. {name}")6+7+8+if __name__ == "__main__":9+ typer.run(main)added:docs/src/arguments/envvar/tutorial002.py+9 added
1+import typer2+3+4+def main(name: str = typer.Argument("World", envvar=["AWESOME_NAME", "GOD_NAME"])):5+ typer.echo(f"Hello Mr. {name}")6+7+8+if __name__ == "__main__":9+ typer.run(main)added:docs/src/arguments/envvar/tutorial003.py+9 added
1+import typer2+3+4+def main(name: str = typer.Argument("World", envvar="AWESOME_NAME", show_envvar=False)):5+ typer.echo(f"Hello Mr. {name}")6+7+8+if __name__ == "__main__":9+ typer.run(main)added:docs/src/arguments/help/tutorial001.py+9 added
1+import typer2+3+4+def main(name: str = typer.Argument(..., help="The name of the user to greet")):5+ typer.echo(f"Hello {name}")6+7+8+if __name__ == "__main__":9+ typer.run(main)added:docs/src/arguments/help/tutorial002.py+12 added
1+import typer2+3+4+def main(name: str = typer.Argument(..., help="The name of the user to greet")):5+ """6+ Say hi to NAME very gently, like Dirk.7+ """8+ typer.echo(f"Hello {name}")9+10+11+if __name__ == "__main__":12+ typer.run(main)added:docs/src/arguments/help/tutorial003.py+12 added
1+import typer2+3+4+def main(name: str = typer.Argument("World", help="Who to greet")):5+ """6+ Say hi to NAME very gently, like Dirk.7+ """8+ typer.echo(f"Hello {name}")9+10+11+if __name__ == "__main__":12+ typer.run(main)added:docs/src/arguments/help/tutorial004.py+12 added
1+import typer2+3+4+def main(name: str = typer.Argument("World", help="Who to greet", show_default=False)):5+ """6+ Say hi to NAME very gently, like Dirk.7+ """8+ typer.echo(f"Hello {name}")9+10+11+if __name__ == "__main__":12+ typer.run(main)added:docs/src/arguments/help/tutorial005.py+13 added
1+import typer2+3+4+def main(5+ name: str = typer.Argument(6+ "Wade Wilson", help="Who to greet", show_default="Deadpoolio the amazing's name"7+ )8+):9+ typer.echo(f"Hello {name}")10+11+12+if __name__ == "__main__":13+ typer.run(main)added:docs/src/arguments/help/tutorial006.py+9 added
1+import typer2+3+4+def main(name: str = typer.Argument("World", metavar="✨username✨")):5+ typer.echo(f"Hello {name}")6+7+8+if __name__ == "__main__":9+ typer.run(main)added:docs/src/arguments/help/tutorial007.py+12 added
1+import typer2+3+4+def main(name: str = typer.Argument("World", hidden=True)):5+ """6+ Say hi to NAME very gently, like Dirk.7+ """8+ typer.echo(f"Hello {name}")9+10+11+if __name__ == "__main__":12+ typer.run(main)added:docs/src/arguments/optional/tutorial001.py+9 added
1+import typer2+3+4+def main(name: str = typer.Argument(...)):5+ typer.echo(f"Hello {name}")6+7+8+if __name__ == "__main__":9+ typer.run(main)added:docs/src/arguments/optional/tutorial002.py+14 added
1+from typing import Optional2+3+import typer4+5+6+def main(name: Optional[str] = typer.Argument(None)):7+ if name is None:8+ typer.echo("Hello World!")9+ else:10+ typer.echo(f"Hello {name}")11+12+13+if __name__ == "__main__":14+ typer.run(main)deleted:docs/src/arguments/tutorial001.py-9 removed
1-import typer2-3-4-def main(name: str = typer.Argument(...)):5- typer.echo(f"Hello {name}")6-7-8-if __name__ == "__main__":9- typer.run(main)deleted:docs/src/arguments/tutorial002.py-12 removed
1-import typer2-3-4-def main(name: str = typer.Argument(None)):5- if name is None:6- typer.echo("Hello World!")7- else:8- typer.echo(f"Hello {name}")9-10-11-if __name__ == "__main__":12- typer.run(main)deleted:docs/src/arguments/tutorial003.py-9 removed
1-import typer2-3-4-def main(name: str = typer.Argument("Wade Wilson")):5- typer.echo(f"Hello {name}")6-7-8-if __name__ == "__main__":9- typer.run(main)added:docs/src/multiple_values/arguments_with_multiple_values/tutorial002.py+16 added
1+from typing import Tuple2+3+import typer4+5+6+def main(7+ names: Tuple[str, str, str] = typer.Argument(8+ ("Harry", "Hermione", "Ron"), help="Select 3 characters to play with"9+ )10+):11+ for name in names:12+ typer.echo(f"Hello {name}")13+14+15+if __name__ == "__main__":16+ typer.run(main)modified:docs/src/options/help/tutorial002.py+1 added-1 removed
1 import typer2 3 4-def main(fullname: str = typer.Option("Wade Wilson", show_default=True)):4+def main(fullname: str = typer.Option("Wade Wilson", show_default=False)):5 typer.echo(f"Hello {fullname}")6 7 8 if __name__ == "__main__":1 unmodified lineadded:docs/tutorial/arguments/default.md+99 added
1+We can also use the same `typer.Argument()` to set a default value.2+3+That way the *CLI argument* will be optional *and also* have a default value.4+5+## An optional *CLI argument* with a default6+7+We can also use `typer.Argument()` to make a *CLI argument* have a default value other than `None`:8+9+```Python hl_lines="4"10+{!./src/arguments/default/tutorial001.py!}11+```12+13+!!! tip14+ Because now the value will be a `str` passed by the user or the default value of `"Wade Wilson"` which is also a `str`, we know the value will never be `None`, so we don't have to (and shouldn't) use `Optional[str]`.15+16+ Have in mind that the `Optional[something]` tells Python that a value "could be `None`". But the use of `Optional` doesn't affect Typer in any way, e.g. it doesn't tell Typer if a value is required or not.17+18+Check it:19+20+<div class="termy">21+22+```console23+// Check the help24+$ python main.py --help25+26+// Notice the [default: Wade Wilson] ✨27+Usage: main.py [OPTIONS] [NAME]28+29+Arguments:30+ [NAME] [default: Wade Wilson]31+32+Options:33+ --install-completion Install completion for the current shell.34+ --show-completion Show completion for the current shell, to copy it or customize the installation.35+ --help Show this message and exit.36+37+// With no optional CLI argument38+$ python main.py39+40+Hello Wade Wilson41+42+// With one CLI argument43+$ python main.py Camila44+45+Hello Camila46+```47+48+</div>49+50+## Dynamic default value51+52+And we can even make the default value be dynamically generated by passing a function as the first function argument:53+54+```Python hl_lines="6 7 10"55+{!./src/arguments/default/tutorial002.py!}56+```57+58+In this case, we created the function `get_name` that will just return a random `str` each time.59+60+And we pass it as the first function argument to `typer.Argument()`.61+62+Check it:63+64+<div class="termy">65+66+```console67+// Check the help68+$ python main.py --help69+70+Usage: main.py [OPTIONS] [NAME]71+72+Arguments:73+ [NAME] [default: (dynamic)]74+75+Options:76+ --install-completion Install completion for the current shell.77+ --show-completion Show completion for the current shell, to copy it or customize the installation.78+ --help Show this message and exit.79+80+// Try it several times, it will use a random default each time81+$ python main.py82+83+Hello Deadpool84+85+$ python main.py86+87+Hello Hiro88+89+$ python main.py90+91+Hello Rick92+93+// Now pass a value for the CLI argument94+$ python main.py Camila95+96+Hello Camila97+```98+99+</div>added:docs/tutorial/arguments/envvar.md+127 added
1+You can also configure a *CLI argument* to read a value from an environment variable if it is not provided in the command line as a *CLI argument*.2+3+To do that, use the `envvar` parameter for `typer.Argument()`:4+5+```Python hl_lines="4"6+{!./src/arguments/envvar/tutorial001.py!}7+```8+9+In this case, the *CLI argument* `name` will have a default value of `"World"`, but will also read any value passed to the environment variable `AWESOME_NAME` if no value is provided in the command line:10+11+<div class="termy">12+13+```console14+// Check the help15+$ python main.py --help16+17+Usage: main.py [OPTIONS] [NAME]18+19+Arguments:20+ [NAME] [env var: AWESOME_NAME;default: World]21+22+Options:23+ --install-completion Install completion for the current shell.24+ --show-completion Show completion for the current shell, to copy it or customize the installation.25+ --help Show this message and exit.26+27+// Call it without a CLI argument28+$ python main.py29+30+Hello Mr. World31+32+// Now pass a value for the CLI argument33+$ python main.py Czernobog34+35+Hello Mr. Czernobog36+37+// And now use the environment variable38+$ AWESOME_NAME=Wednesday python main.py39+40+Hello Mr. Wednesday41+42+// CLI arguments take precedence over env vars43+$ AWESOME_NAME=Wednesday python main.py Czernobog44+45+Hello Mr. Czernobog46+```47+48+</div>49+50+## Multiple environment variables51+52+You are not restricted to a single environment variable, you can declare a list of environment variables that could be used to get a value if it was not passed in the command line:53+54+```Python hl_lines="4"55+{!./src/arguments/envvar/tutorial002.py!}56+```57+58+Check it:59+60+<div class="termy">61+62+```console63+// Check the help64+$ python main.py --help65+66+Usage: main.py [OPTIONS] [NAME]67+68+Arguments:69+ [NAME] [env var: AWESOME_NAME, GOD_NAME;default: World]70+71+Options:72+ --install-completion Install completion for the current shell.73+ --show-completion Show completion for the current shell, to copy it or customize the installation.74+ --help Show this message and exit.75+76+// Try the first env var77+$ AWESOME_NAME=Wednesday python main.py78+79+Hello Mr. Wednesday80+81+// Try the second env var82+$ GOD_NAME=Anubis python main.py83+84+Hello Mr. Anubis85+```86+87+</div>88+89+## Hide an env var from the help text90+91+By default, environment variables used will be shown in the help text, but you can disable them with `show_envvar=False`:92+93+```Python hl_lines="4"94+{!../docs/src/arguments/envvar/tutorial003.py!}95+```96+97+Check it:98+99+<div class="termy">100+101+```console102+//Check the help103+$ python main.py --help104+105+// It won't show the env var106+Usage: main.py [OPTIONS] [NAME]107+108+Arguments:109+ [NAME] [default: World]110+111+Options:112+ --install-completion Install completion for the current shell.113+ --show-completion Show completion for the current shell, to copy it or customize the installation.114+ --help Show this message and exit.115+116+// But it will still be able to use it117+$ AWESOME_NAME=Wednesday python main.py118+119+Hello Mr. Wednesday120+```121+122+</div>123+124+!!! note "Technical Details"125+ In Click applications the env vars are hidden by default. 🙈126+127+ In **Typer** these env vars are shown by default. 👀added:docs/tutorial/arguments/help.md+270 added
1+In the *First Steps* section you saw how to add help for a CLI app/command by adding it to a function's <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>.2+3+Here's how that last example looked like:4+5+```Python6+{!./src/first_steps/tutorial006.py!}7+```8+9+Now that you also know how to use `typer.Argument()`, let's use it to add documentation specific for a *CLI argument*.10+11+## Add a `help` text for a *CLI argument*12+13+You can use the `help` parameter to add a help text for a *CLI argument*:14+15+```Python hl_lines="4"16+{!../docs/src/arguments/help/tutorial001.py!}17+```18+19+And it will be used in the automatic `--help` option:20+21+<div class="termy">22+23+```console24+$ python main.py --help25+26+// Check the section with Arguments below 🚀27+Usage: main.py [OPTIONS] NAME28+29+Arguments:30+ NAME The name of the user to greet [required]31+32+Options:33+ --install-completion Install completion for the current shell.34+ --show-completion Show completion for the current shell, to copy it or customize the installation.35+ --help Show this message and exit.36+```37+38+</div>39+40+## Combine help text and docstrings41+42+And of course, you can also combine that `help` with the <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>:43+44+```Python hl_lines="4 5 6 7"45+{!../docs/src/arguments/help/tutorial002.py!}46+```47+48+And the `--help` option will combine all the information:49+50+<div class="termy">51+52+```console53+$ python main.py --help54+55+// Notice that we have the help text from the docstring and also the Arguments 📝56+Usage: main.py [OPTIONS] NAME57+58+ Say hi to NAME very gently, like Dirk.59+60+Arguments:61+ NAME The name of the user to greet [required]62+63+Options:64+ --install-completion Install completion for the current shell.65+ --show-completion Show completion for the current shell, to copy it or customize the installation.66+ --help Show this message and exit.67+```68+69+</div>70+71+## Help with defaults72+73+If you have a *CLI argument* with a default value, like `"World"`:74+75+```Python hl_lines="4"76+{!../docs/src/arguments/help/tutorial003.py!}77+```78+79+It will show that default value in the help text:80+81+<div class="termy">82+83+```console84+$ python main.py --help85+86+// Notice the [default: World] 🔍87+Usage: main.py [OPTIONS] [NAME]88+89+ Say hi to NAME very gently, like Dirk.90+91+Arguments:92+ [NAME] Who to greet [default: World]93+94+Options:95+ --install-completion Install completion for the current shell.96+ --show-completion Show completion for the current shell, to copy it or customize the installation.97+ --help Show this message and exit.98+```99+100+</div>101+102+But you can disable that if you want to, with `show_default=False`:103+104+```Python hl_lines="4"105+{!../docs/src/arguments/help/tutorial004.py!}106+```107+108+And then it won't show the default value:109+110+<div class="termy">111+112+```console113+$ python main.py --help114+115+// Notice the there's no [default: World] now 🔥116+Usage: main.py [OPTIONS] [NAME]117+118+ Say hi to NAME very gently, like Dirk.119+120+Arguments:121+ [NAME] Who to greet122+123+Options:124+ --install-completion Install completion for the current shell.125+ --show-completion Show completion for the current shell, to copy it or customize the installation.126+127+ --help Show this message and exit.128+```129+130+</div>131+132+!!! note "Technical Details"133+ In Click applications the default values are hidden by default. 🙈134+135+ In **Typer** these default values are shown by default. 👀136+137+## Custom default string138+139+You can use the same `show_default` to pass a custom string (instead of a `bool`) to customize the default value to be shown in the help text:140+141+```Python hl_lines="6"142+{!../docs/src/arguments/help/tutorial005.py!}143+```144+145+And it will be used in the help text:146+147+<div class="termy">148+149+```console150+$ python main.py --help151+152+Usage: main.py [OPTIONS] [NAME]153+154+Arguments:155+ [NAME] Who to greet [default: (Deadpoolio the amazing's name)]156+157+158+Options:159+ --install-completion Install completion for the current shell.160+ --show-completion Show completion for the current shell, to copy it or customize the installation.161+ --help Show this message and exit.162+163+// See it shows "(Deadpoolio the amazing's name)" instead of the actual default of "Wade Wilson"164+```165+166+</div>167+168+## Custom help name (`metavar`)169+170+You can also customize the text used in the generated help text to represent a *CLI argument*.171+172+By default, it will be the same name you declared, in uppercase letters.173+174+So, if you declare it as:175+176+```Python177+name: str178+```179+180+It will be shown as:181+182+```183+NAME184+```185+186+But you can customize it with the `metavar` parameter for `typer.Argument()`.187+188+For example, let's say you don't want to have the default of `NAME`, you want to have `username`, in lowercase, and you really want ✨ emojis ✨ everywhere:189+190+```Python hl_lines="4"191+{!../docs/src/arguments/help/tutorial006.py!}192+```193+194+Now the generated help text will have `✨username✨` instead of `NAME`:195+196+<div class="termy">197+198+```console199+$ python main.py --help200+201+Usage: main.py [OPTIONS] ✨username✨202+203+Arguments:204+ ✨username✨ [default: World]205+206+Options:207+ --install-completion Install completion for the current shell.208+ --show-completion Show completion for the current shell, to copy it or customize the installation.209+ --help Show this message and exit.210+```211+212+</div>213+214+## Hide a *CLI argument* from the help text215+216+If you want, you can make a *CLI argument* **not** show up in the `Arguments` section in the help text.217+218+You will probably not want to do this normally, but it's possible:219+220+```Python hl_lines="4"221+{!../docs/src/arguments/help/tutorial007.py!}222+```223+224+Check it:225+226+<div class="termy">227+228+```console229+$ python main.py --help230+231+// Notice there's no Arguments section at all 🔥232+Usage: main.py [OPTIONS] [NAME]233+234+ Say hi to NAME very gently, like Dirk.235+236+Options:237+ --install-completion Install completion for the current shell.238+ --show-completion Show completion for the current shell, to copy it or customize the installation.239+ --help Show this message and exit.240+```241+242+</div>243+244+!!! info245+ Have in mind that the *CLI argument* will still show up in the first line with `Usage`.246+247+ But it won't show up in the main help text under the `Arguments` section.248+249+### Help text for *CLI arguments* in Click250+251+Click itself doesn't support adding help for *CLI arguments*, and it doesn't generate help for them as in the "`Arguments:`" sections in the examples above.252+253+Not supporting `help` in *CLI arguments* is an intentional <a href="https://click.palletsprojects.com/en/7.x/documentation/#documenting-arguments" class="external-link" target="_blank">design decision in Click</a>:254+255+> This is to follow the general convention of Unix tools of using arguments for only the most necessary things, and to document them in the command help text by referring to them by name.256+257+So, in Click applications, you are expected to write all the documentation for *CLI arguments* by hand in the <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>.258+259+---260+261+Nevertheless, **Typer supports `help` for *CLI arguments***. ✨ 🤷♂262+263+**Typer** doesn't follow that convention and instead supports `help` to make it easier to have consistent help texts with a consistent format for your CLI programs. 🎨264+265+This is also to help you create CLI programs that are ✨ awesome ✨ *by default*. With very little code.266+267+If you want to keep Click's convention in a **Typer** app, you can do it with the `hidden` parameter as described above.268+269+!!! note "Technical Details"270+ To support `help` in *CLI arguments* **Typer** does a lot of internal work in its own sub-classes of Click's internal classes.added:docs/tutorial/arguments/index.md+3 added
1+In the next few sections we'll see some ways to modify how *CLI arguments* work.2+3+We'll create optional *CLI arguments*, we'll add integrated help for *CLI arguments*, etc.added:docs/tutorial/arguments/optional.md+158 added
1+We said before that *by default*:2+3+* *CLI options* are **optional**4+* *CLI arguments* are **required**5+6+Again, that's how they work *by default*, and that's the convention in many CLI programs and systems.7+8+But you can change that.9+10+In fact, it's very common to have **optional** *CLI arguments*, it's way more common than having **required** *CLI options*.11+12+As an example of how it could be useful, let's see how the `ls` CLI program works.13+14+<div class="termy">15+16+```console17+// If you just type18+$ ls19+20+// ls will "list" the files and directories in the current directory21+typer tests README.md LICENSE22+23+// But it also receives an optional CLI argument24+$ ls ./tests/25+26+// And then ls will list the files and directories inside of that directory from the CLI argument27+__init__.py test_tutorial28+```29+30+</div>31+32+### An alternative *CLI argument* declaration33+34+In the [First Steps](../first-steps.md#add-a-cli-argument){.internal-link target=_blank} you saw how to add a *CLI argument*:35+36+```Python hl_lines="4"37+{!./src/first_steps/tutorial002.py!}38+```39+40+Now let's see an alternative way to create the same *CLI argument*:41+42+```Python hl_lines="4"43+{!./src/arguments/optional/tutorial001.py!}44+```45+46+Before, you had this function parameter:47+48+```Python49+name: str50+```51+52+And because `name` didn't have any default value it would be a **required parameter** for the Python function, in Python terms.53+54+**Typer** does the same and makes it a **required** *CLI argument*.55+56+And then we changed it to:57+58+```Python59+name: str = typer.Argument(...)60+```61+62+But now as `typer.Argument()` is the "default value" of the function's parameter, it would mean that "it is no longer required" (in Python terms).63+64+As we no longer have the Python function default value (or its absence) to tell if something is required or not and what is the default value, the first parameter to `typer.Argument()` serves the same purpose of defining that default value, or making it required.65+66+To make it *required*, we pass `...` as the first function argument passed to `typer.Argument(...)`.67+68+!!! info69+ If you hadn't seen that `...` before: it is a special single value, it is <a href="https://docs.python.org/3/library/constants.html#Ellipsis" class="external-link" target="_blank">part of Python and is called "Ellipsis"</a>.70+71+All we did there achieves the same thing as before, a **required** *CLI argument*:72+73+<div class="termy">74+75+```console76+$ python main.py77+78+Usage: main.py [OPTIONS] NAME79+Try "main.py --help" for help.80+81+Error: Missing argument 'NAME'.82+```83+84+</div>85+86+It's still not very useful, but it works correctly.87+88+And being able to declare a **required** *CLI argument* using `name: str = typer.Argument(...)` that works exactly the same as `name: str` will come handy later.89+90+### Make an optional *CLI argument*91+92+Now, finally what we came for, an optional *CLI argument*.93+94+To make a *CLI argument* optional, use `typer.Argument()` and pass a different "default" as the first parameter to `typer.Argument()`, for example `None`:95+96+```Python hl_lines="6"97+{!./src/arguments/optional/tutorial002.py!}98+```99+100+Now we have:101+102+```Python103+name: Optional[str] = typer.Argument(None)104+```105+106+Because we are using `typer.Argument()` **Typer** will know that this is a *CLI argument* (no matter if *required* or *optional*).107+108+And because the first parameter passed to `typer.Argument(None)` (the new "default" value) is `None`, **Typer** knows that this is an **optional** *CLI argument*, if no value is provided when calling it in the command line, it will have that default value of `None`.109+110+!!! tip111+ By using `Optional` your editor will be able to know that the value *could* be `None`, and will be able to warn you if you do something assuming it is a `str` that would break if it was `None`.112+113+Check the help:114+115+<div class="termy">116+117+```console118+// First check the help119+$ python main.py --help120+121+Usage: main.py [OPTIONS] [NAME]122+123+Arguments:124+ [NAME]125+126+Options:127+ --install-completion Install completion for the current shell.128+ --show-completion Show completion for the current shell, to copy it or customize the installation.129+ --help Show this message and exit.130+```131+132+</div>133+134+!!! tip135+ Notice that `NAME` is still a *CLI argument*, it's shown up there in the "`Usage: main.py` ...".136+137+ Also notice that now `[NAME]` has brackets ("`[`" and "`]`") around (before it was just `NAME`) to denote that it's **optional**, not **required**.138+139+Now run it and test it:140+141+<div class="termy">142+143+```console144+// With no CLI argument145+$ python main.py146+147+Hello World!148+149+// With one optional CLI argument150+$ python main.py Camila151+152+Hello Camila153+```154+155+</div>156+157+!!! tip158+ Notice that "`Camila`" here is an optional *CLI argument*, not a *CLI option*, because we didn't use something like "`--name Camila`", we just passed "`Camila`" directly to the program.added:docs/tutorial/arguments/other-uses.md+3 added
1+`typer.Argument()` has several other use cases. Such as for data validation, to enable other features, etc.2+3+You will see about these use cases later in the docs.modified:docs/tutorial/multiple-values/arguments-with-multiple-values.md+48 added
24 unmodified lines25 We also declared a final *CLI argument* `celebration`, and it's correctly used even if we pass an arbitrary number of `files` first.26 27 !!! info28 A `List` can only be used in the last command (if there are subcommands), as this will take anything to the right and assume it's part of the expected *CLI arguments*.29+30+## *CLI arguments* with tuples31+32+If you want a specific number of values and types, you can use a tuple, and it can even have default values:33+34+```Python hl_lines="7 8"35+{!./src/multiple_values/arguments_with_multiple_values/tutorial002.py!}36+```37+38+Check it:39+40+<div class="termy">41+42+```console43+// Check the help44+$ python main.py --help45+46+Usage: main.py [OPTIONS] [NAMES]...47+48+Arguments:49+ [NAMES]... [default: Harry, Hermione, Ron]50+51+Options:52+ --install-completion Install completion for the current shell.53+ --show-completion Show completion for the current shell, to copy it or customize the installation.54+ --help Show this message and exit.55+56+// Use it with its defaults57+$ python main.py58+59+Hello Harry60+Hello Hermione61+Hello Ron62+63+// If you pass an invalid number of arguments you will get an error64+$ python main.py Draco Hagrid65+66+Error: argument names takes 3 values67+68+// And if you pass the exact number of values it will work correctly69+$ python main.py Draco Hagrid Dobby70+71+Hello Draco72+Hello Hagrid73+Hello Dobby74+```75+76+</div>modified:docs/tutorial/options/help.md+17 added-16 removed
1-In the *First Steps* section you saw how to add help for a CLI app/command by adding it to a function's <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>.1+You already saw how to add a help text for *CLI arguments* with the `help` parameter.2 3-Here's how that last example looked like:3+Let's now do the same for *CLI options*:4 5-```Python6-{!./src/first_steps/tutorial006.py!}7-```8-9-Now we'll add a *help* section to the *CLI options*:10-5 ```Python hl_lines="6 7"6 {!./src/options/help/tutorial001.py!}7 ```8 37 unmodified lines46 Say hi to NAME, optionally with a --lastname.47 48 If --formal is used, say hi very formally.49 50+Arguments:51+ NAME [required]52+53 Options:57- --lastname TEXT Last name of person to greet.58- --formal / --no-formal Say hi formally.54+ --lastname TEXT Last name of person to greet. [default: ]55+ --formal / --no-formal Say hi formally. [default: False]56 --install-completion Install completion for the current shell.57 --show-completion Show completion for the current shell, to copy it or customize the installation.58 --help Show this message and exit.59 1 unmodified line61 ```62 63 </div>64 68-## Show default in help65+## Hide default from help66 70-You can tell Typer to show the default value in the help text with `show_default=True`:67+You can tell Typer to not show the default value in the help text with `show_default=False`:68 69 ```Python hl_lines="4"70 {!./src/options/help/tutorial002.py!}71 ```72 76-And it will show up in the help text:73+And it will no longer show the default value in the help text:74 75 <div class="termy">76 77 ```console6 unmodified lines84 85 Usage: main.py [OPTIONS]86 87 Options:91- --fullname TEXT [default: Wade Wilson]88+ --fullname TEXT89 --install-completion Install completion for the current shell.90 --show-completion Show completion for the current shell, to copy it or customize the installation.91 --help Show this message and exit.92+93+// Notice there's no [default: Wade Wilson] 🔥94 ```95 96 </div>97 99-!!! tip100- Notice the `[default: Wade Wilson]` in the help text.98+!!! note "Technical Details"99+ In Click applications the default values are hidden by default. 🙈100+101+ In **Typer** these default values are shown by default. 👀modified:docs/tutorial/subcommands/name-and-help.md-1 removed
251 unmodified lines252 // Check the main help253 $ python main.py --help254 255 // Check the command new-users and its help text256-256 Usage: main.py [OPTIONS] COMMAND [ARGS]...257 258 Options:259 --install-completion Install completion for the current shell.203 unmodified linesdeleted:docs/tutorial/arguments.md-208 removed
1-Let's see how to configure *CLI arguments* with `typer.Argument()`.2-3-## Optional *CLI arguments*4-5-We said before that *by default*:6-7-* *CLI options* are **optional**8-* *CLI arguments* are **required**9-10-Again, that's how they work *by default*, and that's the convention in many CLI programs and systems.11-12-But you can change that.13-14-In fact, it's very common to have **optional** *CLI arguments*, it's way more common than having **required** *CLI options*.15-16-As an example of how it could be useful, let's see how the `ls` CLI program works.17-18-<div class="termy">19-20-```console21-// If you just type22-$ ls23-24-// ls will "list" the files and directories in the current directory25-typer tests README.md LICENSE26-27-// But it also receives an optional CLI argument28-$ ls ./tests/29-30-// And then ls will list the files and directories inside of that directory from the CLI argument31-__init__.py test_tutorial32-```33-34-</div>35-36-### An alternative *CLI argument* declaration37-38-In the [First Steps](first-steps.md#add-a-cli-argument){.internal-link target=_blank} you saw how to add a *CLI argument*:39-40-```Python hl_lines="4"41-{!./src/first_steps/tutorial002.py!}42-```43-44-Now let's see an alternative way to create the same *CLI argument*:45-46-```Python hl_lines="4"47-{!./src/arguments/tutorial001.py!}48-```49-50-Before, you had this function parameter:51-52-```Python53-name: str54-```55-56-And because `name` didn't have any default value it would be a **required parameter** for the Python function, in Python terms.57-58-**Typer** does the same and makes it a **required** *CLI argument*.59-60-And then we changed it to:61-62-```Python63-name: str = typer.Argument(...)64-```65-66-But now as `typer.Argument()` is the "default value" of the function's parameter, it would mean that "it is no longer required" (in Python terms).67-68-As we no longer have the Python function default value (or its absence) to tell if something is required or not and what is the default value, the first parameter to `typer.Argument()` serves the same purpose of defining that default value, or making it required.69-70-To make it *required*, we pass `...` as the first function argument passed to `typer.Argument(...)`.71-72-!!! info73- If you hadn't seen that `...` before: it is a a special single value, it is <a href="https://docs.python.org/3/library/constants.html#Ellipsis" class="external-link" target="_blank">part of Python and is called "Ellipsis"</a>.74-75-All we did there achieves the same thing as before, a **required** *CLI argument*:76-77-<div class="termy">78-79-```console80-$ python main.py81-82-Usage: main.py [OPTIONS] NAME83-Try "main.py --help" for help.84-85-Error: Missing argument 'NAME'.86-```87-88-</div>89-90-It's still not very useful, but it works correctly.91-92-And being able to declare a **required** *CLI argument* using `name: str = typer.Argument(...)` that works exactly the same as `name: str` will come handy later.93-94-### Make an optional *CLI argument*95-96-Now, finally what we came for, an optional *CLI argument*.97-98-To make a *CLI argument* optional, use `typer.Argument()` and pass a different "default" as the first parameter to `typer.Argument()`, for example `None`:99-100-```Python hl_lines="4"101-{!./src/arguments/tutorial002.py!}102-```103-104-Now we have:105-106-```Python107-name: str = typer.Argument(None)108-```109-110-Because we are using `typer.Argument()` **Typer** will know that this is a *CLI argument* (no matter if *required* or *optional*).111-112-And because the first parameter passed to `typer.Argument(None)` (the new "default" value) is `None`, **Typer** knows that this is an **optional** *CLI argument*, if no value is provided when calling it in the command line, it will have that default value of `None`.113-114-Check the help:115-116-<div class="termy">117-118-```console119-// First check the help120-$ python main.py --help121-122-Usage: main.py [OPTIONS] [NAME]123-124-Options:125- --install-completion Install completion for the current shell.126- --show-completion Show completion for the current shell, to copy it or customize the installation.127- --help Show this message and exit.128-```129-130-</div>131-132-!!! tip133- Notice that `NAME` is still a *CLI argument*, it's shown up there in the "`Usage: main.py` ...".134-135- Also notice that now `[NAME]` has brackets ("`[`" and "`]`") around (before it was just `NAME`) to denote that it's **optional**, not **required**.136-137-Now run it and test it:138-139-<div class="termy">140-141-```console142-// With no CLI argument143-$ python main.py144-145-Hello World!146-147-// With one optional CLI argument148-$ python main.py Camila149-150-Hello Camila151-```152-153-</div>154-155-!!! tip156- Notice that "`Camila`" here is an optional *CLI argument*, not a *CLI option*, because we didn't use something like "`--name Camila`", we just passed "`Camila`" directly to the program.157-158-## An optional *CLI argument* with a default159-160-We can also make a *CLI argument* have a default value other than `None`:161-162-```Python hl_lines="4"163-{!./src/arguments/tutorial003.py!}164-```165-166-And test it:167-168-<div class="termy">169-170-```console171-// With no optional CLI argument172-$ python main.py173-174-Hello Wade Wilson175-176-// With one CLI argument177-$ python main.py Camila178-179-Hello Camila180-```181-182-</div>183-184-## About *CLI arguments* help185-186-*CLI arguments* are commonly used for the most necessary things in a program.187-188-They are normally required and, when present, they are normally the main subject of whatever the command is doing.189-190-For that reason, Typer (actually Click underneath) doesn't attempt to automatically document *CLI arguments*.191-192-And you should document them as part of the CLI app documentation, normally in a <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>.193-194-Check the last example from the [First Steps](first-steps.md#document-your-cli-app){.internal-link target=_blank}:195-196-```Python hl_lines="5 6 7 8 9"197-{!./src/first_steps/tutorial006.py!}198-```199-200-Here the *CLI argument* `NAME` is documented as part of the help text.201-202-You should document your *CLI arguments* the same way.203-204-## Other uses205-206-`typer.Argument()` has several other use cases. Such as for data validation, to enable other features, etc.207-208-You will see about these use cases later in the docs.modified:docs/tutorial/first-steps.md+27 added-13 removed
73 unmodified lines74 75 $ python main.py76 77 // If you run it without the argument, it shows a nice error78-78 Usage: main.py [OPTIONS] NAME79 Try "main.py --help" for help.80 81 Error: Missing argument 'NAME'.33 unmodified lines115 $ python main.py --help116 117 Usage: main.py [OPTIONS] NAME LASTNAME118 119+Arguments:120+ NAME [required]121+ LASTNAME [required]122+123 Options:124+ --install-completion Install completion for the current shell.125+ --show-completion Show completion for the current shell, to copy it or customize the installation.121- --help Show this message and exit.126+ --help Show this message and exit.127 128 // There are now 2 CLI arguments, name and lastname129 130 // Now pass a single name argument103 unmodified lines234 $ python main.py --help235 236 Usage: main.py [OPTIONS] NAME LASTNAME237 238+Arguments:239+ NAME [required]240+ LASTNAME [required]241+242 Options:234- --formal / --no-formal243+ --formal / --no-formal [default: False]244+ --install-completion Install completion for the current shell.245+ --show-completion Show completion for the current shell, to copy it or customize the installation.246 --help Show this message and exit.247 ```248 249 </div>43 unmodified lines293 $ python main.py --help294 295 Usage: main.py [OPTIONS] NAME296 297+Arguments:298+ NAME [required]299+300 Options:287- --lastname TEXT288- --formal / --no-formal301+ --lastname TEXT [default: ]302+ --formal / --no-formal [default: False]303+ --install-completion Install completion for the current shell.304+ --show-completion Show completion for the current shell, to copy it or customize the installation.305 --help Show this message and exit.306 ```307 308 </div>29 unmodified lines338 ```console339 $ python main.py --lastname Gutiérrez Camila340 341 // and it will still work normally326-342 Hello Camila Gutiérrez343 ```344 345 </div>18 unmodified lines364 Say hi to NAME, optionally with a --lastname.365 366 If --formal is used, say hi very formally.367 368+Arguments:369+ NAME [required]370+371 Options:354- --lastname TEXT355- --formal / --no-formal372+ --lastname TEXT [default: ]373+ --formal / --no-formal [default: False]374 --install-completion Install completion for the current shell.375 --show-completion Show completion for the current shell, to copy it or customize the installation.376 --help Show this message and exit.377 ```378 379 </div>380 381 !!! tip364- You should document the *CLI arguments* in the docstring.382+ There is another place to document the specific *CLI options* and *CLI arguments* that will show up next to them in the help text as with `--install-completion` or `--help`, you will learn that later in the tutorial.383 366- There is another place to document the *CLI options* that will show up next to them in the help text as with `--install-completion` or `--help`, you will learn that later in the tutorial.367-368- But *CLI arguments* are normally used for the most necessary things, so you should document them here in the *docstring*.369-384 ## Arguments, options, parameters, optional, required385 386 Be aware that these terms refer to multiple things depending on the context, and sadly, those "contexts" mix frequently, so it's easy to get confused.387 104 unmodified linesmodified:docs/tutorial/index.md+4 added-2 removed
5 unmodified lines6 7 In short (very short), you can declare a function with parameters like:8 9 ```Python10+from typing import Optional11+10-def type_example(name: str, formal: bool = False, intro: str = None):12+def type_example(name: str, formal: bool = False, intro: Optional[str] = None):13 pass14 ```15 16 And your editor (and **Typer**) will know that:17 18 * `name` is of type `str` and is a required parameter.19 * `formal` is a `bool` and is by default `False`.18-* `intro` is a `str`, and by default is `None`, so it's optional.20+* `intro` is an optional `str`, by default is `None`.21 22 These type hints are what give you autocomplete in your editor and several other features.23 24 **Typer** is based on these type hints.54 unmodified linesmodified:docs/index.md+10 added-1 removed
97 unmodified lines98 $ python main.py --help99 100 Usage: main.py [OPTIONS] NAME101 102+Arguments:103+ NAME [required]104+105 Options:106 --install-completion Install completion for the current shell.107 --show-completion Show completion for the current shell, to copy it or customize the installation.108 --help Show this message and exit.80 unmodified lines189 $ python main.py hello --help190 191 Usage: main.py hello [OPTIONS] NAME192 193+Arguments:194+ NAME [required]195+196 Options:197 --help Show this message and exit.198 199 // And now get the --help for goodbye1 unmodified line201 $ python main.py goodbye --help202 203 Usage: main.py goodbye [OPTIONS] NAME204 205+Arguments:206+ NAME [required]207+208 Options:200- --formal / --no-formal209+ --formal / --no-formal [default: False]210 --help Show this message and exit.211 212 // Automatic --formal and --no-formal for the bool option 🎉213 81 unmodified linesadded:tests/test_tutorial/test_arguments/test_default/__init__.py
added:tests/test_tutorial/test_arguments/test_default/test_tutorial001.py+41 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.default import tutorial001 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] [NAME]" in result.output18+ assert "Arguments:" in result.output19+ assert "[default: Wade Wilson]" in result.output20+21+22+def test_call_no_arg():23+ result = runner.invoke(app)24+ assert result.exit_code == 025+ assert "Hello Wade Wilson" in result.output26+27+28+def test_call_arg():29+ result = runner.invoke(app, ["Camila"])30+ assert result.exit_code == 031+ assert "Hello Camila" in result.output32+33+34+def test_script():35+ result = subprocess.run(36+ ["coverage", "run", mod.__file__, "--help"],37+ stdout=subprocess.PIPE,38+ stderr=subprocess.PIPE,39+ encoding="utf-8",40+ )41+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_default/test_tutorial002.py+43 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.default import tutorial002 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] [NAME]" in result.output18+ assert "Arguments:" in result.output19+ assert "[default: (dynamic)]" in result.output20+21+22+def test_call_no_arg():23+ greetings = ["Hello Deadpool", "Hello Rick", "Hello Morty", "Hello Hiro"]24+ for i in range(3):25+ result = runner.invoke(app)26+ assert result.exit_code == 027+ assert any(greet in result.output for greet in greetings)28+29+30+def test_call_arg():31+ result = runner.invoke(app, ["Camila"])32+ assert result.exit_code == 033+ assert "Hello Camila" in result.output34+35+36+def test_script():37+ result = subprocess.run(38+ ["coverage", "run", mod.__file__, "--help"],39+ stdout=subprocess.PIPE,40+ stderr=subprocess.PIPE,41+ encoding="utf-8",42+ )43+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_envvar/__init__.py
added:tests/test_tutorial/test_arguments/test_envvar/test_tutorial001.py+47 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.envvar import tutorial001 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] [NAME]" in result.output18+ assert "Arguments:" in result.output19+ assert "[env var: AWESOME_NAME;default: World]" in result.output20+21+22+def test_call_arg():23+ result = runner.invoke(app, ["Wednesday"])24+ assert result.exit_code == 025+ assert "Hello Mr. Wednesday" in result.output26+27+28+def test_call_env_var():29+ result = runner.invoke(app, env={"AWESOME_NAME": "Wednesday"})30+ assert result.exit_code == 031+ assert "Hello Mr. Wednesday" in result.output32+33+34+def test_call_env_var_arg():35+ result = runner.invoke(app, ["Czernobog"], env={"AWESOME_NAME": "Wednesday"})36+ assert result.exit_code == 037+ assert "Hello Mr. Czernobog" in result.output38+39+40+def test_script():41+ result = subprocess.run(42+ ["coverage", "run", mod.__file__, "--help"],43+ stdout=subprocess.PIPE,44+ stderr=subprocess.PIPE,45+ encoding="utf-8",46+ )47+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_envvar/test_tutorial002.py+47 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.envvar import tutorial002 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] [NAME]" in result.output18+ assert "Arguments:" in result.output19+ assert "[env var: AWESOME_NAME, GOD_NAME;default: World]" in result.output20+21+22+def test_call_arg():23+ result = runner.invoke(app, ["Wednesday"])24+ assert result.exit_code == 025+ assert "Hello Mr. Wednesday" in result.output26+27+28+def test_call_env_var1():29+ result = runner.invoke(app, env={"AWESOME_NAME": "Wednesday"})30+ assert result.exit_code == 031+ assert "Hello Mr. Wednesday" in result.output32+33+34+def test_call_env_var2():35+ result = runner.invoke(app, env={"GOD_NAME": "Anubis"})36+ assert result.exit_code == 037+ assert "Hello Mr. Anubis" in result.output38+39+40+def test_script():41+ result = subprocess.run(42+ ["coverage", "run", mod.__file__, "--help"],43+ stdout=subprocess.PIPE,44+ stderr=subprocess.PIPE,45+ encoding="utf-8",46+ )47+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_envvar/test_tutorial003.py+48 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.envvar import tutorial003 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] [NAME]" in result.output18+ assert "Arguments:" in result.output19+ assert "[env var: AWESOME_NAME;default: World]" not in result.output20+ assert "[default: World]" in result.output21+22+23+def test_call_arg():24+ result = runner.invoke(app, ["Wednesday"])25+ assert result.exit_code == 026+ assert "Hello Mr. Wednesday" in result.output27+28+29+def test_call_env_var():30+ result = runner.invoke(app, env={"AWESOME_NAME": "Wednesday"})31+ assert result.exit_code == 032+ assert "Hello Mr. Wednesday" in result.output33+34+35+def test_call_env_var_arg():36+ result = runner.invoke(app, ["Czernobog"], env={"AWESOME_NAME": "Wednesday"})37+ assert result.exit_code == 038+ assert "Hello Mr. Czernobog" in result.output39+40+41+def test_script():42+ result = subprocess.run(43+ ["coverage", "run", mod.__file__, "--help"],44+ stdout=subprocess.PIPE,45+ stderr=subprocess.PIPE,46+ encoding="utf-8",47+ )48+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_help/__init__.py
added:tests/test_tutorial/test_arguments/test_help/test_tutorial001.py+37 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.help import tutorial001 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] NAME" in result.output18+ assert "Arguments:" in result.output19+ assert "NAME" in result.output20+ assert "The name of the user to greet" in result.output21+ assert "[required]" in result.output22+23+24+def test_call_arg():25+ result = runner.invoke(app, ["Camila"])26+ assert result.exit_code == 027+ assert "Hello Camila" in result.output28+29+30+def test_script():31+ result = subprocess.run(32+ ["coverage", "run", mod.__file__, "--help"],33+ stdout=subprocess.PIPE,34+ stderr=subprocess.PIPE,35+ encoding="utf-8",36+ )37+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_help/test_tutorial002.py+38 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.help import tutorial002 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] NAME" in result.output18+ assert "Say hi to NAME very gently, like Dirk." in result.output19+ assert "Arguments:" in result.output20+ assert "NAME" in result.output21+ assert "The name of the user to greet" in result.output22+ assert "[required]" in result.output23+24+25+def test_call_arg():26+ result = runner.invoke(app, ["Camila"])27+ assert result.exit_code == 028+ assert "Hello Camila" in result.output29+30+31+def test_script():32+ result = subprocess.run(33+ ["coverage", "run", mod.__file__, "--help"],34+ stdout=subprocess.PIPE,35+ stderr=subprocess.PIPE,36+ encoding="utf-8",37+ )38+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_help/test_tutorial003.py+38 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.help import tutorial003 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] [NAME]" in result.output18+ assert "Say hi to NAME very gently, like Dirk." in result.output19+ assert "Arguments:" in result.output20+ assert "NAME" in result.output21+ assert "Who to greet" in result.output22+ assert "[default: World]" in result.output23+24+25+def test_call_arg():26+ result = runner.invoke(app, ["Camila"])27+ assert result.exit_code == 028+ assert "Hello Camila" in result.output29+30+31+def test_script():32+ result = subprocess.run(33+ ["coverage", "run", mod.__file__, "--help"],34+ stdout=subprocess.PIPE,35+ stderr=subprocess.PIPE,36+ encoding="utf-8",37+ )38+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_help/test_tutorial004.py+38 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.help import tutorial004 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] [NAME]" in result.output18+ assert "Say hi to NAME very gently, like Dirk." in result.output19+ assert "Arguments:" in result.output20+ assert "NAME" in result.output21+ assert "Who to greet" in result.output22+ assert "[default: World]" not in result.output23+24+25+def test_call_arg():26+ result = runner.invoke(app, ["Camila"])27+ assert result.exit_code == 028+ assert "Hello Camila" in result.output29+30+31+def test_script():32+ result = subprocess.run(33+ ["coverage", "run", mod.__file__, "--help"],34+ stdout=subprocess.PIPE,35+ stderr=subprocess.PIPE,36+ encoding="utf-8",37+ )38+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_help/test_tutorial005.py+36 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.help import tutorial005 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] [NAME]" in result.output18+ assert "Arguments:" in result.output19+ assert "Who to greet" in result.output20+ assert "[default: (Deadpoolio the amazing's name)]" in result.output21+22+23+def test_call_arg():24+ result = runner.invoke(app, ["Camila"])25+ assert result.exit_code == 026+ assert "Hello Camila" in result.output27+28+29+def test_script():30+ result = subprocess.run(31+ ["coverage", "run", mod.__file__, "--help"],32+ stdout=subprocess.PIPE,33+ stderr=subprocess.PIPE,34+ encoding="utf-8",35+ )36+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_help/test_tutorial006.py+36 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.help import tutorial006 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] ✨username✨" in result.output18+ assert "Arguments:" in result.output19+ assert "✨username✨" in result.output20+ assert "[default: World]" in result.output21+22+23+def test_call_arg():24+ result = runner.invoke(app, ["Camila"])25+ assert result.exit_code == 026+ assert "Hello Camila" in result.output27+28+29+def test_script():30+ result = subprocess.run(31+ ["coverage", "run", mod.__file__, "--help"],32+ stdout=subprocess.PIPE,33+ stderr=subprocess.PIPE,34+ encoding="utf-8",35+ )36+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_help/test_tutorial007.py+36 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.help import tutorial007 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] [NAME]" in result.output18+ assert "Say hi to NAME very gently, like Dirk." in result.output19+ assert "Arguments:" not in result.output20+ assert "[default: World]" not in result.output21+22+23+def test_call_arg():24+ result = runner.invoke(app, ["Camila"])25+ assert result.exit_code == 026+ assert "Hello Camila" in result.output27+28+29+def test_script():30+ result = subprocess.run(31+ ["coverage", "run", mod.__file__, "--help"],32+ stdout=subprocess.PIPE,33+ stderr=subprocess.PIPE,34+ encoding="utf-8",35+ )36+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_optional/__init__.py
added:tests/test_tutorial/test_arguments/test_optional/test_tutorial001.py+33 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.optional import tutorial001 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_call_no_arg():15+ result = runner.invoke(app)16+ assert result.exit_code != 017+ assert "Error: Missing argument 'NAME'." in result.output18+19+20+def test_call_arg():21+ result = runner.invoke(app, ["Camila"])22+ assert result.exit_code == 023+ assert "Hello Camila" in result.output24+25+26+def test_script():27+ result = subprocess.run(28+ ["coverage", "run", mod.__file__, "--help"],29+ stdout=subprocess.PIPE,30+ stderr=subprocess.PIPE,31+ encoding="utf-8",32+ )33+ assert "Usage" in result.stdoutadded:tests/test_tutorial/test_arguments/test_optional/test_tutorial002.py+39 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from arguments.optional import tutorial002 as mod7+8+runner = CliRunner()9+10+app = typer.Typer()11+app.command()(mod.main)12+13+14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "[OPTIONS] [NAME]" in result.output18+19+20+def test_call_no_arg():21+ result = runner.invoke(app)22+ assert result.exit_code == 023+ assert "Hello World!" in result.output24+25+26+def test_call_arg():27+ result = runner.invoke(app, ["Camila"])28+ assert result.exit_code == 029+ assert "Hello Camila" in result.output30+31+32+def test_script():33+ result = subprocess.run(34+ ["coverage", "run", mod.__file__, "--help"],35+ stdout=subprocess.PIPE,36+ stderr=subprocess.PIPE,37+ encoding="utf-8",38+ )39+ assert "Usage" in result.stdoutdeleted:tests/test_tutorial/test_arguments/test_tutorial001.py-33 removed
1-import subprocess2-3-import typer4-from typer.testing import CliRunner5-6-from arguments import tutorial001 as mod7-8-runner = CliRunner()9-10-app = typer.Typer()11-app.command()(mod.main)12-13-14-def test_call_no_arg():15- result = runner.invoke(app)16- assert result.exit_code != 017- assert "Error: Missing argument 'NAME'." in result.output18-19-20-def test_call_arg():21- result = runner.invoke(app, ["Camila"])22- assert result.exit_code == 023- assert "Hello Camila" in result.output24-25-26-def test_script():27- result = subprocess.run(28- ["coverage", "run", mod.__file__, "--help"],29- stdout=subprocess.PIPE,30- stderr=subprocess.PIPE,31- encoding="utf-8",32- )33- assert "Usage" in result.stdoutdeleted:tests/test_tutorial/test_arguments/test_tutorial002.py-39 removed
1-import subprocess2-3-import typer4-from typer.testing import CliRunner5-6-from arguments import tutorial002 as mod7-8-runner = CliRunner()9-10-app = typer.Typer()11-app.command()(mod.main)12-13-14-def test_help():15- result = runner.invoke(app, ["--help"])16- assert result.exit_code == 017- assert "[OPTIONS] [NAME]" in result.output18-19-20-def test_call_no_arg():21- result = runner.invoke(app)22- assert result.exit_code == 023- assert "Hello World!" in result.output24-25-26-def test_call_arg():27- result = runner.invoke(app, ["Camila"])28- assert result.exit_code == 029- assert "Hello Camila" in result.output30-31-32-def test_script():33- result = subprocess.run(34- ["coverage", "run", mod.__file__, "--help"],35- stdout=subprocess.PIPE,36- stderr=subprocess.PIPE,37- encoding="utf-8",38- )39- assert "Usage" in result.stdoutdeleted:tests/test_tutorial/test_arguments/test_tutorial003.py-39 removed
1-import subprocess2-3-import typer4-from typer.testing import CliRunner5-6-from arguments import tutorial003 as mod7-8-runner = CliRunner()9-10-app = typer.Typer()11-app.command()(mod.main)12-13-14-def test_help():15- result = runner.invoke(app, ["--help"])16- assert result.exit_code == 017- assert "[OPTIONS] [NAME]" in result.output18-19-20-def test_call_no_arg():21- result = runner.invoke(app)22- assert result.exit_code == 023- assert "Hello Wade Wilson" in result.output24-25-26-def test_call_arg():27- result = runner.invoke(app, ["Camila"])28- assert result.exit_code == 029- assert "Hello Camila" in result.output30-31-32-def test_script():33- result = subprocess.run(34- ["coverage", "run", mod.__file__, "--help"],35- stdout=subprocess.PIPE,36- stderr=subprocess.PIPE,37- encoding="utf-8",38- )39- assert "Usage" in result.stdoutmodified:tests/test_tutorial/test_first_steps/test_tutorial004.py+9 added
9 unmodified lines10 app = typer.Typer()11 app.command()(mod.main)12 13 14+def test_help():15+ result = runner.invoke(app, ["--help"])16+ assert result.exit_code == 017+ assert "Arguments:" in result.output18+ assert "NAME [required]" in result.output19+ assert "LASTNAME [required]" in result.output20+ assert "--formal / --no-formal" in result.output21+22+23 def test_1():24 result = runner.invoke(app, ["Camila", "Gutiérrez"])25 assert result.exit_code == 026 assert "Hello Camila Gutiérrez" in result.output28 unmodified linesmodified:tests/test_tutorial/test_first_steps/test_tutorial005.py+2 added
12 unmodified lines13 14 def test_help():15 result = runner.invoke(app, ["--help"])16 assert result.exit_code == 017+ assert "Arguments:" in result.output18+ assert "NAME [required]" in result.output19 assert "--lastname TEXT" in result.output20 assert "--formal / --no-formal" in result.output21 22 32 unmodified linesadded:tests/test_tutorial/test_multiple_values/test_arguments_with_multiple_values/test_tutorial002.py+50 added
1+import subprocess2+3+import typer4+from typer.testing import CliRunner5+6+from multiple_values.arguments_with_multiple_values import tutorial002 as mod7+8+runner = CliRunner()9+app = typer.Typer()10+app.command()(mod.main)11+12+13+def test_help():14+ result = runner.invoke(app, ["--help"])15+ assert result.exit_code == 016+ assert "[OPTIONS] [NAMES]..." in result.output17+ assert "Arguments:" in result.output18+ assert "[default: Harry, Hermione, Ron]" in result.output19+20+21+def test_defaults():22+ result = runner.invoke(app)23+ assert result.exit_code == 024+ assert "Hello Harry" in result.output25+ assert "Hello Hermione" in result.output26+ assert "Hello Ron" in result.output27+28+29+def test_invalid_args():30+ result = runner.invoke(app, ["Draco", "Hagrid"])31+ assert result.exit_code != 032+ assert "Error: argument names takes 3 values" in result.stdout33+34+35+def test_valid_args():36+ result = runner.invoke(app, ["Draco", "Hagrid", "Dobby"])37+ assert result.exit_code == 038+ assert "Hello Draco" in result.stdout39+ assert "Hello Hagrid" in result.stdout40+ assert "Hello Dobby" in result.stdout41+42+43+def test_script():44+ result = subprocess.run(45+ ["coverage", "run", mod.__file__, "--help"],46+ stdout=subprocess.PIPE,47+ stderr=subprocess.PIPE,48+ encoding="utf-8",49+ )50+ assert "Usage" in result.stdoutmodified:tests/test_tutorial/test_options/test_help/test_tutorial002.py+1 added-1 removed
19 unmodified lines20 def test_help():21 result = runner.invoke(app, ["--help"])22 assert result.exit_code == 023 assert "--fullname TEXT" in result.output24- assert "[default: Wade Wilson]" in result.output24+ assert "[default: Wade Wilson]" not in result.output25 26 27 def test_script():28 result = subprocess.run(6 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_datetime/test_tutorial001.py+1 added-1 removed
26 unmodified lines27 def test_invalid():28 result = runner.invoke(app, ["july-19-1989"])29 assert result.exit_code != 030 assert (31- "Error: Invalid value for '[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]': invalid datetime format: july-19-1989. (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)"31+ "Error: Invalid value for 'BIRTH:[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]': invalid datetime format: july-19-1989. (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)"32 in result.output33 )34 35 8 unmodified linesadded:typer/core.py+119 added
1+import inspect2+from typing import Any, Callable, List, Optional, Tuple, Union3+4+import click.core5+6+7+class TyperArgument(click.core.Argument):8+ def __init__(9+ self,10+ *,11+ # Parameter12+ param_decls: List[str],13+ type: Optional[Any] = None,14+ required: Optional[bool] = None,15+ default: Optional[Any] = None,16+ callback: Optional[Callable] = None,17+ nargs: Optional[int] = None,18+ metavar: Optional[str] = None,19+ expose_value: bool = True,20+ is_eager: bool = False,21+ envvar: Optional[Union[str, List[str]]] = None,22+ autocompletion: Optional[Callable] = None,23+ # TyperArgument24+ show_default: Union[bool, str] = True,25+ show_choices: bool = True,26+ show_envvar: bool = True,27+ help: Optional[str] = None,28+ hidden: bool = False,29+ ):30+ self.help = help31+ self.show_default = show_default32+ self.show_choices = show_choices33+ self.show_envvar = show_envvar34+ self.hidden = hidden35+ super().__init__(36+ param_decls=param_decls,37+ type=type,38+ required=required,39+ default=default,40+ callback=callback,41+ nargs=nargs,42+ metavar=metavar,43+ expose_value=expose_value,44+ is_eager=is_eager,45+ envvar=envvar,46+ autocompletion=autocompletion,47+ )48+49+ def get_help_record(self, ctx: click.Context) -> Optional[Tuple[str, str]]: # type: ignore50+ # Modified version of click.core.Option.get_help_record()51+ # to support Arguments52+ if self.hidden:53+ return None54+ name = self.make_metavar()55+ help = self.help or ""56+ extra = []57+ if self.show_envvar:58+ envvar = self.envvar59+ # allow_from_autoenv is currently not supported in Typer for CLI Arguments60+ if envvar is not None:61+ var_str = (62+ ", ".join(str(d) for d in envvar)63+ if isinstance(envvar, (list, tuple))64+ else envvar65+ )66+ extra.append(f"env var: {var_str}")67+ if self.default is not None and (self.show_default or ctx.show_default): # type: ignore68+ if isinstance(self.show_default, str):69+ default_string = f"({self.show_default})"70+ elif isinstance(self.default, (list, tuple)):71+ default_string = ", ".join(str(d) for d in self.default)72+ elif inspect.isfunction(self.default):73+ default_string = "(dynamic)"74+ else:75+ default_string = self.default76+ extra.append(f"default: {default_string}")77+ if self.required:78+ extra.append("required")79+ if extra:80+ extra_str = ";".join(extra)81+ help = f"{help} [{extra_str}]" if help else f"[{extra_str}]"82+ return name, help83+84+ def make_metavar(self) -> str:85+ # Modified version of click.core.Argument.make_metavar()86+ # to include Argument name87+ if self.metavar is not None:88+ return self.metavar89+ var = self.name.upper()90+ if not self.required:91+ var = "[{}]".format(var)92+ type_var = self.type.get_metavar(self)93+ if type_var:94+ var += f":{type_var}"95+ if self.nargs != 1:96+ var += "..."97+ return var98+99+100+class TyperCommand(click.core.Command):101+ def format_options(102+ self, ctx: click.Context, formatter: click.HelpFormatter103+ ) -> None:104+ args = []105+ opts = []106+ for param in self.get_params(ctx):107+ rv = param.get_help_record(ctx)108+ if rv is not None:109+ if param.param_type_name == "argument":110+ args.append(rv)111+ elif param.param_type_name == "option":112+ opts.append(rv)113+114+ if args:115+ with formatter.section("Arguments"):116+ formatter.write_dl(args)117+ if opts:118+ with formatter.section("Options"):119+ formatter.write_dl(opts)modified:typer/main.py+11 added-4 removed
7 unmodified lines8 9 import click10 11 from .completion import get_completion_inspect_parameters12+from .core import TyperArgument, TyperCommand13 from .models import (14 AnyType,15 ArgumentInfo,16 CommandFunctionType,125 unmodified lines142 hidden: bool = False,143 deprecated: bool = False,144 ) -> Callable[[CommandFunctionType], CommandFunctionType]:145 if cls is None:145- cls = click.Command146+ cls = TyperCommand147 148 def decorator(f: CommandFunctionType) -> CommandFunctionType:149 self.registered_commands.append(150 CommandInfo(269 unmodified lines420 params,421 convertors,422 context_param_name,423 ) = get_params_convertors_ctx_param_name_from_function(command_info.callback)423- cls = command_info.cls or click.Command424+ cls = command_info.cls or TyperCommand425 command = cls( # type: ignore426 name=name,427 context_settings=command_info.context_settings,428 callback=get_callback(256 unmodified lines685 return (686 click.Option(687 # Option688 param_decls=param_decls,688- show_default=parameter_info.show_default,689+ show_default=parameter_info.show_default, # type: ignore690 prompt=parameter_info.prompt,691 confirmation_prompt=parameter_info.confirmation_prompt,692 hide_input=parameter_info.hide_input,693 is_flag=is_flag,25 unmodified lines719 nargs = None720 if is_list:721 nargs = -1722 return (722- click.Argument(723+ TyperArgument(724 # Argument725 param_decls=param_decls,726 type=parameter_type,727 required=required,728 nargs=nargs,729+ # TyperArgument730+ show_default=parameter_info.show_default,731+ show_choices=parameter_info.show_choices,732+ show_envvar=parameter_info.show_envvar,733+ help=parameter_info.help,734+ hidden=parameter_info.hidden,735 # Parameter736 default=default_value,737 callback=get_param_callback(738 callback=parameter_info.callback, convertor=convertor117 unmodified linesmodified:typer/models.py+32 added-7 removed
163 unmodified lines164 expose_value: bool = True,165 is_eager: bool = False,166 envvar: Optional[Union[str, List[str]]] = None,167 autocompletion: Optional[Callable] = None,168+ # TyperArgument169+ show_default: Union[bool, str] = True,170+ show_choices: bool = True,171+ show_envvar: bool = True,172+ help: Optional[str] = None,173+ hidden: bool = False,174 # Choice175 case_sensitive: bool = True,176 # Numbers177 min: Optional[Union[int, float]] = None,24 unmodified lines202 self.expose_value = expose_value203 self.is_eager = is_eager204 self.envvar = envvar205 self.autocompletion = autocompletion206+ # TyperArgument207+ self.show_default = show_default208+ self.show_choices = show_choices209+ self.show_envvar = show_envvar210+ self.help = help211+ self.hidden = hidden212 # Choice213 self.case_sensitive = case_sensitive214 # Numbers215 self.min = min31 unmodified lines247 is_eager: bool = False,248 envvar: Optional[Union[str, List[str]]] = None,249 autocompletion: Optional[Callable] = None,250 # Option239- show_default: bool = False,251+ show_default: bool = True,252 prompt: Union[bool, str] = False,253 confirmation_prompt: bool = False,254 hide_input: bool = False,255 is_flag: Optional[bool] = None,2 unmodified lines258 allow_from_autoenv: bool = True,259 help: Optional[str] = None,260 hidden: bool = False,261 show_choices: bool = True,250- show_envvar: bool = False,262+ show_envvar: bool = True,263 # Choice264 case_sensitive: bool = True,265 # Numbers266 min: Optional[Union[int, float]] = None,25 unmodified lines292 expose_value=expose_value,293 is_eager=is_eager,294 envvar=envvar,295 autocompletion=autocompletion,296+ # TyperArgument297+ show_default=show_default,298+ show_choices=show_choices,299+ show_envvar=show_envvar,300+ help=help,301+ hidden=hidden,302 # Choice303 case_sensitive=case_sensitive,304 # Numbers305 min=min,16 unmodified lines322 resolve_path=resolve_path,323 allow_dash=allow_dash,324 path_type=path_type,325 )308- self.show_default = show_default326 self.prompt = prompt327 self.confirmation_prompt = confirmation_prompt328 self.hide_input = hide_input329 self.is_flag = is_flag330 self.flag_value = flag_value331 self.count = count332 self.allow_from_autoenv = allow_from_autoenv316- self.help = help317- self.hidden = hidden318- self.show_choices = show_choices319- self.show_envvar = show_envvar333 334 335 class ArgumentInfo(ParameterInfo):336 def __init__(7 unmodified lines344 expose_value: bool = True,345 is_eager: bool = False,346 envvar: Optional[Union[str, List[str]]] = None,347 autocompletion: Optional[Callable] = None,348+ # TyperArgument349+ show_default: Union[bool, str] = True,350+ show_choices: bool = True,351+ show_envvar: bool = True,352+ help: Optional[str] = None,353+ hidden: bool = False,354 # Choice355 case_sensitive: bool = True,356 # Numbers357 min: Optional[Union[int, float]] = None,25 unmodified lines383 expose_value=expose_value,384 is_eager=is_eager,385 envvar=envvar,386 autocompletion=autocompletion,387+ # TyperArgument388+ show_default=show_default,389+ show_choices=show_choices,390+ show_envvar=show_envvar,391+ help=help,392+ hidden=hidden,393 # Choice394 case_sensitive=case_sensitive,395 # Numbers396 min=min,35 unmodified linesmodified:typer/params.py+14 added-2 removed
12 unmodified lines13 is_eager: bool = False,14 envvar: Optional[Union[str, List[str]]] = None,15 autocompletion: Optional[Callable] = None,16 # Option17- show_default: bool = False,17+ show_default: bool = True,18 prompt: Union[bool, str] = False,19 confirmation_prompt: bool = False,20 hide_input: bool = False,21 is_flag: Optional[bool] = None,2 unmodified lines24 allow_from_autoenv: bool = True,25 help: Optional[str] = None,26 hidden: bool = False,27 show_choices: bool = True,28- show_envvar: bool = False,28+ show_envvar: bool = True,29 # Choice30 case_sensitive: bool = True,31 # Numbers32 min: Optional[Union[int, float]] = None,75 unmodified lines108 expose_value: bool = True,109 is_eager: bool = False,110 envvar: Optional[Union[str, List[str]]] = None,111 autocompletion: Optional[Callable] = None,112+ # TyperArgument113+ show_default: Union[bool, str] = True,114+ show_choices: bool = True,115+ show_envvar: bool = True,116+ help: Optional[str] = None,117+ hidden: bool = False,118 # Choice119 case_sensitive: bool = True,120 # Numbers121 min: Optional[Union[int, float]] = None,28 unmodified lines150 expose_value=expose_value,151 is_eager=is_eager,152 envvar=envvar,153 autocompletion=autocompletion,154+ # TyperArgument155+ show_default=show_default,156+ show_choices=show_choices,157+ show_envvar=show_envvar,158+ help=help,159+ hidden=hidden,160 # Choice161 case_sensitive=case_sensitive,162 # Numbers163 min=min,20 unmodified linesmodified:mkdocs.yml+7 added-1 removed
25 unmodified lines26 - Tutorial - User Guide - Intro: 'tutorial/index.md'27 - First Steps: 'tutorial/first-steps.md'28 - Printing and Colors: 'tutorial/printing.md'29 - Terminating: 'tutorial/terminating.md'30- - CLI Arguments: 'tutorial/arguments.md'30+ - CLI Arguments:31+ - CLI Arguments Intro: 'tutorial/arguments/index.md'32+ - Optional CLI Arguments: 'tutorial/arguments/optional.md'33+ - CLI Arguments with Default: 'tutorial/arguments/default.md'34+ - CLI Arguments with Help: 'tutorial/arguments/help.md'35+ - CLI Arguments with Environment Variables: 'tutorial/arguments/envvar.md'36+ - Other uses: 'tutorial/arguments/other-uses.md'37 - CLI Options:38 - CLI Options Intro: 'tutorial/options/index.md'39 - CLI Options with Help: 'tutorial/options/help.md'40 - Required CLI Options: 'tutorial/options/required.md'89 unmodified linesmodified:README.md+10 added-1 removed
97 unmodified lines98 $ python main.py --help99 100 Usage: main.py [OPTIONS] NAME101 102+Arguments:103+ NAME [required]104+105 Options:106 --install-completion Install completion for the current shell.107 --show-completion Show completion for the current shell, to copy it or customize the installation.108 --help Show this message and exit.80 unmodified lines189 $ python main.py hello --help190 191 Usage: main.py hello [OPTIONS] NAME192 193+Arguments:194+ NAME [required]195+196 Options:197 --help Show this message and exit.198 199 // And now get the --help for goodbye1 unmodified line201 $ python main.py goodbye --help202 203 Usage: main.py goodbye [OPTIONS] NAME204 205+Arguments:206+ NAME [required]207+208 Options:200- --formal / --no-formal209+ --formal / --no-formal [default: False]210 --help Show this message and exit.211 212 // Automatic --formal and --no-formal for the bool option 🎉213 81 unmodified lines