CliArgTools
Small and easy to use cross-platform Python library for working with command line arguments. CliArgTools allows you to easily get the command line arguments, check if the flags are provided and generate and/or output error message if cli arguments given by the user is incorrect.
Code example:
from src import cliargtools
FILEPATH = cliargtools.getArgByFlag('-fp') # will add required flag -fp
DEBUG = cliargtools.isFlagPresent('-debug') # will check for optional flag -debug
ALL_ARGS = cliargtools.getAllArgs() # will return all the arguments given
if (DEBUG):
print("debug: " + str(DEBUG))
print("some filepath: " + FILEPATH) # printing given filepath and all the arguments
print("cli arguments: " + ' '.join(ALL_ARGS)) # if -debug argument is present
else:
print("Sadly, no debug, but the program still works!")
GetArgsByFlag
Can be used to get the value provided after any flag.
arguments:
required:
flag- string that will be used to identiry the argument (example:"-i")
optional:
optional: bool = Falsespecifies if the argument is optional or requireddefaultValue: any- value that will be returned if not value was given by usererrorMessage: str- will be printed if any error is presenterrorMessageIfNoArg: str- will be printed if flag was given but the value wasn't providederrorMessageIfNoFlag: str- will be printed if required flag wasn't givendefaultErrors: bool = True- specifies if default errors will be printed,Trueby default.
returns:
str- string if given by the user after theflagdefaultValue- if required argument is not given by the user
By default the flag argument will be required by the program, but can be set to optional with optional keyword argument. In this case will return None if the value wasn't present.
If argument is not optional will print the default error message, specifying what is wrong with the arguments given by the user.
Error messages can be overriden by the errorMessage, errorMessageIfNoArg, and errorMessageIfNoFlag keyword arguments.
Default error messages can be disabled by setting defaultArgumets to False
getArgByFlag(flag: str, optional:bool = False, defaultValue:str = None,
errorMessage:str = None, errorMessageIfNoArg:str = None,
errorMessageIfNoFlag:str = None, defaultErrors:bool = True)
isFlagPresent
Can be used to check if the flag is given by the user.
arguments:
required:
flag- string that will be used to identiry the argument (example:"-i")
optional:
optional: bool = Truespecifies if the flag is optional or requirederrorMessage: str- will be printed if any error is presentdefaultErrors: bool = True- specifies if default errors will be printed,Trueby default.
returns:
bool-TrueorFalsevalue where True means that argument was given by the user, andFalsemeans that it is missing.
By default the flag is optional, it means that no error missage will be printed if the flag is missing and False will be returned.
This behaviour can be changed by the optional keyword argument. if optional=False will print errorMessage if the flag wasn't present.
Default error messages can be disabled by setting defaultArgumets to False
Error message can be overriden by the errorMessage keyword argument.
isFlagPresent(flag, optional=True, errorMessage=None, defaultErrors:bool = True)
getAllArgs
Can be used to get the list of all the arguments given by the user
returns:
list- list of all the values given as a cli arguments by the user
getAllArgs()
Metadata
Release files for CliArgTools 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| CliArgTools-1.0.tar.gz | 3.9 kB | Without provenance | Details for CliArgTools-1.0.tar.gz |
Release files / CliArgTools-1.0.tar.gz
| Download URL | CliArgTools-1.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
896db7445aa5635ffed598b14869d54458e3028c4ceaac654ab3fb77b697d1e9
|
|
BLAKE2b-256 checksum How to use checksums |
ec01a4a1c7539b3d59ae7439ead35c0c50e15056d3ab9fcd2ea50e8e3dd9e35b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.1
|
Security for CliArgTools 1.0
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.