Skip to main content

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 BaseOptions to the BaseOptions object
  • Use [] of BaseOptions to get a BaseOption object
  • Use () of BaseOptions to get the value of a BaseOption 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")

Metadata

Release files for baseopt 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for baseopt 0.1.3
File Size Uploaded
baseopt-0.1.3.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for baseopt 0.1.3
File Interpreter ABI Platform
baseopt-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / baseopt-0.1.3.tar.gz

Download URL baseopt-0.1.3.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
800a1f7b0c593d53b06e8e138aabcf71069f3cb0c1388eea46cf747ca9444dd5
BLAKE2b-256 checksum
How to use checksums
1874251760f872b9c871907355affe7d74f083b4536c2bca927b5135c53d33eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / baseopt-0.1.3-py3-none-any.whl

Download URL baseopt-0.1.3-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f59341c2a187b5cdd7440d9399eac1421a9ebf3634b44dc22adcab98082ff7b
BLAKE2b-256 checksum
How to use checksums
274f6d10c630acfd45432735b4d3eb7c889b80d5a983e9befeebc4b05eec9c05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page