polidoro-argument


Namepolidoro-argument JSON
Version 3.1.3 PyPI version JSON
download
home_pagehttps://github.com/heitorpolidoro/polidoro-argument
SummaryPackage to create command line arguments for Python.
upload_time2021-05-07 15:05:34
maintainer
docs_urlNone
authorHeitor Polidoro
requires_python
licenseunlicense
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Polidoro Argument [![Latest](https://img.shields.io/github/release/heitorpolidoro/argument.svg?label=latest)](https://github.com/heitorpolidoro/argument/releases/latest)
Package to simplify creating command line arguments for scripts in Python.

#### How to use:

- Decorate the method you want to create an argument from with `@Argument`.
- Decorate the method you want to call from command line with `@Command`.
- Create a `PolidoroArgumentParser` 
- Call `parser.parse_args()`

All keywords arguments to `@Argument` and `@Command` are the same as in [argparse.ArgumentParser.add_argument](https://docs.python.org/3.7/library/argparse.html#the-add-argument-method) except for 'action' and 'nargs'.
'action' is a custom Action created to run the decorated method and 'nargs' is the number of parameters in the decorated method.

###### Examples:
foo.py
```

from polidoro_argument import Argument, PolidoroArgumentParser

@Argument
def bar():
    print('hi')

parser = ArgumentParser()
parser.parse_args()
```
Result:
```
$ python foo.py --bar
hi 
```

You can pass argument to the method
```
@Argument
def bar(baz=None):
    print(baz)
```
```
$ python foo.py --bar Hello
Hello
```
To create commands
```
@Command
def command():
    print('this is a command')
```
```
$ python foo.py command
this is a command
```
With arguments
```
@Command
def command_with_arg(arg, arg1=None):
    print('this the command arg: %s, arg1: %s' % (arg, arg1))
```
```
$ python foo.py command_with_arg Hello
this the command arg: Hello, arg1: None
$ python foo.py command_with_arg Hello --arg1 World
this the command arg: Hello, arg1: World
```
Using a Class
```
class ClassCommand:
    @staticmethod
    @Argument
    def argument_in_class():
        print('argument_in_class called')

    @staticmethod
    @Command
    def command_in_class(arg='Oi'):
        print('command_in_class called. arg=%s' % arg)
```
```
$ python foo.py classcommand --argument_in_class
argument_in_class called
$ python foo.py classcommand command_in_class
command_in_class called. arg=Oi
$ python foo.py classcommand command_in_class --arg=Ola
command_in_class called. arg=Ola
```






            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/heitorpolidoro/polidoro-argument",
    "name": "polidoro-argument",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Heitor Polidoro",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/bf/66/d6d1de6a4665e3df06fdcfa8787f5211055721fcedeb4b7984baecd17c6c/polidoro-argument-3.1.3.tar.gz",
    "platform": "",
    "description": "# Polidoro Argument [![Latest](https://img.shields.io/github/release/heitorpolidoro/argument.svg?label=latest)](https://github.com/heitorpolidoro/argument/releases/latest)\nPackage to simplify creating command line arguments for scripts in Python.\n\n#### How to use:\n\n- Decorate the method you want to create an argument from with `@Argument`.\n- Decorate the method you want to call from command line with `@Command`.\n- Create a `PolidoroArgumentParser` \n- Call `parser.parse_args()`\n\nAll keywords arguments to `@Argument` and `@Command` are the same as in [argparse.ArgumentParser.add_argument](https://docs.python.org/3.7/library/argparse.html#the-add-argument-method) except for 'action' and 'nargs'.\n'action' is a custom Action created to run the decorated method and 'nargs' is the number of parameters in the decorated method.\n\n###### Examples:\nfoo.py\n```\n\nfrom polidoro_argument import Argument, PolidoroArgumentParser\n\n@Argument\ndef bar():\n    print('hi')\n\nparser = ArgumentParser()\nparser.parse_args()\n```\nResult:\n```\n$ python foo.py --bar\nhi \n```\n\nYou can pass argument to the method\n```\n@Argument\ndef bar(baz=None):\n    print(baz)\n```\n```\n$ python foo.py --bar Hello\nHello\n```\nTo create commands\n```\n@Command\ndef command():\n    print('this is a command')\n```\n```\n$ python foo.py command\nthis is a command\n```\nWith arguments\n```\n@Command\ndef command_with_arg(arg, arg1=None):\n    print('this the command arg: %s, arg1: %s' % (arg, arg1))\n```\n```\n$ python foo.py command_with_arg Hello\nthis the command arg: Hello, arg1: None\n$ python foo.py command_with_arg Hello --arg1 World\nthis the command arg: Hello, arg1: World\n```\nUsing a Class\n```\nclass ClassCommand:\n    @staticmethod\n    @Argument\n    def argument_in_class():\n        print('argument_in_class called')\n\n    @staticmethod\n    @Command\n    def command_in_class(arg='Oi'):\n        print('command_in_class called. arg=%s' % arg)\n```\n```\n$ python foo.py classcommand --argument_in_class\nargument_in_class called\n$ python foo.py classcommand command_in_class\ncommand_in_class called. arg=Oi\n$ python foo.py classcommand command_in_class --arg=Ola\ncommand_in_class called. arg=Ola\n```\n\n\n\n\n\n",
    "bugtrack_url": null,
    "license": "unlicense",
    "summary": "Package to create command line arguments for Python.",
    "version": "3.1.3",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "b78a9990ca37f25ca32e979a784024cd",
                "sha256": "550624e84bc92732c552cbb4a3d72680828788c294ef65a2f3e2b90e2b48a86c"
            },
            "downloads": -1,
            "filename": "polidoro_argument-3.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b78a9990ca37f25ca32e979a784024cd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11734,
            "upload_time": "2021-05-07T15:05:32",
            "upload_time_iso_8601": "2021-05-07T15:05:32.754842Z",
            "url": "https://files.pythonhosted.org/packages/8b/34/e0705aa72fc94aaf88f0a0f07f2e2ad16fc859115a81d507924a350e013a/polidoro_argument-3.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "638acfc7c1ed2594ef3293b4cd0641ba",
                "sha256": "2c2e70a4a2d52e82691c3b167d7b702a06585f37b667d592a2a376e9909ce0a7"
            },
            "downloads": -1,
            "filename": "polidoro-argument-3.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "638acfc7c1ed2594ef3293b4cd0641ba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10560,
            "upload_time": "2021-05-07T15:05:34",
            "upload_time_iso_8601": "2021-05-07T15:05:34.761011Z",
            "url": "https://files.pythonhosted.org/packages/bf/66/d6d1de6a4665e3df06fdcfa8787f5211055721fcedeb4b7984baecd17c6c/polidoro-argument-3.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-05-07 15:05:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "heitorpolidoro",
    "error": "Could not fetch GitHub repository",
    "lcname": "polidoro-argument"
}
        
Elapsed time: 0.23962s