Metadata-Version: 2.1
Name: cmcaine-cli
Version: 0.0.1
Summary: Easy CLIs from function inspection
Home-page: https://github.com/cmcaine/cli
Author: Colin Caine
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown

# CLI

> An extremely easy to use library to generate python CLIs from functions through introspection.

Automatically generate the equivalent of this:

```python
import argparse
parser = argparse.ArgumentParser(description="Generate a cryptographic token with a given entropy.")
parser.add_argument('method', nargs='?', default='xkcd', choices=('xkcd', 'short'))
parser.add_argument('entropy', nargs='?', default=70, type=int)
args = parser.parse_args()

if args.method == 'xkcd':
    print(xkcd(args.entropy))
else:
    print(alphanumeric(args.entropy))
```

from this:

```python
from cli import Choice, cli

def token(method:Choice('xkcd', 'short')='xkcd', entropy=70):
    "Generate a cryptographic token with a given entropy."
    if method == 'xkcd':
	return xkcd(entropy)
    else:
	return alphanumeric(entropy)

cli(token)()
```

Keyword arguments (optional or mandatory) are supported as is one varargs argument per function. Arguments will be automatically converted into the type of their default argument (if it is not None) or their type annotation.

You can even generate CLIs for a whole module (or any other object with function attributes):

```python
import example
from cli import cli

# convert_numbers automatically converts strings to int, float or complex so
# you don't have to annotate all the functions in a module. YMMV.
cli(example, convert_numbers=True)()

# You can get a reference to the current module with sys.modules[__name__]
```

## Code quality

The code is very short, clearly documented inline and all advertised features are tested.

## Reference

```python
def example(positional, arguments):
    pass

def defaults(normally_one=1):
    pass

def typed(positional:bool, positional2:int):
    pass

def keyword(positional, *, keyword1=False, keyword2='default_filename'):
    pass

def mandatory_keywords(positional, *, keyword1, keyword2):
    pass

def varargs(pos1, pos2, *rest):
    pass

def choice_from_list(person:Choice('Ann', 'Bob', 'Charlie'))
    pass
```


