I'm looking for a library wrapper class to wrap an unix command into a Python class (, possibly for further presentation of command on the web). Ideally the command options are presented in the docstring of my wrapped class, and the library either automatically (or by method calls) extracts the optional and required arguments. Have you seen or heard of such a library?
Details related to function of library wrapper class
Lets say I want to wrap a set of commands in a dedicated Python class, possibly for further presentation on a web page which again could present the different options available for the command. Does such a library already exist?
Here are some further explanation on what I would like out of the library, if it exists, based on a somewhat simplistic command, helloworld
, with the following usage:
helloworld [-t <text>] [-n <num>] -U -U uppercase the output text -t <text> text to display, defaults to [Hello world] -n <num> Number of repeats
To wrap this command I would like to write a Python class somewhat similar to the following:
class HelloWorld(CommandWrapper):
"""Wrapper around helloworld command.
Options:
use_uppercase -U Uppercase the output text [false]
text -t <text> Text to display [Hello World]
repeats -n <num> Number of repeats [1]
"""
def __init__(self, *args):
self.build_options(__doc__, 'helloworld', args)
Now this could be used as follows:
all_defaults = HelloWorld()
with_args = HelloWorld(number=4, "Cool")
print("Command with all defaults: {}".format(all_defaults))
print("Command with arguments: {}".format(with_args))
which would print the following
Command with all defaults: helloworld
Command with arguments: helloworld -n 4 -t Cool
Optionally, this library wrapper class would also provide some elements/lists/dicts to be used on a web page where it was possible to get the name of the command, and what the various options are available (possibly with default options). Based on this information one could build a form where it was possible to add options, and choose suitable values for the added options.