diff options
| author | alex <alex@pdp7.net> | 2022-04-22 20:55:11 +0200 |
|---|---|---|
| committer | alex <alex@pdp7.net> | 2022-04-22 20:55:11 +0200 |
| commit | b5c185e0f95e4e5c680e2992af9f7f00574a1cbb (patch) | |
| tree | c73349dbae047763a6ce7d9a267d3a149ba0ea5d /programming | |
| parent | 07da00665affbebd903236d7f4656e1745dad6c7 (diff) | |
Add more hints about argparse
Diffstat (limited to 'programming')
| -rw-r--r-- | programming/python/creating_nice_python_cli_tools.md | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/programming/python/creating_nice_python_cli_tools.md b/programming/python/creating_nice_python_cli_tools.md index 50939ee3..6986416b 100644 --- a/programming/python/creating_nice_python_cli_tools.md +++ b/programming/python/creating_nice_python_cli_tools.md @@ -25,6 +25,8 @@ You can also use logging module to implement flags such as `--debug` and `--verbose`. * Although you can use other fancier tools for parsing command-line arguments, the standard [argparse](https://docs.python.org/3/library/argparse.html) module is good enough for most tools. It has decent support for [sub-commands](https://docs.python.org/3/library/argparse.html#sub-commands), and the linked document describes a very nice pattern to define functions for sub-commands, under "One particularly effective way of handling sub-commands..." + Try to provide help texts for parameters that may not be obvious. + argparse supports a lot of different argument types, such as enumerated options, integers, file names, and others, that provide a lot of functionality out of the box. * Remember that the standard [json](https://docs.python.org/3/library/json.html) module is built-in. You can use it to add a mode to your tool that generates JSON output instead of human-readable output, for easy automation of your tool, maybe using [jq](https://stedolan.github.io/jq/) or [fx](https://github.com/antonmedv/fx). * Use the standard [subprocess](https://docs.python.org/3/library/subprocess.html) module to execute other commands. |
