<commit_before># CLI Generator

Generate intuitive CLI frontends/tools from your Python module or function.

**License:** MIT

## Installation

Use `pip`!

    $ pip install cligenerator

## Usage

CLI Generator is implemented as a class, `CLIGenerator`.

To use, simply pass a function or module object to a new instance
(like: `gen = CLIGenerator(my_function_or_module)`), then you can get the code through `generate()` (like: `print(gen.generate())`).

## Examples

### From function

Let's make a CLI for a function that adds two numbers.

```python
import cligenerator

def my_function(num_a, num_b=3):
	return int(num_a) + int(num_b)

cligen = cligenerator.CLIGenerator(my_function)

# Save our CLI to a file
with open('test_prog.py', 'w') as test_prog_file:
	test_prog_file.write(cligen.generate())
```

Now our CLI program is in `test_prog.py`.

**Running the CLI:**

```bash
$ python3 test_prog.py
usage: test_prog.py [-h] [--num-b NUM_B] num_a
test_prog.py: error: the following arguments are required: num_a

$ python3 test_prog.py --help
usage: test_prog.py [-h] [--num-b NUM_B] num_a

A CLI tool for my_function

positional arguments:
  num_a

optional arguments:
  -h, --help     show this help message and exit
  --num-b NUM_B

$ python3 test_prog.py 5
8

$ python3 test_prog.py 5 --num-b 2
7

$ python3 test_prog.py 10 --num-b 4
14
```

### From module

Let's make a CLI for a simple module.

`mymodule.py`:

```python
# A simple module

def greet(hello='Hello', world='World!'):
	return hello + ', ' + world

def tab(text):
	return '\t' + text

def untab(text):
	return tab.lstrip('\\t').lstrip()
```

**Making the CLI:**

```python
import mymodule
import cligenerator

cligen = cligenerator.generate()

with open('test_prog.py', 'w') as test_prog_file:
	test_prog_file.write(cligen.generate())
```

**Running the CLI:**

```bash
$ python3 test_prog.py
usage: test_prog.py command options
test_prog.py: error: the following arguments are required: command

$ python3 test_prog.py greet
Hello, World!

$ python3 test_prog.py greet --world 'everyone!'
Hello, everyone!

$ python3 test_prog.py --hello 'Bye' --world 'everyone!'
Bye, everyone!

$ python3 test_prog.py tab 'Hello'<commit_msg>Fix README<commit_after># CLI Generator

Generate intuitive CLI frontends/tools from your Python module or function.

**License:** MIT

## Installation

Use `pip`!

    $ pip install cligenerator

## Usage

CLI Generator is implemented as a class, `CLIGenerator`.

To use, simply pass a function or module object to a new instance
(like: `gen = cligenerator.CLIGenerator(my_function_or_module)`), then you can get the code through `generate()` (like: `print(gen.generate())`).

## Examples

### From function

Let's make a CLI for a function that adds two numbers.

```python
import cligenerator

def my_function(num_a, num_b=3):
	return int(num_a) + int(num_b)

cligen = cligenerator.CLIGenerator(my_function)

# Save our CLI to a file
with open('test_prog.py', 'w') as test_prog_file:
	test_prog_file.write(cligen.generate())
```

Now our CLI program is in `test_prog.py`.

**Running the CLI:**

```bash
$ python3 test_prog.py
usage: test_prog.py [-h] [--num-b NUM_B] num_a
test_prog.py: error: the following arguments are required: num_a

$ python3 test_prog.py --help
usage: test_prog.py [-h] [--num-b NUM_B] num_a

A CLI tool for my_function

positional arguments:
  num_a

optional arguments:
  -h, --help     show this help message and exit
  --num-b NUM_B

$ python3 test_prog.py 5
8

$ python3 test_prog.py 5 --num-b 2
7

$ python3 test_prog.py 10 --num-b 4
14
```

### From module

Let's make a CLI for a simple module.

`mymodule.py`:

```python
# A simple module

def greet(hello='Hello', world='World!'):
	return hello + ', ' + world

def tab(text):
	return '\t' + text

def untab(text):
	return tab.lstrip('\\t').lstrip()
```

**Making the CLI:**

```python
import mymodule
import cligenerator

cligen = cligenerator.generate()

with open('test_prog.py', 'w') as test_prog_file:
	test_prog_file.write(cligen.generate())
```

**Running the CLI:**

```bash
$ python3 test_prog.py
usage: test_prog.py command options
test_prog.py: error: the following arguments are required: command

$ python3 test_prog.py greet
Hello, World!

$ python3 test_prog.py greet --world 'everyone!'
Hello, everyone!

$ python3 test_prog.py greet --hello 'Bye' --world 'everyone!'
Bye, everyone!

$ python3 test_prog.py tab 'Hello'
{'fraction_non_alphanumeric': 0.12906871609403256, 'fraction_numerical': 0.00949367088607595, 'mean_word_length': 4.357142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2155885', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1552, 'n_words': 507}