Skip to main content

The CLI helper you need 🥭

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lupe-0.1.9.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

lupe-0.1.9-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

Details for the file lupe-0.1.9.tar.gz.

File metadata

  • Download URL: lupe-0.1.9.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for lupe-0.1.9.tar.gz
Algorithm Hash digest
SHA256 f152173bde48fe76fdf2464e4c3b46edc45eec8b08ff275f9497525124cbd620
MD5 504f1701b70397f75a8311942a2328e7
BLAKE2b-256 84121c0feeb22799d8835e25c629dea4c45abef0f62ce480255d65f97ab4b258

See more details on using hashes here.

File details

Details for the file lupe-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: lupe-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 2.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for lupe-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 381857f8e0dc25291e3c7a5baa8ee48daed4065550d7fb2ace53691d1b9e3493
MD5 119f3b708b1a456c9b8c221ae7ea494b
BLAKE2b-256 f1b1cb2160dcf9cc99161111f3c0e40168b9d827d443db5aa73fe034650717eb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page