Skip to main content

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

Release files for lupe 0.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lupe 0.1.12
File Size Uploaded
lupe-0.1.12.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lupe 0.1.12
File Interpreter ABI Platform
lupe-0.1.12-py3-none-any.whl Python 3 none any Details

Total release size: 6.5 kB

Release files / lupe-0.1.12.tar.gz

Download URL lupe-0.1.12.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
251d0db692f8a18e5b3cfe1b1f27d9e5c950ebc018c4be17ef62557125bb6a58
BLAKE2b-256 checksum
How to use checksums
cb09b241bb5ad58094f4e2dcec9c60da4625c487334997ddad5f39fca6215657
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / lupe-0.1.12-py3-none-any.whl

Download URL lupe-0.1.12-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a6161bef11a08b9ad76c1856d717bdf46fbb9a3847853b483500f83996c4efd
BLAKE2b-256 checksum
How to use checksums
125a47a90fa59eeefe65ff6ed1b88af0f0954041523aed470eff0863212769b6
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.12 This release

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page