MCPcopy Index your code
hub / github.com/idank/explainshell / _visitword

Method _visitword

explainshell/matcher.py:562–744  ·  view source on GitHub ↗
(node, word)

Source from the content-addressed store, hash-verified

560 return m
561
562 def _visitword(node, word):
563 if not self.man_page:
564 logger.info("inside an unknown command, giving up on %r", word)
565 self.matches.append(self.unknown(word, node.pos[0], node.pos[1]))
566 return
567
568 logger.info("trying to match token: %r", word)
569
570 self._prev_option = self._current_option
571 if word.startswith("--"):
572 word = word.split("=", 1)[0]
573 option = self.find_option(word)
574 if option:
575 logger.info("found an exact match for %r: %r", word, option)
576 mr = MatchResult(
577 node.pos[0], node.pos[1], option.text, None, _option_debug(option)
578 )
579 self.matches.append(mr)
580
581 # check if we splitted the word just above, if we did then reset
582 # the current option so the next word doesn't consider itself
583 # an argument
584 if word != node.word:
585 self._current_option = None
586 else:
587 word = node.word
588
589 # check if we're inside a nested command and this word marks the end
590 if (
591 isinstance(self.group_stack[-1][-1], list)
592 and word in self.group_stack[-1][-1]
593 ):
594 logger.info("token %r ends current nested command", word)
595 self.endcommand()
596 mr = MatchResult(
597 node.pos[0],
598 node.pos[1],
599 self.matches[-1].text,
600 None,
601 {"kind": "nested_end"},
602 )
603 self.matches.append(mr)
604 elif (
605 word != "-"
606 and word.startswith("-")
607 and not word.startswith("--")
608 # A quoted word (e.g. '-7 days') is an argument, not a
609 # flag cluster. bashlex strips quotes from node.word
610 # but keeps them in the position span, so a span longer
611 # than the word means it was quoted.
612 and node.pos[1] - node.pos[0] == len(word)
613 ):
614 logger.debug("looks like a short option")
615 if len(word) > 2:
616 logger.info("trying to split it up")
617 self.matches.extend(attemptfuzzy(word))
618 else:
619 self.matches.append(

Callers

nothing calls this directly

Calls 6

unknownMethod · 0.95
find_optionMethod · 0.95
endcommandMethod · 0.95
startcommandMethod · 0.95
MatchResultClass · 0.85
_option_debugFunction · 0.85

Tested by

no test coverage detected