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

Method add_option

src/click/parser.py:265–288  ·  view source on GitHub ↗

Adds a new option named `dest` to the parser. The destination is not inferred (unlike with optparse) and needs to be explicitly provided. Action can be any of ``store``, ``store_const``, ``append``, ``append_const`` or ``count``. The `obj` can be used to identify t

(
        self,
        obj: CoreOption,
        opts: cabc.Sequence[str],
        dest: str | None,
        action: str | None = None,
        nargs: int = 1,
        const: t.Any | None = None,
    )

Source from the content-addressed store, hash-verified

263 self._args: list[_Argument] = []
264
265 def add_option(
266 self,
267 obj: CoreOption,
268 opts: cabc.Sequence[str],
269 dest: str | None,
270 action: str | None = None,
271 nargs: int = 1,
272 const: t.Any | None = None,
273 ) -> None:
274 """Adds a new option named `dest` to the parser. The destination
275 is not inferred (unlike with optparse) and needs to be explicitly
276 provided. Action can be any of ``store``, ``store_const``,
277 ``append``, ``append_const`` or ``count``.
278
279 The `obj` can be used to identify the option in the order list
280 that is returned from the parser.
281 """
282 opts = [_normalize_opt(opt, self.ctx) for opt in opts]
283 option = _Option(obj, opts, dest, action=action, nargs=nargs, const=const)
284 self._opt_prefixes.update(option.prefixes)
285 for opt in option._short_opts:
286 self._short_opt[opt] = option
287 for opt in option._long_opts:
288 self._long_opt[opt] = option
289
290 def add_argument(self, obj: CoreArgument, dest: str | None, nargs: int = 1) -> None:
291 """Adds a positional argument named `dest` to the parser.

Callers 2

add_to_parserMethod · 0.80
test_custom_parserFunction · 0.80

Calls 3

_normalize_optFunction · 0.85
_OptionClass · 0.85
updateMethod · 0.80

Tested by 1

test_custom_parserFunction · 0.64