# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['clipyarser']

package_data = \
{'': ['*']}

setup_kwargs = {
    'name': 'clipyarser',
    'version': '0.2.0',
    'description': 'A simple, declarative and easy-testable command line argument parser',
    'long_description': "# clipyarser\n\n`clipyarser` is a simple, declarative and easy-testable command line argument parser.\nInspired by [Typer](https://github.com/tiangolo/typer).\n\nSimply decorate your _normal_ python functions with `@clipyarser.main` or `@clipyarser.subcommand` and\nyou have a fully working cli program.\n`clipyarser` parses the arguments from the console and calls the matching function with the right arguments.\n\n## Tutorial\n\nHere we will create a small command line application with `clipyarser`.\n\n### Setup\n\nCreate a new directory and an empty `main.py` file.\n\nIn `main.py` import `clipyarser`:\n\n```python\nfrom clipyarser import CLI\n```\n\n### Create a CLI parser\n\nTo create a `clipyarser` parser, simply write this to your `main.py` file.\n\n```python\nfrom clipyarser import Clipyarser\n\nclipyarser = Clipyarser()\n```\n\nNow we create a simple greeting function.\n\n```python\n@clipyarser.main\ndef main(name: str) -> str:\n    return f'Hello {name}'\n```\n\nThis function simply returns a string which says hello to a person.\nThe name of the person is specified in the arguments of the function.\n\nNote that we use type hints in the function arguments.\nThis is necessary for `clipyarser`, because it parses the arguments from the console according to the specified types.\nSo when adding an argument `age` with type `int`, `clipyarser` does the parsing and validation of an `int` for you.\n\nNow, we have to execute `clipyarser` when the program is run.\n\n```python\nif __name__ == '__main__':\n    clipyarser.run()\n```\n\nAnd that is the first running example of `clipyarser`.\n\nNow lets test it.\n\n```shell\n$ python3 main.py\nusage: example.py [-h] name {} ...\nexample.py: error: the following arguments are required: name\n```\n\nOk, we have to specify the name of the person we want to greet.\nThis makes sense, because we take `name` as argument in our `main()` function.\n\n```shell\n$ python3 main.py Linus\nHello Linus\n```\n\nOk nice. That worked.\n\n### Default Arguments/Options\n\nSometimes it is convenient that a function has default arguments, which can be overridden when calling the function.\nThis is also possible with `clipyarser`. Let's try to take our greeting function from above and extend it with an\noptional argument.\n\n```python\n@clipyarser.main\ndef main(name: str, greeting: str = 'Hello') -> str:\n  return f'{greeting} {name}'\n```\n\nSo a user can customize the greeting. By default, the greeting is 'Hello', but it can be overridden.\nNow let's see how this looks in the console.\n\n```shell\n$ python3 main.py Linus\nHello Linus\n$ python3 main.py Linus --greeting Hi\nHi Linus\n```\n\nPretty intiutive, right?\n\n### Subcommands\n\nIn a bigger application, you may don't want all logic in a `main()` function.\nTherefore, `clipyarser` allows you to add subcommands.\n\n```python3\nfrom clipyarser import Clipyarser\n\nclipyarser = Clipyarser()\n\n@clipyarser.subcommand\ndef add(a: int, b: int) -> int:\n    return a + b\n```\n\nThis subcommand is a function which adds to numbers together.\n\n```shell\n$ python3 main.py add 2 4\n6\n```\n\nBut what has happened to the main function? For simplicity, we have deleted it.\nLet's try to add one again.\n\n```shell\n@clipyarser.main\ndef main(verbose: bool = False):\n  return 'verbose is {verbose}'\n```\n\nNow, when calling our application, the `main()` function always runs.\nThis might be handy when you have some logic or arguments that are independent of am individual subcommand, like a \nmore verbose output.\n\n```shell\n$ python3 main.py add 3 2\nverbose is False\n5\n$ python3 main.py --verbose true add 3 2\nverbose is True\n5\n```\n\n### Printing multiple lines\n\nUntil now when we want to print something to the console, we just returned it.\nThis might seem ok, but sometimes you want to print multiple lines or want to print something during a calculation.\nBut simple do `print()` is not a good idea. We will se soon why.\n\nTo print multiple lines, use the `yield` statement.\n\nBack to our greeting example from the beginning.\n\n```python3\nfrom time import sleep\nfrom clipyarser import Clipyarser\n\nclipyarser = Clipyarser()\n\n\n@clipyarser.main\ndef main(name: str):\n    yield 'Hello'\n    sleep(2)\n    yield name\n    yield 42\n```\n\n```shell\n$ python3 main.py Linus\nHello\nLinus\n42\n```\n\nBecause yield turns `main()` into a generator function, the output 'Hello' is printed immediately, but `name` takes \ntwo seconds to print.\n\nMaybe one could think of another solution: Just add all things to be printed to a list and return this list at the \nend of the function.\nThis is bad, because the whole output takes two seconds to print, in particular the 'Hello' line.\nThis makes your `clipyarser` not very responsive to the end user.\n\nOk. But why is just printing a bad idea? Testing.\n\n### Testing\n\nThe advantage of CLI is simple testing.\nFunctions like `main()` and `add()` are normal python functions, so you can call them like normal functions.\nThey take _normal_ arguments. They return _normal_ things.\nThis means that you can also test these functions like normal functions.\n\n```python3\nimport unittest\nfrom clipyarser import Clipyarser\n\nclipyarser = Clipyarser()\n\n\nclass TestMyCli(unittest.TestCase):\n    def test_greet(self):\n        actual = list(main('Linus'))\n        expected = ['Hello', 'Linus', 42]\n        self.assertEqual(actual, expected)\n```\n\nSince `main()` is a generator function, we can convert its output to a list and check if it is what we expect.\nIf using `print()`, this would not be as easy.\n\nOk, this is the end of the tutorial. Have fun using `clipyarser`.\n",
    'author': 'Linus',
    'author_email': 'linuskmr.dev@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/linuskmr/clipyarser',
    'packages': packages,
    'package_data': package_data,
    'python_requires': '>=3.8,<4.0',
}


setup(**setup_kwargs)
