https://github.com/wils0ns/oi
Command line parser for python applications.
https://github.com/wils0ns/oi
argparse cli parser python
Last synced: over 1 year ago
JSON representation
Command line parser for python applications.
- Host: GitHub
- URL: https://github.com/wils0ns/oi
- Owner: wils0ns
- License: mit
- Created: 2017-10-05T21:05:17.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-28T08:33:29.000Z (almost 6 years ago)
- Last Synced: 2025-01-26T12:41:34.139Z (over 1 year ago)
- Topics: argparse, cli, parser, python
- Language: Python
- Homepage:
- Size: 28.3 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
Oi - Simple command-line interface parser.
==========================================
This small python package implements a simple object-oriented layer on top of python's `argparse `_,
offering a more intuitive and easier way to build command-line interfaces.
Quick Start
-----------
Installing Oi package.
~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: bash
pip install oicli
Usage example
~~~~~~~~~~~~~
Given the commands bellow:
.. code-block:: bash
$ myapp user list
$ myapp user add --name Wilson --email wilson@codeminus.org
The parser would look like this:
.. code-block:: python
import oi
app = oi.App('myapp')
user_cmd = oi.Command(app, 'user')
user_list_cmd = oi.Command(user_cmd, 'list')
user_add_cmd = oi.Command(user_cmd, 'add')
user_add_cmd.add_argument('--name')
user_add_cmd.add_argument('--email')
print(app.parse_args())
Running the application with the code above:
.. code-block:: bash
$ myapp user
Namespace(command='user')
.. code-block:: bash
$ myapp user list
Namespace(command='user_list')
.. code-block:: bash
$ myapp user add --name Wilson --email wilson@codeminus.org
Namespace(command='user_add', email='wilson@codeminus.org', name='Wilson')
Notice the **command** attribute of the Namespace.
It correspond to the name of the command invoked.
The sub-command name is appended to its parent command to ensure a unique identifier is created.
What does "Oi" mean? Well... What does it mean to you? Try the `wiki `_.