The :class:`~pyTooling.CLIAbstraction.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. |br| See :ref:`ARG`.
- Construct a list of arguments in correct order and with proper escaping ready to be used with e.g. :mod:`subprocess`.
The following example implements a portion of the git
program and its --version
argument.
Program Definition
class Git(Program):
_executableNames = {
"Darwin": "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())
.. todo:: * set executable name based on the operating system.
.. todo:: * use decorator ``CLIArgument`` * usage of nested classes * parametrize nested classes with class-arguments
.. todo:: * Using dictionary syntax with nested classes as typed keys. * Using ``Value`` to change the arguments value at runtime.
.. todo:: * Explain helper methods to copy active arguments.