Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

baseopt

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

baseopt

A package for parsing and managing CLI options/arguments from getopt.

  • 0.1.3
  • PyPI
  • Socket score

Maintainers
1

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc