forked from camelia/python-argumentor
A simple, copylefted, lightweight library to work with command-line arguments in Python
argumentor
argumentor is a simple and lightweight library to build complex command-line tools.
Features
- Differenciate commands from options
- Define aliases for commands and options
- Automatically generate help pages
- Set default values
- No external dependencies
Installation
Using pip
The argumentor library can be installed from the Python Package Index (PyPI):
$ pip install argumentor
Installing from source
Using pip, it is also possible to install a package directly from source.
First clone the source code repository hosted on Codeberg:
$ git clone https://codeberg.org/camelia/python-argumentor argumentor
Then, enter the local repository and install argumentor (you may want to use a virtual environment):
$ cd argumentor
$ pip install .
Usage
Below is a minimalist code snippet that aims to demonstrate some basic uses of argumentor:
import sys
from argumentor import Argumentor
from argumentor.exc import ParsingError
argm = Argumentor("program-name")
argm.add_command(
"cmd1",
description="command 1",
)
argm.add_command(
"cmd2",
description="command 2",
)
argm.add_option(
"--opt",
description="global option 1",
)
argm.add_option_alias("-o", "--opt")
try:
cmd, opts = argm.parse()
except ParsingError as err:
print(err)
sys.exit(1)
More information about usage can be found in the documentation.
License
argumentor is free software! You are free to use, copy, modify, share and redistribute it under the terms of the GNU Lesser General Public License, version 3 or later.