argtools


Nameargtools JSON
Version 0.1.6 PyPI version JSON
download
home_pagehttps://github.com/m1m0r1/argtools.py
SummaryA collection of decorators to build command-line tools with minimal effort
upload_time2021-02-22 03:32:43
maintainer
docs_urlNone
authorTakahiro Mimori
requires_python
license
keywords argparse subcommand command cli
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Argtools
==========

Description
-------------------
A collection of decorators wrapping argparse module for building command-line tools with *minimal effort*.

Quick start
-------------------

### Installation
```sh
$ pip install argtools
```

### Building a simple command-line tool

```python
# examples/test.py
from argtools import command, argument

@command
@argument('foo', help='a positional arugment')
@argument('--bar', default=3, help='an optional argument')
def main(args):
    """ One line description here

    Write details here (printed with --help|-h)
    """
    print args.bar
    print args.foo
    return 1  # return code


if __name__ == '__main__':
    command.run()
```

```sh
$ python test.py
$ python test.py -v   # Increasing the verbosity of logging module
```

The `argument` decorator has the same api as argparse.ArgumentParser.add_argument.
See http://docs.python.org/dev/library/argparse.html for details.


### Building subcommands

```python
# examples/subtest.py
from argtools import command, argument

@command.add_sub
def foo(args):
    """ This is foo
    """
    print 'foo'


@command.add_sub
def bar(args):
    """ This is bar
    """
    print 'bar'


@command.add_sub(name=baz)  # set different name
def bar(args):
    """ This is baz
    """
    print 'baz'

if __name__ == '__main__':
    command.run()
```

```sh
$ python test.py foo      # print foo
$ python test.py bar      # print bar
$ python test.py bar -h   # print help text of bar subcommand
```


Other features
-------------------

- In `command.run()`, the logging module is setup. You can control the verbosity with options: -v, -vv, ..
- In `command.run()`, SIGPIPE occured inside of wrapped function will be ignored to ease piping.
- To use `group` or `exclusive` functionality of argparse, give `argument` objects (e.g. arg1, arg2, arg3) as `@argument.group(arg1, arg2, arg3)` or `@argument.exclusive(arg1, arg2, arg3)`, respectively (documentation is #TODO).
- Builtin options: -v, --verbose and --debug can be turned off by setting `command.add_verbose = False` or `command.add_debug = False`
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/m1m0r1/argtools.py",
    "name": "argtools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "argparse subcommand command cli",
    "author": "Takahiro Mimori",
    "author_email": "takahiro.mimori@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cc/6e/697dcd8daaa1c47fd4c72419112664c6b7c10af069340390b5932a97ebdc/argtools-0.1.6.tar.gz",
    "platform": "",
    "description": "Argtools\n==========\n\nDescription\n-------------------\nA collection of decorators wrapping argparse module for building command-line tools with *minimal effort*.\n\nQuick start\n-------------------\n\n### Installation\n```sh\n$ pip install argtools\n```\n\n### Building a simple command-line tool\n\n```python\n# examples/test.py\nfrom argtools import command, argument\n\n@command\n@argument('foo', help='a positional arugment')\n@argument('--bar', default=3, help='an optional argument')\ndef main(args):\n    \"\"\" One line description here\n\n    Write details here (printed with --help|-h)\n    \"\"\"\n    print args.bar\n    print args.foo\n    return 1  # return code\n\n\nif __name__ == '__main__':\n    command.run()\n```\n\n```sh\n$ python test.py\n$ python test.py -v   # Increasing the verbosity of logging module\n```\n\nThe `argument` decorator has the same api as argparse.ArgumentParser.add_argument.\nSee http://docs.python.org/dev/library/argparse.html for details.\n\n\n### Building subcommands\n\n```python\n# examples/subtest.py\nfrom argtools import command, argument\n\n@command.add_sub\ndef foo(args):\n    \"\"\" This is foo\n    \"\"\"\n    print 'foo'\n\n\n@command.add_sub\ndef bar(args):\n    \"\"\" This is bar\n    \"\"\"\n    print 'bar'\n\n\n@command.add_sub(name=baz)  # set different name\ndef bar(args):\n    \"\"\" This is baz\n    \"\"\"\n    print 'baz'\n\nif __name__ == '__main__':\n    command.run()\n```\n\n```sh\n$ python test.py foo      # print foo\n$ python test.py bar      # print bar\n$ python test.py bar -h   # print help text of bar subcommand\n```\n\n\nOther features\n-------------------\n\n- In `command.run()`, the logging module is setup. You can control the verbosity with options: -v, -vv, ..\n- In `command.run()`, SIGPIPE occured inside of wrapped function will be ignored to ease piping.\n- To use `group` or `exclusive` functionality of argparse, give `argument` objects (e.g. arg1, arg2, arg3) as `@argument.group(arg1, arg2, arg3)` or `@argument.exclusive(arg1, arg2, arg3)`, respectively (documentation is #TODO).\n- Builtin options: -v, --verbose and --debug can be turned off by setting `command.add_verbose = False` or `command.add_debug = False`",
    "bugtrack_url": null,
    "license": "",
    "summary": "A collection of decorators to build command-line tools with minimal effort",
    "version": "0.1.6",
    "split_keywords": [
        "argparse",
        "subcommand",
        "command",
        "cli"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "6a8817e3c4ab96d4d2ccef353dfdd7b4",
                "sha256": "0d5f9be15a81822fe53b05a8e73983267929c55fb65751506c97425b0557bbec"
            },
            "downloads": -1,
            "filename": "argtools-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "6a8817e3c4ab96d4d2ccef353dfdd7b4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4753,
            "upload_time": "2021-02-22T03:32:43",
            "upload_time_iso_8601": "2021-02-22T03:32:43.964290Z",
            "url": "https://files.pythonhosted.org/packages/cc/6e/697dcd8daaa1c47fd4c72419112664c6b7c10af069340390b5932a97ebdc/argtools-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-02-22 03:32:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "m1m0r1",
    "error": "Could not fetch GitHub repository",
    "lcname": "argtools"
}
        
Elapsed time: 0.17323s