# Path: awsshell/fuzzy.py
# def fuzzy_search(user_input, corpus):
#     candidates = []
#     for word in corpus:
#         current_score = calculate_score(user_input, word)
#         if current_score > 0:
#             candidates.append((word, current_score))
#     return [c[0] for c in sorted(candidates, key=lambda x: x[1], reverse=True)]
# 
# Path: awsshell/substring.py
# def substring_search(word, collection):
#     """Find all matches in the `collection` for the specified `word`.
# 
#     If `word` is empty, returns all items in `collection`.
# 
#     :type word: str
#     :param word: The substring to search for.
# 
#     :type collection: collection, usually a list
#     :param collection: A collection of words to match.
# 
#     :rtype: list of strings
#     :return: A sorted list of matching words from collection.
#     """
#     return [item for item in sorted(collection) if item.startswith(word)]


from awsshell.fuzzy import fuzzy_search
from awsshell.substring import substring_search
            # current context and traverse into the subcommand.
            # "ec2 "
            #      ^--here, need to traverse into "ec2"
            #
            # Otherwise:
            # "ec2 --no-validate-ssl "
            #                        ^-- here, stay on "ec2" context.
            if not last_word.startswith('-'):
                next_command = self._current['children'].get(last_word)
                if next_command is not None:
                    self._current = next_command
                    self._current_name = last_word
                    self.cmd_path.append(self._current_name)
            elif last_word in self.arg_metadata and \
                    self.arg_metadata[last_word]['example']:
                # Then this is an arg with a shorthand example so we'll
                # suggest that example.
                return [self.arg_metadata[last_word]['example']]
            # Even if we don't change context, we still want to
            # autocomplete all the commands for the current context
            # in either of the above two cases.
            return self._current['commands'][:]
        elif last_word.startswith('-'):
            # TODO: cache this for the duration of the current context.
            # We don't need to recompute this until the args are
            # different.
            all_args = self._get_all_args()
            if self.match_fuzzy:
                return fuzzy_search(last_word, all_args)
            else:

# Path: awsshell/fuzzy.py
# def fuzzy_search(user_input, corpus):
#     candidates = []
#     for word in corpus:
#         current_score = calculate_score(user_input, word)
#         if current_score > 0:
#             candidates.append((word, current_score))
#     return [c[0] for c in sorted(candidates, key=lambda x: x[1], reverse=True)]
# 
# Path: awsshell/substring.py
# def substring_search(word, collection):
#     """Find all matches in the `collection` for the specified `word`.
# 
#     If `word` is empty, returns all items in `collection`.
# 
#     :type word: str
#     :param word: The substring to search for.
# 
#     :type collection: collection, usually a list
#     :param collection: A collection of words to match.
# 
#     :rtype: list of strings
#     :return: A sorted list of matching words from collection.
#     """
#     return [item for item in sorted(collection) if item.startswith(word)]


# Path: awsshell/autocomplete.py
from awsshell.fuzzy import fuzzy_search
from awsshell.substring import substring_search

            # current context and traverse into the subcommand.
            # "ec2 "
            #      ^--here, need to traverse into "ec2"
            #
            # Otherwise:
            # "ec2 --no-validate-ssl "
            #                        ^-- here, stay on "ec2" context.
            if not last_word.startswith('-'):
                next_command = self._current['children'].get(last_word)
                if next_command is not None:
                    self._current = next_command
                    self._current_name = last_word
                    self.cmd_path.append(self._current_name)
            elif last_word in self.arg_metadata and \
                    self.arg_metadata[last_word]['example']:
                # Then this is an arg with a shorthand example so we'll
                # suggest that example.
                return [self.arg_metadata[last_word]['example']]
            # Even if we don't change context, we still want to
            # autocomplete all the commands for the current context
            # in either of the above two cases.
            return self._current['commands'][:]
        elif last_word.startswith('-'):
            # TODO: cache this for the duration of the current context.
            # We don't need to recompute this until the args are
            # different.
            all_args = self._get_all_args()
            if self.match_fuzzy:
                return fuzzy_search(last_word, all_args)
            else:

                return substring_search(last_word, all_args)