Skip to main content

Argument Parser

Project description

optioner

Static Badge Static Badge Static Badge Static Badge Static Badge


v1.3.5

Installation    |    Usage


About

Optioner is a lightweight Argument Parser and easy to use.

Installation

$ pip install optioner

Usage

initialization
>>> 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)
 |      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:]
 |          compulsort (list | optional): optional compulsory arguments
 |
 |  ----------------------------------------------------------------------
 |  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)
>> optionCTRL._argparse()

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

or 

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

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

optioner-1.3.5.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

optioner-1.3.5-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file optioner-1.3.5.tar.gz.

File metadata

  • Download URL: optioner-1.3.5.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for optioner-1.3.5.tar.gz
Algorithm Hash digest
SHA256 3c9ae787cdeb78a46ca87643ea0098b41356a81a7aab0ac5c6a00228606bc943
MD5 01b832de7411a2f3f69ecfba3cdef4bd
BLAKE2b-256 35b0b3c155ddeb531edf28e5df4dfdcfe987bee554397b191bfc395d681ad7dd

See more details on using hashes here.

File details

Details for the file optioner-1.3.5-py3-none-any.whl.

File metadata

  • Download URL: optioner-1.3.5-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for optioner-1.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 444be958b6671ea7eaef0f0c6d300c439e1d71b5f3787cf26dfc63be58f8145e
MD5 739d46386c04a2c6ccf1f33b565c5d30
BLAKE2b-256 133858ef4688bb13724dba27b0311bd5a8c4877d78b10bf4154ed847674e5ea3

See more details on using hashes here.

Supported by

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