Commit 46ca9625 authored by vermeul's avatar vermeul
Browse files

added click examples

parent 3bf80a62
# Command_Line_Processing
\ No newline at end of file
# Command Line Processing
* for many utility programs the command line is the primary interface
* so make it flexible
* and convenient
* and mnemonic
* and predictable
* standardize on a uniform command-line structure and use it consistently
## Meta-options
**Standardize your meta-options**
* `--usage` print a concise usage line
* `--help` print the `--usage` line, followed by a one-line summary of each option
* `--version` print the program's version number
* `--man` print complete documentation
Use the shorter names (e.g. `-u`, `-h`, `-v`, `-m`) not for meta-options (since they are not used very frequently) for your other options that your program needs.
## consider using the click module
**do not try to implement your own argument-parsing module**
The built-in `argparse` module is ok for basic arguments, but as your command-line tool grows and gets more complex, you might to switch to the great click module. It uses decorators as wrappers around the function that is exposed to the command line. These allow quite sophisticated **automatic type-checking of the input values** as well as **interactive shell**. This means, your actual function is freed from «infrastructure code», i.e. code that that only checks for correct input but otherwise does not contribute to the function.
import click
'-y', '--year',
type=click.IntRange(2014, 2050),
def my_function(year, out_folder, password):
if __name__ == '__main__':
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment