SysArg
CLI Argument Parser Functions
Contents
- Install
- Initialize
- Functions
- defind : Setup option/command/group/help....
- Cmd : Get Inputed Special Command (it need cmd_id=1 parameter at initialize)
- Get : Get parameter's input values
- Version : show version
- Check : Check option
- Help : Dispaly Help
- Install
pip3 install sysarg
- Initialize
- program : Program Name
- cmd_id : command ID
- desc : Program Description
- epilog : Program Epilog (tail string of the help)
- version : define Program version
- help_desc: Customize description of Help
import SysArg
arg=SysArg.SysArg(program='ArgTest',desc='ARG. Testing',version='1.0')
if you want make a special command in this application case: (ArgTest command ...)
import SysArg
arg=SysArg.SysArg(program='ArgTest',desc='ARG. Testing',version='1.0',cmd_id=1)
- defind
- name: (required) parameter name
- short: short parameter(-XX)
- long: long parameter(--XX)
- params:
- default:0(found parameter then True),
- 0<n: how many required parameter input data(number)
- - : until next parameter or until finished inputs
- params_name: --abc=<PARAMS_NAME(Explain String)> (this format)
- required: required parameter (default False, need then True)
- default: default value when no input
- type: default str, wrong type then not taken (support: str,int,list,tuple,dict)
- spliter: if you set list or tuple at type. but input is single string then using spliter (example: , : )
- group: make a special group's prameters
- group_desc: group desciption
- command: If Command Group then True
- arg: If this group is command and need input argument then True
- select: If you want selectable input, this is list type format, if wrong input then Get() command will make an error
example format: -n, --numbre=INT
arg.define('number',short='-n',long='--number',params_name='INT',type=int,desc='Number Input')
it this option required value
arg.define('number',short='-n',long='--number',params_name='INT',type=int,desc='Number Input',required=True)
Add some of GROUP(ex: INPUT)
arg.define('number',short='-n',long='--number',params_name='INT',type=int,desc='Number Input',group='INPUT')
example format: -n, --numbre INT
arg.define('number',short='-n',long='--number',params=1,type=int,desc='Number Input')
example format: -l, --list ['A','B']
arg.define('List',short='-l',long='--list',params=1,type=list,desc='List Input')
example format: -l, --list 'A,B,C'
arg.define('List',short='-l',long='--list',params=1,type=list,spliter=',',desc='List Input')
example format: -l, --list A B C
arg.define('List',short='-l',long='--list',params=3,type=list,desc='List Input')
example default : if not input then default get 7
arg.define('N',short='-n',long='--number',params=1,type=int,desc='Number Input',default=7)
example check parameter: if -n or --number parameter then True
arg.define('N',short='-n',long='--number')
example command group:
arg.define(group_desc='File list',group='ls',command=True)
arg.define('show_detail',short='-l',desc='show detail',group='ls')
arg.define('show_time',short='-t',desc='show time',group='ls')
arg.define('number',short='-n',long='--number',params_name='INT',type=int,desc='Number Input',group='INPUT')
arg.define(group_desc='Power command',group='power',command=True,arg=True,select=['on','off','reset'])
- Cmd Get Input Command name
cmd=arg.Cmd()
Check input 'command'
if arg.Cmd('command'):
~~~~
else:
~~~~
- Get parameter's value
- All data
param=arg.Get()
- Get group INPUT's All data
param=arg.Get(group='INPUT')
- Get value of COMMAND power's data
# ./APP power -i x.x.x.x on
if arg.Cmd('power'):
pw_cmd=arg.Get(group='power')
if pw_cmd == 'on':
...
elif pw_cmd == 'off':
...
....
- Get Parameter number's data
param=arg.Get('number')
- Get Parameter List's data in the INPUT group
param=arg.Get('List',group='INPUT')
Simple Example)
import SysArg
arg=SysArg.SysArg(program='ArgTest',desc='ARG. Testing',version='1.0',cmd_id=1)
arg.define('a',short='-a',long='--abc',desc='test input',params=1)
arg.define(group_desc='test command',group='ls',command=True)
arg.define('detail',short='-l',desc='show detail',group='ls')
arg.define('find_time',short='-t',desc='find time',group='ls',params=1)
arg.Version()
arg.Help()
cmd=arg.Cmd()
a=arg.Get('a')
Output:
$ python3 a.py --help
Usage: ArgTest <command> [OPTION] [<args>]
Version: 1.0
ARG. Testing
Supported <command>s are:
ls test command
[OPTION]
-h, --help Help
-a, --abc test input(input(1):S)
* ls test command
-l show detail
-t find time(input(1):S)
Metadata
Release files for sysarg 2.0.12
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 |
|---|---|---|---|---|
| sysarg-2.0.12.tar.gz | 14.1 kB | Without provenance | Details for sysarg-2.0.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sysarg-2.0.12-py3-none-any.whl | Python 3 | none | any | Details for sysarg-2.0.12-py3-none-any.whl |
Total release size: 25.6 kB
Release files / sysarg-2.0.12.tar.gz
| Download URL | sysarg-2.0.12.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b38112469055a7408e9761d17cc60bb9fdb79c3e905c3ae6b3972982a5a2f71a
|
|
BLAKE2b-256 checksum How to use checksums |
37b907d6a2437ed3803f75854d36130b251c24f5c43121e15bfb34fc1bf7823d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.18
|
Release files / sysarg-2.0.12-py3-none-any.whl
| Download URL | sysarg-2.0.12-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a06f64c07892db08582be340448cbd72b615deb0cd75b461465b4a67ec4b85f1
|
|
BLAKE2b-256 checksum How to use checksums |
bfcc7a6a482161155f423f4357db18f650b6287226e1217be5216ecf4966c45c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.18
|
Security for sysarg 2.0.12
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.