1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
.. _CLIABS/Program:
Program
#######
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:`CLIABS/Arguments`.
* Construct a list of arguments in correct order and with proper escaping ready to be used with e.g. :mod:`subprocess`.
Simple Example
**************
The following example implements a portion of the ``git`` program and its ``--version`` argument.
.. rubric:: Program Definition
.. code-block:: Python
:name: PROG:Example:Definition
:caption: Git program defining --version argument.
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."""
.. rubric:: Program Usage
.. code-block:: Python
:name: PROG:Example:Usage
:caption: Usage of the abstracted Git program.
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
.. _CLIABS/CLIArgument:
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.
|