Last updated:
0 purchases
lupe 0.1.12
WIP
Currently in development.
Save time building command-line apps with LUPE
Install
$ pip install lupe
Features
Parses arguments
Converts flags snake_case for easier use
Negates flags when using the --no- prefix
Outputs version when -v, --version
Outputs description and supplied help text when -h, --help
Usage
On the command line:
$ python main.py dinner --mango --no-banana
On the app:
#!/usr/bin/python
import lupe
help = """
Usage foo [input]
Options
-h, --help Show this help message and exit
-v, --version Show version and exit
-m, --mangeo Include a mango
Examples
$ main.py dinner --mango --no-banana
"""
cli = lupe(help, {
'flags': {
'mango': {
'type': 'boolen',
'alias': 'm'
},
'banana': {
'type': 'boolen',
}
}
})
print(cli.flags)
# {'mango': True, 'banana': False}
print(cli.inputs)
# [dinner]
API
lupe(help_message, options?)
lupe(options)
Returns an object with:
inputs (Array) - Non-flag arguments
flags (Object) - Flags converted to snake_case excluding aliases
help (string) - The help text used with --help
show_help([exit_code=2]) (Function) - Show the help text and exit with exit_code
show_version() (Function) - Show the version text and exit
help_message
Type: string
options
Type: object
Shortcut for the help option.
version
Type: string
Version of the command-line application.
flags
Type: object
Define argument flags.
The key is the flag name in snake_case and the value is an object with any of:
type: Type of value. (Possible values: string boolean number)
alias: Usually used to define a short flag alias.
default: Default value when the flag is not specified.
required: Determine if the flag is required. (Default: false)
Note that flags are always defined using a snake_case key (my_key), but will match arguments in kebab-case (--my-key).
Example:
flags = {
'unicorn': {
'type': 'string',
'alias': 'u',
'default': ['rainbow', 'cat'],
'required': True,
}
}
Credit
Based on meow from @sindresorhus
License
MIT © Abraham Hernandez
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.