argparse-decorations


Nameargparse-decorations JSON
Version 0.0.9 PyPI version JSON
download
home_pagehttps://bitbucket.org/rmonico/argparse_decorations
Summaryargparse wrapper around decorations
upload_time2025-01-14 15:56:19
maintainerNone
docs_urlNone
authorRafael Monico
requires_pythonNone
licenseGPL3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # argparse\_decoration

A argparse wrapper through decorations

## 30 sec tutorial

Given `test.py` with:

```
#!/bin/python3

from argparse_decorations import init, Command, parse_and_run

init()

@Command('mycommand')
def handler():
    print('Hello!')

parse_and_run()

```

then `./test.py` produces:

```
usage: test.py [-h] {mycommand} ...

Help message

positional arguments:
  {mycommand}

options:
  -h, --help   show this help message and exit
```


and `./test.py mycommand`:

```
Hello!
```


## 1 min tutorial

The program:

```
from argparse_decorations import init, Command, SubCommand, Argument, parse_and_run

init()

@Command('mycommand')
@SubCommand('add')
@Argument('a', type=int)
@Argument('b', type=int)
def add_handler_but_could_be_any_identifier(a, b):
    print(a + b)

parse_and_run()
```

when called `./test.py mycommand add 1 2` produces:

`3`


`@Command` and `@SubCommand` will make a call to `ArgumentParser.add_parser()` and `@Argument` will call `ArgumentParser.add_argument`
These calls are made 'as-is' passing every `*args` and `**kwargs` passed on decorations to commands


A complete example whose explore all possibilities:

```python
@Command('math')
@SubCommand('add')
@Argument('valueA', type=int)
@Argument('valueB', type=int)
def add_handler(valueA, valueB):
    print('Adding args ' + str(valueA) + ' and ' + str(valueB))
    print(valueA + valueB)


@Command('math')
@SubCommand('sub')
@Argument('valueA', type=int)
@Argument('valueB', type=int)
def subtract_handler(valueA, valueB):
    print('Subtracting args ' + str(valueA) + ' and ' + str(valueB))
    print(valueA - valueB)


@Command('math')
@SubCommand('mul')
@Argument('valueA', type=int)
@Argument('valueB', type=int)
def subtract_handler(valueA, valueB):
    print('Multiplying args ' + str(valueA) + ' and ' + str(valueB))
    print(valueA * valueB)


@Command('math')
@SubCommand('pi')
def pi():
    print('3.1415926535979')
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://bitbucket.org/rmonico/argparse_decorations",
    "name": "argparse-decorations",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Rafael Monico",
    "author_email": "rmonico1@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f7/18/b1f8b7d802aa5623abb774c48b0c705854b908e7b25ba7541ce34c179b6d/argparse_decorations-0.0.9.tar.gz",
    "platform": null,
    "description": "# argparse\\_decoration\n\nA argparse wrapper through decorations\n\n## 30 sec tutorial\n\nGiven `test.py` with:\n\n```\n#!/bin/python3\n\nfrom argparse_decorations import init, Command, parse_and_run\n\ninit()\n\n@Command('mycommand')\ndef handler():\n    print('Hello!')\n\nparse_and_run()\n\n```\n\nthen `./test.py` produces:\n\n```\nusage: test.py [-h] {mycommand} ...\n\nHelp message\n\npositional arguments:\n  {mycommand}\n\noptions:\n  -h, --help   show this help message and exit\n```\n\n\nand `./test.py mycommand`:\n\n```\nHello!\n```\n\n\n## 1 min tutorial\n\nThe program:\n\n```\nfrom argparse_decorations import init, Command, SubCommand, Argument, parse_and_run\n\ninit()\n\n@Command('mycommand')\n@SubCommand('add')\n@Argument('a', type=int)\n@Argument('b', type=int)\ndef add_handler_but_could_be_any_identifier(a, b):\n    print(a + b)\n\nparse_and_run()\n```\n\nwhen called `./test.py mycommand add 1 2` produces:\n\n`3`\n\n\n`@Command` and `@SubCommand` will make a call to `ArgumentParser.add_parser()` and `@Argument` will call `ArgumentParser.add_argument`\nThese calls are made 'as-is' passing every `*args` and `**kwargs` passed on decorations to commands\n\n\nA complete example whose explore all possibilities:\n\n```python\n@Command('math')\n@SubCommand('add')\n@Argument('valueA', type=int)\n@Argument('valueB', type=int)\ndef add_handler(valueA, valueB):\n    print('Adding args ' + str(valueA) + ' and ' + str(valueB))\n    print(valueA + valueB)\n\n\n@Command('math')\n@SubCommand('sub')\n@Argument('valueA', type=int)\n@Argument('valueB', type=int)\ndef subtract_handler(valueA, valueB):\n    print('Subtracting args ' + str(valueA) + ' and ' + str(valueB))\n    print(valueA - valueB)\n\n\n@Command('math')\n@SubCommand('mul')\n@Argument('valueA', type=int)\n@Argument('valueB', type=int)\ndef subtract_handler(valueA, valueB):\n    print('Multiplying args ' + str(valueA) + ' and ' + str(valueB))\n    print(valueA * valueB)\n\n\n@Command('math')\n@SubCommand('pi')\ndef pi():\n    print('3.1415926535979')\n```\n\n\n",
    "bugtrack_url": null,
    "license": "GPL3",
    "summary": "argparse wrapper around decorations",
    "version": "0.0.9",
    "project_urls": {
        "Homepage": "https://bitbucket.org/rmonico/argparse_decorations"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f718b1f8b7d802aa5623abb774c48b0c705854b908e7b25ba7541ce34c179b6d",
                "md5": "4772349297bfe66cce8fa8a5d52c7c9f",
                "sha256": "241134975f672c96e1428c0804e7fbc08e7ed6a86431e23870c1ac5d599ebd7a"
            },
            "downloads": -1,
            "filename": "argparse_decorations-0.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "4772349297bfe66cce8fa8a5d52c7c9f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4635,
            "upload_time": "2025-01-14T15:56:19",
            "upload_time_iso_8601": "2025-01-14T15:56:19.657614Z",
            "url": "https://files.pythonhosted.org/packages/f7/18/b1f8b7d802aa5623abb774c48b0c705854b908e7b25ba7541ce34c179b6d/argparse_decorations-0.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-14 15:56:19",
    "github": false,
    "gitlab": false,
    "bitbucket": true,
    "codeberg": false,
    "bitbucket_user": "rmonico",
    "bitbucket_project": "argparse_decorations",
    "lcname": "argparse-decorations"
}
        
Elapsed time: 1.62010s