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")

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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

baseopt-0.1.3-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

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

Hashes for baseopt-0.1.3.tar.gz
Algorithm Hash digest
SHA256 800a1f7b0c593d53b06e8e138aabcf71069f3cb0c1388eea46cf747ca9444dd5
MD5 90e8cbadbae1d9b89bd5e0e92cb0adbb
BLAKE2b-256 1874251760f872b9c871907355affe7d74f083b4536c2bca927b5135c53d33eb

See more details on using hashes here.

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

Hashes for baseopt-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4f59341c2a187b5cdd7440d9399eac1421a9ebf3634b44dc22adcab98082ff7b
MD5 a8a82c00225b45662a18a620212911bb
BLAKE2b-256 274f6d10c630acfd45432735b4d3eb7c889b80d5a983e9befeebc4b05eec9c05

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page