No project description provided
Project description
Argumental
annotation descripters to put closuer on classes and objects to allow argparse to be easy to use
Argue.py
A tool to decorate a python class to create an argparse ready command line application
Here is an example application
#!/usr/bin/env python3
import os,re,sys,json
from Argumental.Argue import Argue
# the argument decorator
args = Argue()
# create a root level argparse argument.
@args.argument(short='v', flag=True)
def verbose():
"""
detailed output mode
"""
return False
## simple arg main code
# args.parse()
# print(args.verbose())
## or create a reusable decorated class for the command line
# create a subparser based on the class
@args.command(name="class", single=False) # True to bypass to methods
class MyClass(object):
"""
My Class
"""
# add an argparse value as a property, override class attributes
@args.property(
short='v',
default='abc123',
help='with built in setter and deleter'
)
def value(self): return
# declare the method as a sub parser with method parameters
@args.operation(
name='method'
)
@args.parameter(
param='myParameter',
short='p',
name='parameter',
required=True,
help='My Parameter'
)
@args.returns(
type=dict,
help='test values'
)
def myOperation(self, myParameter=None):
"""
My Operation
"""
return dict(
myParameter=myParameter,
value=self.value
)
if __name__ == '__main__': args.execute()
output
$ ./MyClass.py -h
usage: Argue.py [-h] [-v] {class,args} ...
positional arguments:
{class,args} commands
class My Class
args print the values for the args
optional arguments:
-h, --help show this help message and exit
-v, --verbose detailed output mode
sub paser for class
$ ./MyClass.py class -h
usage: Argue.py class [-h] [-v VALUE] {method} ...
positional arguments:
{method} operations
method My Operation
optional arguments:
-h, --help show this help message and exit
-v VALUE, --value VALUE
with built in setter and deleter, default=abc123
sub parser for method
$ ./MyClass.py class method -h
usage: Argue.py class method [-h] -p PARAMETER
optional arguments:
-h, --help show this help message and exit
-p PARAMETER, --parameter PARAMETER
My Parameter
and calling the method
$ ./MyClass.py class -v myv method -p myp
{
"myParameter": "myp",
"value": "myv"
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Argumental-1.13.tar.gz
(11.1 kB
view details)
File details
Details for the file Argumental-1.13.tar.gz
.
File metadata
- Download URL: Argumental-1.13.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eb0b93acbcb686d466f99e7000df44f21de233914bb034173a44f3f3acf475b |
|
MD5 | 73e011100b9aa511991f5106cb403008 |
|
BLAKE2b-256 | 9dc619f9a0b6bc16632ef1bbab7c5ba88a8f4466ae97a654f0ee9368cb8f0b6e |