Beispiel #1
0
def RunSearch(table_path, terms, cli):
    """Runs search-help by opening and reading help table, finding commands.

  Args:
    table_path: str, the path to the help table.
    terms: [str], list of strings that must be found in the command.
    cli: the Calliope CLI object

  Returns:
    a list of json objects representing gcloud commands.
  """
    if not os.path.exists(table_path):
        with progress_tracker.ProgressTracker(
                'Updating command help index...'):
            table.Update(cli)

    with open(table_path, 'r') as table_file:
        parent = json.loads(table_file.read())

    def WalkTree(parent, found_commands):
        result = PossiblyGetResult(parent, terms)
        if result:
            found_commands.append(result)
        for child_command in parent.get(lookup.COMMANDS, {}).values():
            WalkTree(child_command, found_commands)

    found_commands = []
    WalkTree(parent, found_commands)
    return found_commands
Beispiel #2
0
def RunSearch(terms, cli):
    """Runs search-help by opening and reading help table, finding commands.

  Args:
    terms: [str], list of strings that must be found in the command.
    cli: the Calliope CLI object

  Returns:
    a list of json objects representing gcloud commands.
  """
    try:
        table_path = table.IndexPath()
    # If the help table file can't be found, load the help tree directly from
    # the passed cli.
    except table.NoSdkRootException:
        with progress_tracker.ProgressTracker('Command help index not found, '
                                              'loading gcloud commands...'):
            parent = table.GetSerializedHelpIndex(cli)
    else:
        if not os.path.exists(table_path):
            with progress_tracker.ProgressTracker(
                    'Updating command help index...'):
                table.Update(cli)

        with open(table_path, 'r') as table_file:
            parent = json.loads(table_file.read())

    searcher = Searcher(parent, terms)
    return searcher.Search()
Beispiel #3
0
  def Run(self, args):
    # Re-compile python files.
    state = local_state.InstallationState.ForCurrent()
    state.CompilePythonFiles()

    # Re-set remote completion cache.
    remote_completion.RemoteCompletion.ResetCache()

    # Re-generate static completion table.
    table.Update(self.cli)

    # Re-generate help table.
    help_table.Update(self.cli)
    def Run(self, args):
        # Re-compile python files.
        state = local_state.InstallationState.ForCurrent()
        state.CompilePythonFiles()

        # Delete the deprecated completion cache.
        resource_cache.DeleteDeprecatedCache()

        # Delete the completion cache.
        try:
            resource_cache.ResourceCache(create=False).Delete()
        except cache_exceptions.CacheNotFound:
            pass
        except cache_exceptions.Error as e:
            log.info('Unexpected resource cache error ignored: [%s].', e)

        # Re-generate static completion table.
        table.Update(self._cli_power_users_only)

        # Re-generate help table.
        help_table.Update(self._cli_power_users_only)
Beispiel #5
0
def RunSearch(terms, cli):
    """Runs search-help by opening and reading help table, finding commands.

  Args:
    terms: [str], list of strings that must be found in the command.
    cli: the Calliope CLI object

  Returns:
    a list of json objects representing gcloud commands.
  """
    try:
        table_path = table.IndexPath()
    # If the help table file can't be found, load the help tree directly from
    # the passed cli.
    except table.NoSdkRootException:
        with progress_tracker.ProgressTracker('Command help index not found, '
                                              'loading gcloud commands...'):
            parent = table.GetSerializedHelpIndex(cli)
    else:
        if not os.path.exists(table_path):
            with progress_tracker.ProgressTracker(
                    'Updating command help index...'):
                table.Update(cli)

        with open(table_path, 'r') as table_file:
            parent = json.loads(table_file.read())

    def WalkTree(parent, found_commands):
        result = PossiblyGetResult(parent, terms)
        if result:
            found_commands.append(result)
        for child_command in parent.get(lookup.COMMANDS, {}).values():
            WalkTree(child_command, found_commands)

    found_commands = []
    WalkTree(parent, found_commands)
    return found_commands