Coverage for pyTooling/CLIAbstraction/ValuedFlag.py: 100%
28 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-22 21:29 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-22 21:29 +0000
1# ==================================================================================================================== #
2# _____ _ _ ____ _ ___ _ _ _ _ _ #
3# _ __ _ |_ _|__ ___ | (_)_ __ __ _ / ___| | |_ _| / \ | |__ ___| |_ _ __ __ _ ___| |_(_) ___ _ __ #
4# | '_ \| | | || |/ _ \ / _ \| | | '_ \ / _` || | | | | | / _ \ | '_ \/ __| __| '__/ _` |/ __| __| |/ _ \| '_ \ #
5# | |_) | |_| || | (_) | (_) | | | | | | (_| || |___| |___ | | / ___ \| |_) \__ \ |_| | | (_| | (__| |_| | (_) | | | | #
6# | .__/ \__, ||_|\___/ \___/|_|_|_| |_|\__, (_)____|_____|___/_/ \_\_.__/|___/\__|_| \__,_|\___|\__|_|\___/|_| |_| #
7# |_| |___/ |___/ #
8# ==================================================================================================================== #
9# Authors: #
10# Patrick Lehmann #
11# #
12# License: #
13# ==================================================================================================================== #
14# Copyright 2017-2026 Patrick Lehmann - Bötzingen, Germany #
15# Copyright 2014-2016 Technische Universität Dresden - Germany, Chair of VLSI-Design, Diagnostics and Architecture #
16# #
17# Licensed under the Apache License, Version 2.0 (the "License"); #
18# you may not use this file except in compliance with the License. #
19# You may obtain a copy of the License at #
20# #
21# http://www.apache.org/licenses/LICENSE-2.0 #
22# #
23# Unless required by applicable law or agreed to in writing, software #
24# distributed under the License is distributed on an "AS IS" BASIS, #
25# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
26# See the License for the specific language governing permissions and #
27# limitations under the License. #
28# #
29# SPDX-License-Identifier: Apache-2.0 #
30# ==================================================================================================================== #
31#
32"""
33Valued flags are arguments with a name and an always present value.
35The usual delimiter sign between name and value is an equal sign (``=``).
37.. seealso::
39 :mod:`~pyTooling.CLIAbstraction.Flag`
40 |rarr| For simple flags.
41 :mod:`~pyTooling.CLIAbstraction.BooleanFlag`
42 |rarr| For flags with a different pattern based on the boolean value itself.
43 :class:`~pyTooling.CLIAbstraction.OptionalValuedFlag.OptionalValuedFlag`
44 |rarr| For flags that have an optional value.
45 :mod:`~pyTooling.CLIAbstraction.ValuedFlagList`
46 |rarr| For a list of valued flags.
47"""
48from typing import Any
50from pyTooling.Decorators import export
51from pyTooling.MetaClasses import abstractclass
52from pyTooling.CLIAbstraction.Argument import NamedAndValuedArgument
55@export
56@abstractclass
57class ValuedFlag(NamedAndValuedArgument[str], pattern="{0}={1}"):
58 """
59 Class and base-class for all ValuedFlag classes, which represents a flag argument with value.
61 A valued flag is a flag name followed by a value. The default delimiter sign is equal (``=``). Name and value are
62 passed as one argument to the executable even if the delimiter sign is a whitespace character.
64 **Example:**
66 * ``width=100``
67 """
69 def __init_subclass__(cls, *args: Any, pattern: str = "{0}={1}", **kwargs: Any) -> None:
70 """
71 This method is called when a class is derived.
73 :param args: Any positional arguments.
74 :param pattern: Optional, this pattern is used to format an argument. |br|
75 Default: ``"{0}={1}"``.
76 :param kwargs: Any keyword argument.
77 """
78 kwargs["pattern"] = pattern
79 super().__init_subclass__(*args, **kwargs)
82@export
83@abstractclass
84class ShortValuedFlag(ValuedFlag, pattern="-{0}={1}"):
85 """
86 Represents a :py:class:`ValuedFlagArgument` with a single dash.
88 **Example:**
90 * ``-optimizer=on``
91 """
93 def __init_subclass__(cls, *args: Any, pattern: str = "-{0}={1}", **kwargs: Any) -> None:
94 """
95 This method is called when a class is derived.
97 :param args: Any positional arguments.
98 :param pattern: Optional, this pattern is used to format an argument. |br|
99 Default: ``"-{0}={1}"``.
100 :param kwargs: Any keyword argument.
101 """
102 kwargs["pattern"] = pattern
103 super().__init_subclass__(*args, **kwargs)
106@export
107@abstractclass
108class LongValuedFlag(ValuedFlag, pattern="--{0}={1}"):
109 """
110 Represents a :py:class:`ValuedFlagArgument` with a double dash.
112 **Example:**
114 * ``--optimizer=on``
115 """
117 def __init_subclass__(cls, *args: Any, pattern: str = "--{0}={1}", **kwargs: Any) -> None:
118 """
119 This method is called when a class is derived.
121 :param args: Any positional arguments.
122 :param pattern: Optional, this pattern is used to format an argument. |br|
123 Default: ``"--{0}={1}"``.
124 :param kwargs: Any keyword argument.
125 """
126 kwargs["pattern"] = pattern
127 super().__init_subclass__(*args, **kwargs)
130@export
131@abstractclass
132class WindowsValuedFlag(ValuedFlag, pattern="/{0}:{1}"):
133 """
134 Represents a :py:class:`ValuedFlagArgument` with a single slash.
136 **Example:**
138 * ``/optimizer:on``
139 """
141 # TODO: Is it possible to copy the doc-string from super?
142 def __init_subclass__(cls, *args: Any, pattern: str = "/{0}:{1}", **kwargs: Any) -> None:
143 """
144 This method is called when a class is derived.
146 :param args: Any positional arguments.
147 :param pattern: Optional, this pattern is used to format an argument. |br|
148 Default: ``"/{0}:{1}"``.
149 :param kwargs: Any keyword argument.
150 """
151 kwargs["pattern"] = pattern
152 super().__init_subclass__(*args, **kwargs)