https://github.com/ybubnov/flagparse
Python modular command-line interfaces.
https://github.com/ybubnov/flagparse
cli python
Last synced: over 1 year ago
JSON representation
Python modular command-line interfaces.
- Host: GitHub
- URL: https://github.com/ybubnov/flagparse
- Owner: ybubnov
- License: mit
- Created: 2019-09-03T17:57:24.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-19T18:29:08.000Z (over 6 years ago)
- Last Synced: 2025-04-03T11:56:21.096Z (over 1 year ago)
- Topics: cli, python
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flagparse
[![Build Status][BuildStatus]](https://travis-ci.org/ybubnov/flagparse)
Flagparse is a library for building modular command-line interfaces with
accent on nested commands. This library removes the pain of manually
constructing the argument parsing and applying handler for each command, all
of this is done by this tiny library.
## Installation
```bash
pip install flagparse
```
## Usage and documentation
Please see the [wiki][Wiki] for basic usage and other documentation of using
flagparse.
Here is an example of a simple Flagparse app:
```py
import flagparse
class Sum(flagparse.SubCommand):
"""Sub-command to handle numbers summation."""
name = "sum"
arguments = [
(["integers"],
dict(metavar="INT",
type=int,
nargs="+",
help="integers to be summed")),
]
def handle(self, args: flagparse.Namespace) -> None:
print(sum(args.integers))
class Calc(flagparse.Command):
"""A simple calculator that sums numbers."""
name = "calc"
if __name__ == "__main__":
Calc(subcommands=[Sum]).parse()
```
How it looks when run:
```bash
$ python main.py sum 1 2 3
6
```
## License
The openflow library is distributed under MIT license, therefore you are free
to do with code whatever you want. See the [LICENSE](LICENSE) file for full
license text.
[BuildStatus]: https://travis-ci.org/ybubnov/flagparse.svg?branch=master
[Wiki]: https://github.com/ybubnov/flagparse/wiki