MCPcopy Index your code
hub / github.com/google/python-fire / _Fire

Function _Fire

fire/core.py:361–619  ·  view source on GitHub ↗

Execute a Fire command on a target component using the args supplied. Arguments that come after a final isolated '--' are treated as Flags, eg for interactive mode or completion script generation. Other arguments are consumed by the execution of the Fire command, eg in the traversal of the

(component, args, parsed_flag_args, context, name=None)

Source from the content-addressed store, hash-verified

359
360
361def _Fire(component, args, parsed_flag_args, context, name=None):
362 """Execute a Fire command on a target component using the args supplied.
363
364 Arguments that come after a final isolated '--' are treated as Flags, eg for
365 interactive mode or completion script generation.
366
367 Other arguments are consumed by the execution of the Fire command, eg in the
368 traversal of the members of the component, or in calling a function or
369 instantiating a class found during the traversal.
370
371 The steps performed by this method are:
372
373 1. Parse any Flag args (the args after the final --)
374
375 2. Start with component as the current component.
376 2a. If the current component is a class, instantiate it using args from args.
377 2b. If the component is a routine, call it using args from args.
378 2c. If the component is a sequence, index into it using an arg from
379 args.
380 2d. If possible, access a member from the component using an arg from args.
381 2e. If the component is a callable object, call it using args from args.
382 2f. Repeat 2a-2e until no args remain.
383 Note: Only the first applicable rule from 2a-2e is applied in each iteration.
384 After each iteration of step 2a-2e, the current component is updated to be the
385 result of the applied rule.
386
387 3a. Embed into ipython REPL if interactive mode is selected.
388 3b. Generate a completion script if that flag is provided.
389
390 In step 2, arguments will only ever be consumed up to a separator; a single
391 step will never consume arguments from both sides of a separator.
392 The separator defaults to a hyphen (-), and can be overwritten with the
393 --separator Fire argument.
394
395 Args:
396 component: The target component for Fire.
397 args: A list of args to consume in Firing on the component, usually from
398 the command line.
399 parsed_flag_args: The values of the flag args (e.g. --verbose, --separator)
400 that are part of every Fire CLI.
401 context: A dict with the local and global variables available at the call
402 to Fire.
403 name: Optional. The name of the command. Used in interactive mode and in
404 the tab completion script.
405 Returns:
406 FireTrace of components starting with component, tracing Fire's execution
407 path as it consumes args.
408 Raises:
409 ValueError: If there are arguments that cannot be consumed.
410 ValueError: If --completion is specified but no name available.
411 """
412 verbose = parsed_flag_args.verbose
413 interactive = parsed_flag_args.interactive
414 separator = parsed_flag_args.separator
415 show_completion = parsed_flag_args.completion
416 show_help = parsed_flag_args.help
417 show_trace = parsed_flag_args.trace
418

Callers 1

FireFunction · 0.85

Calls 10

AddAccessedPropertyMethod · 0.95
AddErrorMethod · 0.95
AddSeparatorMethod · 0.95
AddCompletionScriptMethod · 0.95
AddInteractiveModeMethod · 0.95
_IsHelpShortcutFunction · 0.85
_CallAndUpdateTraceFunction · 0.85
FireErrorClass · 0.85
_GetMemberFunction · 0.85
CompletionScriptFunction · 0.85

Tested by

no test coverage detected