MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / suggest_similar

Function suggest_similar

cmd2/utils.py:785–804  ·  view source on GitHub ↗

Given a requested command and an iterable of possible options returns the most similar (if any is similar). :param requested_command: The command entered by the user :param options: The list of available commands to search for the most similar :param similarity_function_to_use: An optio

(
    requested_command: str, options: Iterable[str], similarity_function_to_use: Callable[[str, str], float] | None = None
)

Source from the content-addressed store, hash-verified

783
784
785def suggest_similar(
786 requested_command: str, options: Iterable[str], similarity_function_to_use: Callable[[str, str], float] | None = None
787) -> str | None:
788 """Given a requested command and an iterable of possible options returns the most similar (if any is similar).
789
790 :param requested_command: The command entered by the user
791 :param options: The list of available commands to search for the most similar
792 :param similarity_function_to_use: An optional callable to use to compare commands
793 :return: The most similar command or None if no one is similar
794 """
795 proposed_command = None
796 best_simil = MIN_SIMIL_TO_CONSIDER
797 requested_command_to_compare = requested_command.lower()
798 similarity_function_to_use = similarity_function_to_use or similarity_function
799 for each in options:
800 simil = similarity_function_to_use(each.lower(), requested_command_to_compare)
801 if best_simil < simil:
802 best_simil = simil
803 proposed_command = each
804 return proposed_command
805
806
807def get_types(func_or_method: Callable[..., Any]) -> tuple[dict[str, Any], Any]:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…