argent

Parse command-line arguments using introspective magic.


Keywords
command-line, arguments, flags, argparse
License
Other
Install
pip install argent==0.01.1

Documentation

Argent.

Argent is a new argument parser for command-line programs in Python. It turns out Python already has objects that can take arbitrary arguments, supply defaults, and do things with them: they're called functions. For help messages, Argent uses some introspective magic on these functions and then analyzes your docstrings for more information. And you already detail your arguments meticulously in your docstrings, right?

Features

  • Easy syntax; no cascades of text, as in argparse. Use the Python function syntax you already know and love, with decorators for specifying parsers and subparsers.
  • Cleverness founded in introspective magic; on the other hand, it's only a little more magic than docutils, for example. There's no black magic metaclass hacking here.
  • So long as you format your docstrings how Argent expects you too, you'll get beautiful detailed help messages.

Examples

This is about the simplest you can do:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from argent import Parser

@Parser.from_function
def simplest():
    "Prints hello when you call it."
    print "hello!"

simplest.command_line()

This program's help message (run python simplest.py --help) is:

usage: simplest.py [--h] 

Prints hello when you call it.

optional flags:
   --h, --help   Display this help message and exit.

Here's a more featureful example, and there are more over at this other page.

Todo:

  • Flags that can take arguments -- like --flag argument.
  • Type checking; for now you have to assume everything will come in as strings.
  • Colorized help output?
  • Clean up the codebase, as always.
  • More documentation.