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.0.tar.gz
(6.0 kB
view details)
Built Distribution
File details
Details for the file baseopt-0.1.0.tar.gz
.
File metadata
- Download URL: baseopt-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d2ad01dc4d4e630b71522cc7d9b2bd8981a4e14be1751709556b7348dbe4e19 |
|
MD5 | aa79b346f92be20579d5ff2f118b6f29 |
|
BLAKE2b-256 | 7cb6aab139b1bd9cb7327087bf20d130405126c2655af649cd0157818ad6c1e0 |
File details
Details for the file baseopt-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: baseopt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39868d4586a6c4ee4ea05d1a77cca08d1ec2b2143ad941ec25e8ab5bd2bb588e |
|
MD5 | 76ab734b7b2b675ee4f97cb576d02d11 |
|
BLAKE2b-256 | 21978b1e20a7215303e079d659e95512fdc47f18c36282c65d67b9ac1da1a07c |