argrun

a small library that wraps argparse to map arguments to decorated functions


Keywords
argparse, arguments, cli
License
MIT
Install
pip install argrun==0.2.2

Documentation

argrun

a library that wraps argparse, mapping arguments to decorated functions

functions are only called if the associated command line argument is present/non-empty

Installation:

$ pip install argrun

Usage:

from functools import reduce
import argrun 

runner = argrun.ArgumentRunner()

@runner.parse('-m', '--multiply', help='multiplies numbers', nargs='*')
def multiply(args):
    print(reduce(lambda x,y: x * y, map(int, args)))

if __name__ == '__main__':
    runner.run()

Documentation:

See also argparse

argrun.argrun

ArgumentRunner

ArgumentRunner(self)

ArgumentRunner offers a decorator, parses arguments, and allows decorated functions to be ran

parse_args

ArgumentRunner.parse_args(*args, **kwargs)

Parses arguments and returns the result as a dictionary

parse

ArgumentRunner.parse(*args, **kwargs)

a decorator that defines the arguments to be parsed and associates it with the decorated method

run

ArgumentRunner.run(*args, **kwargs)

Runs all decorated functions

add_argument

ArgumentRunner.add_argument(*args, **kwargs)

adds an argument to be parsed without being run