Skip to content

Latest commit

 

History

History
77 lines (51 loc) · 1.82 KB

Program.rst

File metadata and controls

77 lines (51 loc) · 1.82 KB

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:`ARG`.
  • 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.

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())

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

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.