예제 #1
0
    def _get_dest_editors(self, target_arg=None):
        """
        Inspects the target/destination of the command argument to determine which VSCode-like
        editor(s) are the intended target for which to check for outdated extensions.

        This function uses fuzzy matching with a pre-determined threshold to find matching code
        editor names that match enough to be considered the intended target editor destinations.
        The purpose of this is to allow a small amount of leeway in what target names the user
        provides and how the program interprets them.

        For instance, with a fuzzy-matching threshold of 85% (the default), a user could provide
        an intended target of 'code', 'vscode', 'vs.code', or 'vs-code', and each of those values
        would resolve to the base Visual Studio Code editor.

        In the event that the target editor is not able to be resolved to the name of a known,
        supported code editor, then no value is added to the set of resolved targets.

        Keyword Arguments:
            target_arg {list} -- A list of strings to compare against the names
            of known, supported code editors. (default: [])

        Returns:
            set -- A unique set of matching code editor names.
        """
        targets = set()
        target_arg = target_arg or []
        for target in target_arg:
            # find the single best match from the list of known, supported
            # code editors (that matches above the specified threshold)
            try:
                match, _ = process.extractOne(
                    query=target,
                    choices=_AVAILABLE_EDITOR_VALUES,
                    score_cutoff=_FUZZY_SORT_CONFIDENCE_THRESHOLD)

                # We don't want the value in this instance, we want the key,
                # so find the key that's associated with the value match.
                match = list(SupportedEditorCommands.keys())[
                    list(SupportedEditorCommands.values()).index(match)]

            # If we couldn't find a match using the editor values themselves,
            # we'll check for a fuzzy match using the supported editor keys
            except TypeError:
                try:
                    match, _ = process.extractOne(
                        query=target,
                        choices=_AVAILABLE_EDITOR_KEYS,
                        score_cutoff=_FUZZY_SORT_CONFIDENCE_THRESHOLD)

                # If we still couldn't find a match, then we'll just move
                # on to the next item in the list of targets.
                except TypeError:
                    continue

            # Add the match to the running set of matched targets
            targets.add(match)
        return targets
예제 #2
0
    def run(self, *args, **kwargs) -> None:
        # Update the logger to apply the log-level from the main options
        self.apply_log_level(_LOGGER)

        # build a parser that's specific to the 'list' command and parse
        # the 'list' command arguments.
        parser = self.get_command_parser()
        args, _ = parser.parse_known_args()
        args.target = [Command.main_options.target]

        # Remove the leading "list" command from the arguments
        args.extensions = args.extensions[1:]

        # get a handle to the current system editors
        self.system_editors = get_editors(Command.tunnel)

        # Determine the target editors and validate that they're installed
        if args.all:
            target_editors = set(list(SupportedEditorCommands.keys()))
        else:
            target_editors = self._get_target_editors(args.target)
        valid_editors = self._validate_target_editors(target_editors)

        for editor in valid_editors:
            self._print_extensions_for_editor(editor)
예제 #3
0
import configargparse
from fuzzywuzzy import process

from rich.console import Console
from rich.table import Table
from rich import box

from pyvem._command import Command
from pyvem._config import _PROG, rich_theme
from pyvem._help import Help
from pyvem._editor import SupportedEditorCommands, get_editors
from pyvem._logging import get_rich_logger


_FUZZY_SORT_CONFIDENCE_THRESHOLD = 85
_AVAILABLE_EDITOR_KEYS = SupportedEditorCommands.keys()
_AVAILABLE_EDITOR_VALUES = SupportedEditorCommands.values()

_console = Console(theme=rich_theme)
_LOGGER = get_rich_logger(__name__, console=_console)

_HELP = Help(
    name='outdated',
    brief='Show extensions that can be updated',
    synopsis=f'{_PROG} outdated\n'
             f'{_PROG} outdated [[<extension> ...]]\n'
             f'{_PROG} outdated [[<extension> ...]] [[--<editor>]]\n'
             f'{_PROG} outdated [[--<editor>]]\n'
             f'{_PROG} outdated [[--editors]]\n'
             f'{_PROG} outdated [[--all-editors]]\n\n'
             f'[h2]aliases:[/h2] {_PROG} dated, {_PROG} old\n',