Parse and manage CLI options/arguments from getopt
Project description
baseopt
A simple package for parsing and managing CLI options/arguments from getopt.
Install
pip install baseopt
Usage
import sys
from baseopt import BaseOption, BaseOptions
# Or you can just initialize the BaseOptions
options = BaseOptions([
BaseOption(name="help", shortname="h", dtype=bool, default=False),
BaseOption(name="file", shortname="f", dtype=str, doc="Path to the input file")
])
# Or you can create your own option classes
class Options(BaseOptions):
def __init__(self):
super().__init__()
# Append available options
self.add(name="help", shortname="h", dtype=bool, default=False)
self.add(name="file", shortname="f", dtype=str, doc="Path to the input file")
options = Options()
# Parse command line arguments
options.parse(sys.argv[1:])
# Check if we should print a help message
if options["help"].value:
options.help()
sys.exit(1)
print(options["file"].value)
Executing the above script gives
Options:
-h | --help
-f | --file Path to the input file
(def = "None")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
baseopt-0.1.1.tar.gz
(6.3 kB
view details)
Built Distribution
File details
Details for the file baseopt-0.1.1.tar.gz
.
File metadata
- Download URL: baseopt-0.1.1.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0b6fadbf5d5c0482eac57902fe7cf2f3e11da072639f5fab8b5444d949f0ec2 |
|
MD5 | 6df755c2f93235e51c0a7986f33bd848 |
|
BLAKE2b-256 | f5341bb2d6ab4e858d8fac3cb8c27d0df1dbf8fac3a506a1ef64cbab5c126cab |
File details
Details for the file baseopt-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: baseopt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bed8b3b7f99c985b426405646f64ec7108db3074ecb7166bd4503f58ef69ca75 |
|
MD5 | 7b20365a297bec6053ffab6e2a26c47f |
|
BLAKE2b-256 | 751a23064691b9f9d9353200ccce7cc7378eb229068d34655b12a350d6b770b0 |