Skip to main content

A lightweight verbose argument parser

Project description

Amersham

Test Coverage

Amersham: The name of a London Underground station which alliterates with "argument parser"

Motivation

Every CLI application wants two things:

  1. Sanitized user input
  2. Descriptive usage and help messages

Amersham implements both with minimal boilerplate.

Quick Start

Install

pip3 install amersham

Import

import sys

from amersham import Parser

Create a parser and command

parser = Parser("app")

@parser.command()
def command(parameter, flag = None):
    pass

Run the parser

if __name__ == "__main__":
    parser.run(sys.argv[1:])

Run your program

user:~$ python3 app.py --help
usage
  app.py [--help] [--flag] PARAMETER

flags
  --help  -h  displays this message
  --flag

parameters
  PARAMETER  string

Advanced Usage

More Descriptive Help Messages

Add some context to our command and arguments

overrides = {
    "description": "a command",

    "parameter": {
        "description": "a parameter",
    },
    "flag": {
        "description": "a flag",
        "alias": "f",
    }
}

@parser.command(**overrides)
def command(parameter, flag = ""):
    pass

And see the results

user:~$ python3 app.py --help
usage
  app.py [--help] [--flag] PARAMETER

description
  a command

flags
  --help  -h          displays this message
  --flag      string  a flag

parameters
  PARAMETER  string  a parameter

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

amersham-1.0.1.tar.gz (8.4 kB view hashes)

Uploaded Source

Built Distribution

amersham-1.0.1-py3-none-any.whl (9.8 kB view hashes)

Uploaded Python 3

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