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

31 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-25 22:22 +0000

1# ==================================================================================================================== # 

2# _____ _ _ ____ _ ___ _ _ _ _ _ # 

3# _ __ _ |_ _|__ ___ | (_)_ __ __ _ / ___| | |_ _| / \ | |__ ___| |_ _ __ __ _ ___| |_(_) ___ _ __ # 

4# | '_ \| | | || |/ _ \ / _ \| | | '_ \ / _` || | | | | | / _ \ | '_ \/ __| __| '__/ _` |/ __| __| |/ _ \| '_ \ # 

5# | |_) | |_| || | (_) | (_) | | | | | | (_| || |___| |___ | | / ___ \| |_) \__ \ |_| | | (_| | (__| |_| | (_) | | | | # 

6# | .__/ \__, ||_|\___/ \___/|_|_|_| |_|\__, (_)____|_____|___/_/ \_\_.__/|___/\__|_| \__,_|\___|\__|_|\___/|_| |_| # 

7# |_| |___/ |___/ # 

8# ==================================================================================================================== # 

9# Authors: # 

10# Patrick Lehmann # 

11# # 

12# License: # 

13# ==================================================================================================================== # 

14# Copyright 2017-2025 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 tuple-flag arguments represent a name and a value as a 2-tuple. 

34 

35.. seealso:: 

36 

37 * For flags with a value. |br| 

38 |rarr| :mod:`~pyTooling.CLIAbstraction.ValuedFlag` 

39 * For flags that have an optional value. |br| 

40 |rarr| :mod:`~pyTooling.CLIAbstraction.NamedOptionalValuedFlag` 

41""" 

42from typing import Any 

43 

44try: 

45 from pyTooling.Decorators import export 

46 from pyTooling.CLIAbstraction.Argument import NamedTupledArgument 

47except (ImportError, ModuleNotFoundError): # pragma: no cover 

48 print("[pyTooling.Versioning] Could not import from 'pyTooling.*'!") 

49 

50 try: 

51 from Decorators import export 

52 from CLIAbstraction.Argument import NamedTupledArgument 

53 except (ImportError, ModuleNotFoundError) as ex: # pragma: no cover 

54 print("[pyTooling.Versioning] Could not import directly!") 

55 raise ex 

56 

57 

58@export 

59class ShortTupleFlag(NamedTupledArgument, pattern="-{0}"): 

60 """ 

61 Represents a :class:`ValuedTupleArgument` with a single dash in front of the switch name. 

62 

63 **Example:** 

64 

65 * ``-file file1.txt`` 

66 """ 

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

68 kwargs["pattern"] = pattern 

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

70 

71 def __new__(cls, *args: Any, **kwargs: Any): 

72 if cls is ShortTupleFlag: 

73 raise TypeError(f"Class '{cls.__name__}' is abstract.") 

74 return super().__new__(cls, *args, **kwargs) 

75 

76 

77@export 

78class LongTupleFlag(NamedTupledArgument, pattern="--{0}"): 

79 """ 

80 Represents a :class:`ValuedTupleArgument` with a double dash in front of the switch name. 

81 

82 **Example:** 

83 

84 * ``--file file1.txt`` 

85 """ 

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

87 kwargs["pattern"] = pattern 

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

89 

90 def __new__(cls, *args: Any, **kwargs: Any): 

91 if cls is LongTupleFlag: 

92 raise TypeError(f"Class '{cls.__name__}' is abstract.") 

93 return super().__new__(cls, *args, **kwargs) 

94 

95 

96@export 

97class WindowsTupleFlag(NamedTupledArgument, pattern="/{0}"): 

98 """ 

99 Represents a :class:`ValuedTupleArgument` with a single slash in front of the switch name. 

100 

101 **Example:** 

102 

103 * ``/file file1.txt`` 

104 """ 

105 def __init_subclass__(cls, *args: Any, pattern: str = "/{0}", **kwargs: Any): 

106 kwargs["pattern"] = pattern 

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

108 

109 def __new__(cls, *args: Any, **kwargs: Any): 

110 if cls is WindowsTupleFlag: 

111 raise TypeError(f"Class '{cls.__name__}' is abstract.") 

112 return super().__new__(cls, *args, **kwargs)