MCPcopy
hub / github.com/google/python-fire / _IsHelpShortcut

Function _IsHelpShortcut

fire/core.py:206–236  ·  view source on GitHub ↗

Determines if the user is trying to access help without '--' separator. For example, mycmd.py --help instead of mycmd.py -- --help. Args: component_trace: (FireTrace) The trace for the Fire command. remaining_args: List of remaining args that haven't been consumed yet. Returns: T

(component_trace, remaining_args)

Source from the content-addressed store, hash-verified

204
205
206def _IsHelpShortcut(component_trace, remaining_args):
207 """Determines if the user is trying to access help without '--' separator.
208
209 For example, mycmd.py --help instead of mycmd.py -- --help.
210
211 Args:
212 component_trace: (FireTrace) The trace for the Fire command.
213 remaining_args: List of remaining args that haven't been consumed yet.
214 Returns:
215 True if help is requested, False otherwise.
216 """
217 show_help = False
218 if remaining_args:
219 target = remaining_args[0]
220 if target in ('-h', '--help'):
221 # Check if --help would be consumed as a keyword argument, or is a member.
222 component = component_trace.GetResult()
223 if inspect.isclass(component) or inspect.isroutine(component):
224 fn_spec = inspectutils.GetFullArgSpec(component)
225 _, remaining_kwargs, _ = _ParseKeywordArgs(remaining_args, fn_spec)
226 show_help = target in remaining_kwargs
227 else:
228 members = dict(inspect.getmembers(component))
229 show_help = target not in members
230
231 if show_help:
232 component_trace.show_help = True
233 command = f'{component_trace.GetCommand()} -- --help'
234 print(f'INFO: Showing help with the command {shlex.quote(command)}.\n',
235 file=sys.stderr)
236 return show_help
237
238
239def _PrintResult(component_trace, verbose=False, serialize=None):

Callers 1

_FireFunction · 0.85

Calls 3

_ParseKeywordArgsFunction · 0.85
GetResultMethod · 0.80
GetCommandMethod · 0.80

Tested by

no test coverage detected