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. Vetted user input
  2. Descriptive usage and help messages

Amersham takes care of both with minimal boilerplate.

Installation

user:app$ git clone git@github.com:inigo-selwood/amersham.git

Quick Start

Import

import sys

from amersham import Parser, Flag, Parameter

Create a parser

parser = Parser("parser", "a parser")

Create a command

@parser.command("a command",
        flag = Flag("a flag"),
        parameter = Parameter("a parameter))
def command(parameter: str, flag: str):
    print(parameter, flag)

Why the duplication? The same could be acheived with type annotations

Take away the decorator, and it's just a normal function. The signature stays descriptive; changing parser is painless.


Run the parser

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

Help

Amersham generates descriptive help messages, so you don't have to.

For the application:

user:app$ python3 app --help
usage
  app [--help] {command} ...

description
  a parser

commands
  command  a command

And for each command:

user:app$ python3 app command --help
usage
  app command [--help] {command} ...

description
  a command

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

parameters
  parameter  a parameter

Overriding Defaults

Amersham infers the names of your commands, arguments, and flag aliases. You can override that behaviour should you want to.

Rename a command:

@parser.command("a command", name="a-different-name")
def command():
    pass

Or a flag/parameter:

@parser.command("a command",
        flag = Flag("a flag", name="flag-name"),
        parameter = Parameter("a parameter, name="parameter-name"))
def command(parameter: str, flag: str):
    print(parameter, flag)

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-0.0.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

amersham-0.0.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file amersham-0.0.1.tar.gz.

File metadata

  • Download URL: amersham-0.0.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for amersham-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1de6f2019cceb0e86268e051af9d8df876d804c015b97c2ee93d2d3a28f8695b
MD5 2cbefb397984381e34414e1cd593304a
BLAKE2b-256 53f39b5b488471fd14c340684438d6a3f23fba945649eaa53762ba18aa86430e

See more details on using hashes here.

File details

Details for the file amersham-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: amersham-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for amersham-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 739732ede3e23ea9d762bf876fe010f838f2dc9baa22a1ba9150b338d08879cf
MD5 c479caa31e06437993330f129bad440f
BLAKE2b-256 950448838caac433df04427be13030ab1d34c0701045b1914c7786da0b46f989

See more details on using hashes here.

Supported by

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