Metadata-Version: 2.4
Name: InteractiveArgparse
Version: 0.2.0
Summary: Effortlessly turn any ArgumentParser script into an interactive prompt.
Home-page: https://github.com/mikimn/InteractiveArgparse
Author: Miki Mendelson-Mints
Author-email: mikimn1999@gmail.com
Project-URL: Bug Tracker, https://github.com/mikimn/InteractiveArgparse/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: PyInquirer==1.0.3
Requires-Dist: prompt_toolkit==1.0.14
Requires-Dist: rich==10.7.0
Provides-Extra: web
Requires-Dist: pywebio<1.8.4; extra == "web"
Dynamic: license-file

# InteractiveArgparse
![Coverage](docs/assets/coverage.svg)
![Build Status](https://github.com/mikimn/InteractiveArgparse/actions/workflows/python-package.yml/badge.svg)
[![PyPI version](https://badge.fury.io/py/InteractiveArgparse.svg)](https://badge.fury.io/py/InteractiveArgparse)

## Table of Contents

* [Installation](#installation)
* [Getting Started](#getting-started)
* [Usage](#usage)
* [Features](#features)
* [Prompters](#prompters)
* [Subcommands](#subcommands)

## Installation
To install, run
```shell script
pip install InteractiveArgparse
```

## Getting Started

You can wrap your existing `ArgumentParser` with an `InteractiveArgumentParser` like so:
```python
import argparse
from interactive_argparse import InteractiveArgumentParser

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--name", help="The user's name.")
    parser.add_argument("--should_greet", help="Whether or not I should greet the user", action="store_true")

    iparser = InteractiveArgumentParser(parser)
    args = iparser.parse_args()
    print(args)


if __name__ == "__main__":
    main()
```

Running this script without arguments results in interactive prompts like so:

<img alt="Example 1 output" src="docs/assets/example1.png" />

## Prompters

`InteractiveArgumentParser` can be pointed at a completely different interactive flow via its `prompter` argument: a `rich`-based terminal prompter (`RichPrompter`), an auto-generated web form (`WebPrompter`), or your own custom `Prompter` subclass.

```python
from interactive_argparse import interactive


@interactive("rich")
def build_parser():
    parser = argparse.ArgumentParser()
    parser.add_argument("--name", help="The user's name.")
    return parser


args = build_parser().parse_args()
```

<!-- TODO: add a screenshot of RichPrompter here, like example1.png above. -->

See [docs/prompters.md](docs/prompters.md) for how to use the built-in prompters and how to write your own.

## Subcommands

`ArgumentParser.add_subparsers()` is supported: `InteractiveArgumentParser` prompts for a subcommand first, then prompts for that subcommand's own arguments.

See [docs/subparsers.md](docs/subparsers.md) for details.

## Development

### Running tests

To run all tests:
```shell
python -m pytest
```

## Contributing

We welcome early adopters and contributors to this project! See the [Contributing](CONTRIBUTING.md) section for details.

## License

This project is open-sourced under the MIT license. See [LICENSE](LICENSE.md) for details.
