Skip to main content

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.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

baseopt-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file baseopt-0.1.2.tar.gz.

File metadata

  • Download URL: baseopt-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 a41deeaabc638cc2d484ff9b64011aacd0e46e2acebb0ee1f8b8b3e73d8c37e9
MD5 a81f77743c34e5ad5789d79b64351126
BLAKE2b-256 756f02d99179ac4ef2b034de209eb00b9090e97530329e8aeea2fcede325c46d

See more details on using hashes here.

File details

Details for the file baseopt-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: baseopt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d7f3cf9aa2efd130793d63c8e93d9cd1187948bccd6dd706478f0a28c551d785
MD5 78acb1be82190c240b66bdd32a8982a7
BLAKE2b-256 281a8c640d27cb43c32b45ff33cbba365c94b35221e6e9632ac16a3e969022c1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page