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

Method parse_args

src/click/core.py:1303–1337  ·  view source on GitHub ↗
(self, ctx: Context, args: list[str])

Source from the content-addressed store, hash-verified

1301 return ctx
1302
1303 def parse_args(self, ctx: Context, args: list[str]) -> list[str]:
1304 if not args and self.no_args_is_help and not ctx.resilient_parsing:
1305 raise NoArgsIsHelpError(ctx)
1306
1307 parser = self.make_parser(ctx)
1308 opts, args, param_order = parser.parse_args(args=args)
1309
1310 for param in iter_params_for_processing(param_order, self.get_params(ctx)):
1311 _, args = param.handle_parse_result(ctx, opts, args)
1312
1313 # We now have all parameters' values into `ctx.params`, but the data may contain
1314 # the `UNSET` sentinel.
1315 # Convert `UNSET` to `None` to ensure that the user doesn't see `UNSET`.
1316 #
1317 # Waiting until after the initial parse to convert allows us to treat `UNSET`
1318 # more like a missing value when multiple params use the same name.
1319 # Refs:
1320 # https://github.com/pallets/click/issues/3071
1321 # https://github.com/pallets/click/pull/3079
1322 for name, value in ctx.params.items():
1323 if value is UNSET:
1324 ctx.params[name] = None
1325
1326 if args and not ctx.allow_extra_args and not ctx.resilient_parsing:
1327 ctx.fail(
1328 ngettext(
1329 "Got unexpected extra argument ({args})",
1330 "Got unexpected extra arguments ({args})",
1331 len(args),
1332 ).format(args=" ".join(map(str, args)))
1333 )
1334
1335 ctx.args = args
1336 ctx._opt_prefixes.update(parser._opt_prefixes)
1337 return args
1338
1339 def invoke(self, ctx: Context) -> t.Any:
1340 """Given a context, this invokes the attached callback (if it exists)

Callers 1

make_contextMethod · 0.95

Calls 8

make_parserMethod · 0.95
get_paramsMethod · 0.95
NoArgsIsHelpErrorClass · 0.85
handle_parse_resultMethod · 0.80
updateMethod · 0.80
parse_argsMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected