MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / _ArgumentState

Class _ArgumentState

cmd2/argparse_completer.py:96–127  ·  view source on GitHub ↗

Keeps state of an argument being parsed.

Source from the content-addressed store, hash-verified

94
95
96class _ArgumentState:
97 """Keeps state of an argument being parsed."""
98
99 def __init__(self, arg_action: argparse.Action) -> None:
100 self.action = arg_action
101 self.min: int
102 self.max: float | int
103 self.count = 0
104 self.is_remainder = self.action.nargs == argparse.REMAINDER
105
106 # Check if nargs is a range
107 nargs_range: tuple[int, int | float] | None = self.action.get_nargs_range() # type: ignore[attr-defined]
108 if nargs_range is not None:
109 self.min = nargs_range[0]
110 self.max = nargs_range[1]
111
112 # Otherwise check against argparse types
113 elif self.action.nargs is None:
114 self.min = 1
115 self.max = 1
116 elif self.action.nargs == argparse.OPTIONAL:
117 self.min = 0
118 self.max = 1
119 elif self.action.nargs in (argparse.ZERO_OR_MORE, argparse.REMAINDER):
120 self.min = 0
121 self.max = INFINITY
122 elif self.action.nargs == argparse.ONE_OR_MORE:
123 self.min = 1
124 self.max = INFINITY
125 else:
126 self.min = cast(int, self.action.nargs)
127 self.max = cast(int, self.action.nargs)
128
129
130class _UnfinishedFlagError(CompletionError):

Callers 2

completeMethod · 0.85
_handle_last_tokenMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…