Program
The Program
represents an executable command line program. It offers an interface to
define and enable command line arguments.
Features:
Abstract a command line program as a Python class.
Abstract arguments of that program as nested classes derived from pre-defined Argument classes.
See Arguments.Construct a list of arguments in correct order and with proper escaping ready to be used with e.g.
subprocess
.
Simple Example
The following example implements a portion of the git
program and its --version
argument.
Program Definition
class Git(Program):
_executableNames: ClassVar[Dict[str, str]] = {
"Darwin": "git",
"FreeBSD": "git",
"Linux": "git",
"Windows": "git.exe"
}
@CLIArgument()
class FlagVersion(LongFlag, name="version"):
"""Print the version information."""
Program Usage
git = Git()
git[git.FlagVersion] = True
print(git.AsArgument())
Setting Program Names based on OS
Todo
set executable name based on the operating system.
Defining Arguments on a Program
Todo
use decorator
CLIArgument
usage of nested classes
parametrize nested classes with class-arguments
CLIArgument
CLIArgument attribute
Setting Arguments on a Program
Todo
Using dictionary syntax with nested classes as typed keys.
Using
Value
to change the arguments value at runtime.
Derive Program Variants
Todo
Explain helper methods to copy active arguments.