Skip to main content

A simple package for a flag parsing

Project description

Flag library

Simple flag processing for Python

Supported types:

type implemented
int True
float True
str True
bool True
list True
custom True

Installation

$ pip install easy-flagger

Simple usage example

# python example.py -f 10.3
from flagger import Flagger

if __name__ == "__main__":
    flag = Flagger()
    f_flag = flag.parse_flag("-f", float)

    print(f_flag) # >> 10.3

List usage example

# python example.py -l 1,2,3
from flagger import Flagger

if __name__ == "__main__":
    flag = Flagger()
    l_flag = flag.parse_flag("-l", list, sep=",")

    print(l_flag) # >> ['1', '2', '3']

Checks flag for existence example

# python example.py --flag
from flagger import Flagger

if __name__ == "__main__":
    flag = Flagger()
    l_flag = flag.parse_flag("--flag")

    print(l_flag) # >> True

Using custom types flags

# python example.py -e Aerendyl
from flagger import Flagger

class Elven:
    allowed = {
        "aerendyl": 1,
        "erendriel": 2,
        "galadriel": 3
    }
    
    @staticmethod
    def check(value: str):
        value = value.lower()
        is_allowed = value in Elven.allowed
        if not is_allowed:
            raise ValueError("the language is that of Mordor, which I will not utter here")
        
        return Elven.allowed.get(value) 

if __name__ == "__main__":
    flag = Flagger()
    flagger.types.add_parser(Elven, Elven.check)
    
    elf = flagger.parse_flag("-e", Elven)
    
    print(elf) # >> Aerendyl

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

easy_flagger-2.0.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

easy_flagger-2.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file easy_flagger-2.0.0.tar.gz.

File metadata

  • Download URL: easy_flagger-2.0.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for easy_flagger-2.0.0.tar.gz
Algorithm Hash digest
SHA256 e16c86b61bdc05469568059cf3da7466776050097ef1077850e73958eb02b316
MD5 40baa3a2376a90731283126a92fa80b5
BLAKE2b-256 0b814f55b75d3452be4919a6de8ba11944a445a4e602bb557e056a72acd82ab1

See more details on using hashes here.

Provenance

The following attestation bundles were made for easy_flagger-2.0.0.tar.gz:

Publisher: release-action.yml on Doneeel/easy-flagger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file easy_flagger-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: easy_flagger-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for easy_flagger-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3bb71239b5a3f4797d420a4914058664b84b159bfc9be14ab505d56ae4da69cf
MD5 13d3570bf6d6d97231b88fd3474fe34d
BLAKE2b-256 8e134678d989769b1eb59742e1dfe4e59c3b57d73b344007c9933a6f6d788bfb

See more details on using hashes here.

Provenance

The following attestation bundles were made for easy_flagger-2.0.0-py3-none-any.whl:

Publisher: release-action.yml on Doneeel/easy-flagger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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