88from subprocess import list2cmdline as l2c
99
1010from rich .markdown import Markdown
11- from rich_argparse import RawDescriptionRichHelpFormatter
11+ from rich_argparse import RawTextRichHelpFormatter
1212
1313default_args = {
1414 "ruff-check" : ["tests" , "stubs" ],
2727
2828Command | Default invocation |
2929------- | ------------------ |
30- { _newl .join (f"` { tool } ` | ` { l2c ((* tool .split ('-' ), * default ))} ` " for tool , default in default_args .items ())}
30+ { _newl .join (f"{ tool } | { l2c ((* tool .split ('-' ), * default ))} " for tool , default in default_args .items ())}
3131
32- You can override the default invocation by passing extra args after the command:
33-
34- E.g: `python run.py mypy tests` invokes `mypy tests` instead.
35-
36- Run `python -m pip install -r requirements-tests.txt` to install dependencies.
32+ You can override the default invocation by passing extra args after the command.
3733"""
3834
3935
4036def main () -> int :
4137 parser = argparse .ArgumentParser (
4238 description = Markdown (description ), # pyright: ignore[reportArgumentType]
43- formatter_class = RawDescriptionRichHelpFormatter ,
39+ epilog = "Run [argparse.args]python -m pip install -r requirements.txt[/] to install project dependencies." ,
40+ formatter_class = RawTextRichHelpFormatter ,
4441 add_help = False ,
4542 )
4643 parser .add_argument (
4744 "tool" ,
4845 nargs = "?" ,
4946 metavar = "command" ,
5047 choices = default_args ,
51- help = "A command from (%(choices)s) to run, optionally with args. See the table above for more information." ,
48+ help = "A command from (%(choices)s)\n to run, optionally with args.\n \n See the table above for more information.\n \n " ,
5249 )
5350 parser .add_argument (
5451 "-h" ,
5552 "--help" ,
5653 action = "store_true" ,
57- help = "Show this help message and exit. Use ` --help CMD` to print the help of a command ` CMD`. " ,
54+ help = "Show this help message and exit.\n Use --help [i] CMD[/] to print the help of command [i] CMD[/]. \n \n " ,
5855 )
59- parser .add_argument ("--all" , action = "store_true" , help = "Run all the commands in the table above." )
56+ parser .add_argument ("--all" , action = "store_true" , help = "Run all commands in the table above." )
6057
6158 args , rest = parser .parse_known_args ()
62-
6359 tool : str | None = args .tool
6460
6561 if args .help :
66- help_text = parser .format_help ()
67- help_text = help_text [0 ].upper () + help_text [1 :]
68- print (help_text , end = "" , file = sys .stderr )
62+ parser .print_help (file = sys .stderr )
6963 if tool :
7064 print ("\n " + "━" * 80 + "\n " , file = sys .stderr )
7165 return subprocess .call ([* tool .split ("-" ), "--help" ])
@@ -76,7 +70,14 @@ def main() -> int:
7670 elif tool :
7771 tools = [tool ]
7872 else :
79- parser .error (f"missing command from ({ ', ' .join (default_args )} ) or `--all`" )
73+ parser .print_usage (file = sys .stderr )
74+ formatter = parser .formatter_class (prog = parser .prog )
75+ formatter .add_text (
76+ f"\n [argparse.prog]{ parser .prog } [/]: [red]error:[/] missing command from "
77+ f"({ ', ' .join (f'[argparse.args]{ a } [/]' for a in default_args )} ) "
78+ f"or [argparse.args]--all[/]"
79+ )
80+ parser .exit (2 , formatter .format_help ())
8081
8182 ret = 0
8283 for tool in tools :
0 commit comments