Coverage for pyTooling/CLIAbstraction/Flag.py: 100%

25 statements  

« 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""" 

33Flag arguments represent simple boolean values by being present or absent. 

34 

35.. seealso:: 

36 

37 :mod:`~pyTooling.CLIAbstraction.BooleanFlag` 

38 |rarr| For flags with a different pattern based on the boolean value itself. 

39 :mod:`~pyTooling.CLIAbstraction.ValuedFlag` 

40 |rarr| For flags with a value. 

41 :class:`~pyTooling.CLIAbstraction.OptionalValuedFlag.OptionalValuedFlag` 

42 |rarr| For flags that have an optional value. 

43""" 

44from typing import Any 

45 

46from pyTooling.Decorators import export 

47from pyTooling.MetaClasses import abstractclass 

48from pyTooling.CLIAbstraction.Argument import NamedArgument 

49 

50 

51@export 

52@abstractclass 

53class FlagArgument(NamedArgument): 

54 """ 

55 Base-class for all Flag classes, which represents a simple flag argument like ``-v`` or ``--verbose``. 

56 

57 A simple flag is a single value (absent/present or off/on) with no additional data (value). 

58 """ 

59 

60 

61@export 

62@abstractclass 

63class ShortFlag(FlagArgument, pattern="-{0}"): 

64 """ 

65 Represents a :class:`~pyTooling.CLIAbstraction.Flag.FlagArgument` argument with a single dash. 

66 

67 **Example:** 

68 

69 * ``-optimize`` 

70 """ 

71 

72 def __init_subclass__(cls, *args: Any, pattern: str = "-{0}", **kwargs: Any) -> None: 

73 """ 

74 This method is called when a class is derived. 

75 

76 :param args: Any positional arguments. 

77 :param pattern: Optional, this pattern is used to format an argument. |br| 

78 Default: ``"-{0}"``. 

79 :param kwargs: Any keyword argument. 

80 """ 

81 kwargs["pattern"] = pattern 

82 super().__init_subclass__(*args, **kwargs) 

83 

84 

85@export 

86@abstractclass 

87class LongFlag(FlagArgument, pattern="--{0}"): 

88 """ 

89 Represents a :class:`~pyTooling.CLIAbstraction.Flag.FlagArgument` argument with a double dash. 

90 

91 **Example:** 

92 

93 * ``--optimize`` 

94 """ 

95 

96 def __init_subclass__(cls, *args: Any, pattern: str = "--{0}", **kwargs: Any) -> None: 

97 """ 

98 This method is called when a class is derived. 

99 

100 :param args: Any positional arguments. 

101 :param pattern: Optional, this pattern is used to format an argument. |br| 

102 Default: ``"--{0}"``. 

103 :param kwargs: Any keyword argument. 

104 """ 

105 kwargs["pattern"] = pattern 

106 super().__init_subclass__(*args, **kwargs) 

107 

108 

109@export 

110@abstractclass 

111class WindowsFlag(FlagArgument, pattern="/{0}"): 

112 """ 

113 Represents a :class:`~pyTooling.CLIAbstraction.Flag.FlagArgument` argument with a single slash. 

114 

115 **Example:** 

116 

117 * ``/optimize`` 

118 """ 

119 

120 def __init_subclass__(cls, *args: Any, pattern: str = "/{0}", **kwargs: Any) -> None: 

121 """ 

122 This method is called when a class is derived. 

123 

124 :param args: Any positional arguments. 

125 :param pattern: Optional, this pattern is used to format an argument. |br| 

126 Default: ``"/{0}"``. 

127 :param kwargs: Any keyword argument. 

128 """ 

129 kwargs["pattern"] = pattern 

130 super().__init_subclass__(*args, **kwargs)