Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abranhe/lupe
The CLI helper you need ðŸ¥
https://github.com/abranhe/lupe
cli command-line pip python
Last synced: 17 days ago
JSON representation
The CLI helper you need ðŸ¥
- Host: GitHub
- URL: https://github.com/abranhe/lupe
- Owner: abranhe
- License: mit
- Created: 2018-07-12T01:47:28.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-09-20T14:40:42.000Z (about 3 years ago)
- Last Synced: 2024-10-12T12:14:56.759Z (about 1 month ago)
- Topics: cli, command-line, pip, python
- Language: Python
- Homepage: https://p.abranhe.com/lupe
- Size: 28.3 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
Awesome Lists containing this project
README
# WIP
> Currently in development.
Save time building command-line apps with LUPE## Install
```console
$ 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:
```console
$ python main.py dinner --mango --no-banana
```On the app:
```python
#!/usr/bin/python
import lupehelp = """
Usage foo [input]Options
-h, --help Show this help message and exit
-v, --version Show version and exit
-m, --mango Include a mangoExamples
$ main.py dinner --mango --no-banana
"""cli = lupe(help, {
'flags': {
'mango': {
'type': 'boolean',
'alias': 'm'
},
'banana': {
'type': 'boolean',
}
}
})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:
```python
flags = {
'unicorn': {
'type': 'string',
'alias': 'u',
'default': ['rainbow', 'cat'],
'required': True,
}
}
```## Credit
Based on [meow](https://github.com/sindresorhus/meow) from [@sindresorhus](https://github.com/sindresorhus)
## License
MIT © [Abraham Hernandez](https://github.com/abranhe)