Skip to main content

optioner

Continuous Deployment Feature Tests Build status codecov PyPI - Version Python Version from PEP 621 TOML PyPI - Wheel Dependents (via libraries.io) GitHub License GitHub last commit


Installation    |    Usage


About

Optioner is a lightweight Argument Parser and easy to use. Full documentation here

Installation

$ pip install optioner

Usage

initialization

[ Full Documentation ]

>>> from optioner import options
>>> help(options)

Help on class options in module optioner:

class options(builtins.object)
 |  options(shortargs: list, longargs: list, gotargs: list)
 |
 |  Methods defined here:
 |
 |  __init__(self, shortargs: list, longargs: list, gotargs: list, compulsory_short_args:list =[], compulsory_long_args:list =[], ignore: list[str] [], ifthisthennotthat:list[list[str]] = [[],[]])
 |      init function: This runs everytime the class is called.
 |
 |      Args:
 |          shortargs (list): example: ['h', 'l', 'i', ...]
 |          longargs (list): example: ['help', 'lock', 'init', ...]
 |          gotargs (list): sys.argv[1:]
 |          compulsory_short_args (list | optional): optional compulsory arguments
 |          compulsory_long_args (list | optional): corresponding optional compulsory arguments
 |          ignore (list[str] | optional): if these args are found, compulsion args will be overridden. (suitable if you have compulsory args and you also need --help or --version args)
 |          ifthisthennotthat (list[list[str]] | optional): if you have a condition where if a specific argument is provided, then some other argument cannot be provided.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables (if defined)
use method

after creating class object, call _argparse() method

help:

>>> help(options._argparse)

Help on function _argparse in module optioner:

_argparse(self)
    _argparse: checks all the arguments and stores error if any

    Return:
        actualargs (list): all valid args found.
        argcheck (boolean): Boolean (True: all good, False: Found undefined args)
        argerror (str): error note (if all good, no error note)
        falseargs (list): wrong args if any. (if None, empty list)

usage:

# import module
>>> from optioner import options
>>> import sys
# define short args
>>> shortargs = ['a', 'b']
# define long args
>>> longargs = ['assign', 'bind']
# create option control
>>> optionCTRL = options(shortargs, longargs, sys.argv[1:])
# get values
>>> actualargs, argcheck, argerror, falseargs = optionCTRL._argparse()

Extra features

Added a function to query argument value.

>>> help(options._what_is)

Help on function _what_is_ in module optioner:

_what_is_(self, arg: str)
    Returns the value of the argument that is passed.

    Args:
        arg (str): argument you need the value of
        count (int | optional): no of values you are expecting. Default is one

    Returns:
        str | tuple | None_: returns value of argument or None

usage:

>>> optionCTRL = options(shortargs, longargs, gotargs)
>>> args, check, error, falseargs = optionCTRL._argparse()

>>> optionCTRL._what_is_(args[0])

or 

>>> optionCTRL._what_is_(args[1])
# NOTE: if the user provided a longarg say --input, _what_is_ can be used with the corresponding shortarg, in this case it is -i, to find the value.

## For example:
optCTRL = options(shortargs, longargs, argv[1:])
args, check, error, falseargs = optCTRL._argparse()

# now it doesn't matter a longarg or a short arg is passed.
# calling _what_is_ with the shortarg or longarg will return the value.

if '-i' in args or '--input' in args:
    print(optCTRL._what_is_('i')) # or print(optCTRL._what_is_('input'))

# so if the user provided --input, if we call _what_is('i'), we can get the value.
# or if the user provided -i, we can call _what_is_('input'), to get the value.
# NOTE: this is an ease of use feature, only available for v1.5.2 and above.

Metadata

Release files for optioner 1.5.2

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

Source distribution (sdist)

Source distribution for optioner 1.5.2
File Size Uploaded Provenance
optioner-1.5.2.tar.gz 6.3 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 13.1 kB

Release files / optioner-1.5.2.tar.gz

Download URL optioner-1.5.2.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4b3e39ce3bbe505a395ee7798e0bf07ea1af6ce7d3440f92752f8e30c98f8158
BLAKE2b-256 checksum
How to use checksums
2605c1cb23cce2b24f065a2d90e7a33ecc9d5ba8b90d57123de7b964aff2d70b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / optioner-1.5.2-py3-none-any.whl

Download URL optioner-1.5.2-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc692864772209b89247fb5b9daa21393ec2435e07497bf4bc09efbc7c832692
BLAKE2b-256 checksum
How to use checksums
054c7030ae1659115378882a9a747e27de59abfefedff9bf53a89ca194fdd112
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Security for optioner 1.5.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.5.2 This release

2 release files No provenance

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