MCPcopy
hub / github.com/pallets/click / _Option

Class _Option

src/click/parser.py:127–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125
126
127class _Option:
128 def __init__(
129 self,
130 obj: CoreOption,
131 opts: cabc.Sequence[str],
132 dest: str | None,
133 action: str | None = None,
134 nargs: int = 1,
135 const: t.Any | None = None,
136 ):
137 self._short_opts = []
138 self._long_opts = []
139 self.prefixes: set[str] = set()
140
141 for opt in opts:
142 prefix, value = _split_opt(opt)
143 if not prefix:
144 raise ValueError(
145 _("Invalid start character for option ({option})").format(
146 option=opt
147 )
148 )
149 self.prefixes.add(prefix[0])
150 if len(prefix) == 1 and len(value) == 1:
151 self._short_opts.append(opt)
152 else:
153 self._long_opts.append(opt)
154 self.prefixes.add(prefix)
155
156 if action is None:
157 action = "store"
158
159 self.dest = dest
160 self.action = action
161 self.nargs = nargs
162 self.const = const
163 self.obj = obj
164
165 @property
166 def takes_value(self) -> bool:
167 return self.action in ("store", "append")
168
169 def process(self, value: t.Any, state: _ParsingState) -> None:
170 if self.action == "store":
171 state.opts[self.dest] = value # type: ignore
172 elif self.action == "store_const":
173 state.opts[self.dest] = self.const # type: ignore
174 elif self.action == "append":
175 state.opts.setdefault(self.dest, []).append(value) # type: ignore
176 elif self.action == "append_const":
177 state.opts.setdefault(self.dest, []).append(self.const) # type: ignore
178 elif self.action == "count":
179 state.opts[self.dest] = state.opts.get(self.dest, 0) + 1 # type: ignore
180 else:
181 raise ValueError(f"unknown action '{self.action}'")
182 state.order.append(self.obj)
183
184

Callers 1

add_optionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected