pyTooling.CLIAbstraction.Argument

This module implements command line arguments without prefix character(s).

Variables

Classes


Variables

pyTooling.CLIAbstraction.Argument.ValueT

The type of value in a valued argument.

~ValueT

Classes

class pyTooling.CLIAbstraction.Argument.CommandLineArgument[source]

Base-class for all Argument classes.

An argument instance can be converted via AsArgument to a single string value or a sequence of string values (tuple) usable e.g. with subprocess.Popen. Each argument class implements at least one pattern parameter to specify how argument are formatted.

There are multiple derived formats supporting:

Inheritance

Inheritance diagram of CommandLineArgument

_pattern: ClassVar[str]

Format string to render the argument on the command line.

abstractmethod AsArgument()[source]

Convert this argument instance to a string representation using the matching pattern based on the internal name and value.

The result isn’t escaped: subprocess.Popen passes each string to the program as one argument. __str__() returns it escaped for a command line.

Return type:

str | Iterable[str]

Returns:

Formatted argument.

Raises:

NotImplementedError – This is an abstract method and must be overwritten by a subclass.

__str__()[source]

Return this argument as written on a command line, escaped for the current platform.

Return type:

str

Returns:

The formatted argument, escaped by formatCommandLine: shlex.join(), on Windows subprocess.list2cmdline().

static _DoubleQuotedLiteral(value)[source]

Return a string as a Python literal in double quotes, escaped as repr() escapes it.

Parameters:

value (str) – The string.

Return type:

str

Returns:

The string’s literal.

__repr__()[source]

Return this argument as a Python literal, with strings in double quotes.

Return type:

str

Returns:

The formatted argument (AsArgument()) as a literal; a sequence as a list.

classmethod GetMethodsWithAttributes(predicate=None)

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (type[TAttr] | Iterable[type[TAttr]] | None) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[..., Any], tuple[Attribute, ...]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

__new__(**kwargs)
class pyTooling.CLIAbstraction.Argument.ExecutableArgument[source]

Represents the executable.

Inheritance

Inheritance diagram of ExecutableArgument

__init__(executable)[source]

Initializes a ExecutableArgument instance.

Parameters:

executable (Path) – Path to the executable.

Raises:

TypeError – If parameter ‘executable’ is not of type Path.

Return type:

None

_executable: Path

Path to the executable this argument represents.

property Executable: Path

Property to access the path to the wrapped executable (_executable).

Returns:

Internal path to the executable.

Raises:

TypeError – If an assigned value is not of type Path.

AsArgument()[source]

Convert this argument instance to a string representation using the matching pattern based on the internal path to the wrapped executable.

Return type:

str | Iterable[str]

Returns:

Formatted argument.

classmethod GetMethodsWithAttributes(predicate=None)

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (type[TAttr] | Iterable[type[TAttr]] | None) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[..., Any], tuple[Attribute, ...]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

static _DoubleQuotedLiteral(value)

Return a string as a Python literal in double quotes, escaped as repr() escapes it.

Parameters:

value (str) – The string.

Return type:

str

Returns:

The string’s literal.

__new__(**kwargs)
__repr__()

Return this argument as a Python literal, with strings in double quotes.

Return type:

str

Returns:

The formatted argument (AsArgument()) as a literal; a sequence as a list.

__str__()

Return this argument as written on a command line, escaped for the current platform.

Return type:

str

Returns:

The formatted argument, escaped by formatCommandLine: shlex.join(), on Windows subprocess.list2cmdline().

_pattern: ClassVar[str] = None

Format string to render the argument on the command line.

class pyTooling.CLIAbstraction.Argument.DelimiterArgument[source]

Represents a delimiter symbol like --.

Inheritance

Inheritance diagram of DelimiterArgument

AsArgument()[source]

Convert this argument instance to a string representation using the matching pattern.

Return type:

str | Iterable[str]

Returns:

Formatted argument.

classmethod GetMethodsWithAttributes(predicate=None)

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (type[TAttr] | Iterable[type[TAttr]] | None) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[..., Any], tuple[Attribute, ...]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

static _DoubleQuotedLiteral(value)

Return a string as a Python literal in double quotes, escaped as repr() escapes it.

Parameters:

value (str) – The string.

Return type:

str

Returns:

The string’s literal.

__new__(**kwargs)
__repr__()

Return this argument as a Python literal, with strings in double quotes.

Return type:

str

Returns:

The formatted argument (AsArgument()) as a literal; a sequence as a list.

__str__()

Return this argument as written on a command line, escaped for the current platform.

Return type:

str

Returns:

The formatted argument, escaped by formatCommandLine: shlex.join(), on Windows subprocess.list2cmdline().

_pattern: ClassVar[str] = '--'

Format string to render the argument on the command line.

class pyTooling.CLIAbstraction.Argument.NamedArgument[source]

Base-class for all command line arguments with a name.

Inheritance

Inheritance diagram of NamedArgument

_name: ClassVar[str]

Name of the argument, inserted into _pattern.

property Name: str

Get the internal name.

Returns:

Internal name.

AsArgument()[source]

Convert this argument instance to a string representation using the matching pattern based on the internal name.

Return type:

str | Iterable[str]

Returns:

Formatted argument.

Raises:

ValueError – If internal name is None.

classmethod GetMethodsWithAttributes(predicate=None)

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (type[TAttr] | Iterable[type[TAttr]] | None) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[..., Any], tuple[Attribute, ...]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

static _DoubleQuotedLiteral(value)

Return a string as a Python literal in double quotes, escaped as repr() escapes it.

Parameters:

value (str) – The string.

Return type:

str

Returns:

The string’s literal.

__new__(**kwargs)
__repr__()

Return this argument as a Python literal, with strings in double quotes.

Return type:

str

Returns:

The formatted argument (AsArgument()) as a literal; a sequence as a list.

__str__()

Return this argument as written on a command line, escaped for the current platform.

Return type:

str

Returns:

The formatted argument, escaped by formatCommandLine: shlex.join(), on Windows subprocess.list2cmdline().

_pattern: ClassVar[str] = '{0}'

Format string to render the argument on the command line.

class pyTooling.CLIAbstraction.Argument.ValuedArgument[source]

Base-class for all command line arguments with a value.

Inheritance

Inheritance diagram of ValuedArgument

__init__(value)[source]

Initializes a ValuedArgument instance.

Parameters:

value (ValueT) – Value to be stored internally.

Raises:
Return type:

None

_value: ValueT

Value of the argument, inserted into _pattern.

property Value: ValueT

Property to access the internal value (_value).

Returns:

Internal value.

Raises:

ValueError – If None is assigned.

AsArgument()[source]

Convert this argument instance to a string representation using the matching pattern based on the internal value.

Return type:

str | Iterable[str]

Returns:

Formatted argument.

classmethod GetMethodsWithAttributes(predicate=None)

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (type[TAttr] | Iterable[type[TAttr]] | None) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[..., Any], tuple[Attribute, ...]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

static _DoubleQuotedLiteral(value)

Return a string as a Python literal in double quotes, escaped as repr() escapes it.

Parameters:

value (str) – The string.

Return type:

str

Returns:

The string’s literal.

__annotate_func__()

The type of the None singleton.

__new__(**kwargs)
__repr__()

Return this argument as a Python literal, with strings in double quotes.

Return type:

str

Returns:

The formatted argument (AsArgument()) as a literal; a sequence as a list.

__str__()

Return this argument as written on a command line, escaped for the current platform.

Return type:

str

Returns:

The formatted argument, escaped by formatCommandLine: shlex.join(), on Windows subprocess.list2cmdline().

_pattern: ClassVar[str] = '{0}'

Format string to render the argument on the command line.

class pyTooling.CLIAbstraction.Argument.StringArgument[source]

Represents a simple string argument.

A list of strings is available as StringListArgument.

Inheritance

Inheritance diagram of StringArgument

AsArgument()

Convert this argument instance to a string representation using the matching pattern based on the internal value.

Return type:

str | Iterable[str]

Returns:

Formatted argument.

classmethod GetMethodsWithAttributes(predicate=None)

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (type[TAttr] | Iterable[type[TAttr]] | None) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[..., Any], tuple[Attribute, ...]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

property Value: ValueT

Property to access the internal value (_value).

Returns:

Internal value.

Raises:

ValueError – If None is assigned.

static _DoubleQuotedLiteral(value)

Return a string as a Python literal in double quotes, escaped as repr() escapes it.

Parameters:

value (str) – The string.

Return type:

str

Returns:

The string’s literal.

__init__(value)

Initializes a ValuedArgument instance.

Parameters:

value (str) – Value to be stored internally.

Raises:
Return type:

None

__new__(**kwargs)
__repr__()

Return this argument as a Python literal, with strings in double quotes.

Return type:

str

Returns:

The formatted argument (AsArgument()) as a literal; a sequence as a list.

__str__()

Return this argument as written on a command line, escaped for the current platform.

Return type:

str

Returns:

The formatted argument, escaped by formatCommandLine: shlex.join(), on Windows subprocess.list2cmdline().

_pattern: ClassVar[str] = '{0}'

Format string to render the argument on the command line.

_value: ValueT

Value of the argument, inserted into _pattern.

class pyTooling.CLIAbstraction.Argument.StringListArgument[source]

Represents a list of string argument (StringArgument).

Inheritance

Inheritance diagram of StringListArgument

__init__(values)[source]

Initializes a StringListArgument instance.

Parameters:

values (Iterable[str]) – An iterable of str instances.

Raises:

TypeError – If iterable parameter ‘values’ contains elements not of type string.

Return type:

None

property Value: list[str]

Property to access the internal list of str objects (_values).

Note

On assignment, the list object is not replaced, but cleared and then reused by adding the given elements of the iterable.

Returns:

Reference to the internal list of str objects.

Raises:

TypeError – If an assigned iterable contains elements which are not of type string.

Setter accepts:

Iterable[str]

AsArgument()[source]

Convert this argument instance to a string representation using the matching pattern based on the internal value.

Return type:

str | Iterable[str]

Returns:

Sequence of formatted arguments.

classmethod GetMethodsWithAttributes(predicate=None)

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (type[TAttr] | Iterable[type[TAttr]] | None) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[..., Any], tuple[Attribute, ...]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

static _DoubleQuotedLiteral(value)

Return a string as a Python literal in double quotes, escaped as repr() escapes it.

Parameters:

value (str) – The string.

Return type:

str

Returns:

The string’s literal.

__new__(**kwargs)
__repr__()

Return this argument as a Python literal, with strings in double quotes.

Return type:

str

Returns:

The formatted argument (AsArgument()) as a literal; a sequence as a list.

__str__()

Return this argument as written on a command line, escaped for the current platform.

Return type:

str

Returns:

The formatted argument, escaped by formatCommandLine: shlex.join(), on Windows subprocess.list2cmdline().

_pattern: ClassVar[str] = '{0}'

Format string to render the argument on the command line.

_value: ValueT

Value of the argument, inserted into _pattern.

class pyTooling.CLIAbstraction.Argument.PathArgument[source]

Represents a single path argument.

A list of paths is available as PathListArgument.

Inheritance

Inheritance diagram of PathArgument

__init__(path)[source]

Initializes a PathArgument instance.

Parameters:

path (Path) – Path to a filesystem object.

Raises:

TypeError – If parameter ‘path’ is not of type Path.

Return type:

None

_path: Path

Path this argument represents.

classmethod GetMethodsWithAttributes(predicate=None)

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (type[TAttr] | Iterable[type[TAttr]] | None) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[..., Any], tuple[Attribute, ...]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

static _DoubleQuotedLiteral(value)

Return a string as a Python literal in double quotes, escaped as repr() escapes it.

Parameters:

value (str) – The string.

Return type:

str

Returns:

The string’s literal.

__new__(**kwargs)
__repr__()

Return this argument as a Python literal, with strings in double quotes.

Return type:

str

Returns:

The formatted argument (AsArgument()) as a literal; a sequence as a list.

__str__()

Return this argument as written on a command line, escaped for the current platform.

Return type:

str

Returns:

The formatted argument, escaped by formatCommandLine: shlex.join(), on Windows subprocess.list2cmdline().

_pattern: ClassVar[str] = None

Format string to render the argument on the command line.

property Value: Path

Property to access the internal path object (_path).

Returns:

Internal path object.

Raises:

TypeError – If an assigned value is not of type Path.

AsArgument()[source]

Convert this argument instance to a string representation using the matching pattern based on the internal value.

Return type:

str | Iterable[str]

Returns:

Formatted argument.

class pyTooling.CLIAbstraction.Argument.PathListArgument[source]

Represents a list of path arguments (PathArgument).

Inheritance

Inheritance diagram of PathListArgument

classmethod GetMethodsWithAttributes(predicate=None)

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (type[TAttr] | Iterable[type[TAttr]] | None) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[..., Any], tuple[Attribute, ...]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

static _DoubleQuotedLiteral(value)

Return a string as a Python literal in double quotes, escaped as repr() escapes it.

Parameters:

value (str) – The string.

Return type:

str

Returns:

The string’s literal.

__new__(**kwargs)
__repr__()

Return this argument as a Python literal, with strings in double quotes.

Return type:

str

Returns:

The formatted argument (AsArgument()) as a literal; a sequence as a list.

__str__()

Return this argument as written on a command line, escaped for the current platform.

Return type:

str

Returns:

The formatted argument, escaped by formatCommandLine: shlex.join(), on Windows subprocess.list2cmdline().

_pattern: ClassVar[str] = None

Format string to render the argument on the command line.

__init__(paths)[source]

Initializes a PathListArgument instance.

Parameters:

paths (Iterable[Path]) – An iterable os Path instances.

Raises:

TypeError – If iterable parameter ‘paths’ contains elements not of type Path.

Return type:

None

_paths: list[Path]

Paths this argument represents.

property Value: list[Path]

Property to access the internal list of path objects (_paths).

Note

On assignment, the list object is not replaced, but cleared and then reused by adding the given elements of the iterable.

Returns:

Reference to the internal list of path objects.

Raises:

TypeError – If an assigned iterable contains elements which are not of type Path.

Setter accepts:

Iterable[Path]

AsArgument()[source]

Convert this argument instance to a string representation using the matching pattern based on the internal value.

Return type:

str | Iterable[str]

Returns:

Sequence of formatted arguments.