Coverage for pyTooling/CLIAbstraction/Command.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""" 

33This module implements command arguments. Usually, commands are mutually exclusive and the first argument in a list of 

34arguments to a program. 

35 

36While commands can or cannot have prefix characters, they shouldn't be confused with flag arguments or string arguments. 

37 

38**Example:** 

39 

40* ``prog command -arg1 --argument2`` 

41 

42.. seealso:: 

43 

44 :mod:`~pyTooling.CLIAbstraction.Flag` 

45 |rarr| For simple flags (various formats). 

46 :class:`~pyTooling.CLIAbstraction.Argument.StringArgument` 

47 |rarr| For string arguments. 

48""" 

49from typing import Any 

50 

51from pyTooling.Decorators import export 

52from pyTooling.MetaClasses import abstractclass 

53from pyTooling.CLIAbstraction.Argument import NamedArgument 

54 

55 

56# TODO: make this class abstract 

57@export 

58@abstractclass 

59class CommandArgument(NamedArgument): 

60 """ 

61 Represents a command argument. 

62 

63 It is usually used to select a sub parser in a CLI argument parser or to hand over all following parameters to a 

64 separate tool. An example for a command is 'checkout' in ``git.exe checkout``, which calls ``git-checkout.exe``. 

65 

66 **Example:** 

67 

68 * ``command`` 

69 """ 

70 

71 

72@export 

73@abstractclass 

74class ShortCommand(CommandArgument, pattern="-{0}"): 

75 """ 

76 Represents a command name with a single dash. 

77 

78 **Example:** 

79 

80 * ``-command`` 

81 """ 

82 

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

84 """ 

85 This method is called when a class is derived. 

86 

87 :param args: Any positional arguments. 

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

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

90 :param kwargs: Any keyword argument. 

91 """ 

92 kwargs["pattern"] = pattern 

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

94 

95 

96@export 

97@abstractclass 

98class LongCommand(CommandArgument, pattern="--{0}"): 

99 """ 

100 Represents a command name with a double dash. 

101 

102 **Example:** 

103 

104 * ``--command`` 

105 """ 

106 

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

108 """ 

109 This method is called when a class is derived. 

110 

111 :param args: Any positional arguments. 

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

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

114 :param kwargs: Any keyword argument. 

115 """ 

116 kwargs["pattern"] = pattern 

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

118 

119 

120@export 

121@abstractclass 

122class WindowsCommand(CommandArgument, pattern="/{0}"): 

123 """ 

124 Represents a command name with a single slash. 

125 

126 **Example:** 

127 

128 * ``/command`` 

129 """ 

130 

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

132 """ 

133 This method is called when a class is derived. 

134 

135 :param args: Any positional arguments. 

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

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

138 :param kwargs: Any keyword argument. 

139 """ 

140 kwargs["pattern"] = pattern 

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