Returns a string describing a flag's default value. Args: flag: The name of the flag. spec: An instance of fire.inspectutils.FullArgSpec, containing type and default information about the arguments to a callable. Returns: A string to be used in constructing the help screen for
(flag, spec)
| 535 | |
| 536 | |
| 537 | def _GetArgDefault(flag, spec): |
| 538 | """Returns a string describing a flag's default value. |
| 539 | |
| 540 | Args: |
| 541 | flag: The name of the flag. |
| 542 | spec: An instance of fire.inspectutils.FullArgSpec, containing type and |
| 543 | default information about the arguments to a callable. |
| 544 | Returns: |
| 545 | A string to be used in constructing the help screen for the function, the |
| 546 | empty string if the flag does not have a default or the default is not |
| 547 | available. |
| 548 | """ |
| 549 | num_defaults = len(spec.defaults) |
| 550 | args_with_defaults = spec.args[-num_defaults:] |
| 551 | |
| 552 | for arg, default in zip(args_with_defaults, spec.defaults): |
| 553 | if arg == flag: |
| 554 | return repr(default) |
| 555 | if flag in spec.kwonlydefaults: |
| 556 | return repr(spec.kwonlydefaults[flag]) |
| 557 | return '' |
| 558 | |
| 559 | |
| 560 | def _CreateItem(name, description, indent=2): |