A package for parsing and managing 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
- Use
BaseOptions
to create an option list - Add individual
BaseOption
s to theBaseOptions
object - Use
[]
ofBaseOptions
to get aBaseOption
object - Use
()
ofBaseOptions
to get the value of aBaseOption
object
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"):
options.help()
sys.exit(1)
print(options("file"))
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.3.tar.gz
(6.4 kB
view details)
Built Distribution
File details
Details for the file baseopt-0.1.3.tar.gz
.
File metadata
- Download URL: baseopt-0.1.3.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 800a1f7b0c593d53b06e8e138aabcf71069f3cb0c1388eea46cf747ca9444dd5 |
|
MD5 | 90e8cbadbae1d9b89bd5e0e92cb0adbb |
|
BLAKE2b-256 | 1874251760f872b9c871907355affe7d74f083b4536c2bca927b5135c53d33eb |
File details
Details for the file baseopt-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: baseopt-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.9 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 | 4f59341c2a187b5cdd7440d9399eac1421a9ebf3634b44dc22adcab98082ff7b |
|
MD5 | a8a82c00225b45662a18a620212911bb |
|
BLAKE2b-256 | 274f6d10c630acfd45432735b4d3eb7c889b80d5a983e9befeebc4b05eec9c05 |