Exemplo n.º 1
0
 def callback(ctx, attr, value):
     if not value or ctx.resilient_parsing:
         return
     shell = click_completion.get_auto_shell()
     content = click_completion.get_code(shell=shell, prog_name="mohand")
     echo(content)
     ctx.exit()
Exemplo n.º 2
0
    def callback(ctx, attr, value):
        if not value or ctx.resilient_parsing:
            return value

        prog_name = click.get_current_context().find_root().info_name
        shell = click_completion.get_auto_shell()
        mode = path = None

        if shell == 'fish':
            path = path or os.path.expanduser(
                '~') + '/.config/fish/completions/%s.fish' % prog_name
            mode = mode or 'w'
            content = 'eval (mohand --completion)'
        elif shell == 'bash':
            path = path or os.path.expanduser('~') + '/.bash_completion'
            mode = mode or 'a'
            content = 'eval "$(mohand --completion)"'
        elif shell == 'zsh':
            path = path or os.path.expanduser('~') + '/.zshrc'
            mode = mode or 'a'
            content = 'eval "$(mohand --completion)"'
        else:
            raise ClickException('%s is not supported.' % shell)

        d = os.path.dirname(path)
        if not os.path.exists(d):
            os.makedirs(d)
        f = open(path, mode)
        f.write(content)
        f.write("\n")
        f.close()

        echo('{shell} 补全插件安装完成: {path}'.format(shell=shell, path=path))
        exit(0)
Exemplo n.º 3
0
def setup_autocomplete():
    """
    Enables autocompletion of Breeze2 commands.
    Functionality: By default the generated shell scripts will be available in ./dev/breeze/autocomplete/ path
    Depending on the shell type in the machine we have to link it to the corresponding file
    """
    global NAME
    breeze_comment = "Added by Updated Airflow Breeze autocomplete setup"
    # Determine if the shell is bash/zsh/powershell. It helps to build the autocomplete path
    shell = get_auto_shell()
    click.echo(f"Installing {shell} completion for local user")
    extra_env = {'_CLICK_COMPLETION_COMMAND_CASE_INSENSITIVE_COMPLETE': 'ON'}
    autocomplete_path = Path(
        AIRFLOW_SOURCES_DIR
    ) / ".build/autocomplete" / f"{NAME}-complete.{shell}"
    shell, path = click_completion.core.install(shell=shell,
                                                prog_name=NAME,
                                                path=autocomplete_path,
                                                append=False,
                                                extra_env=extra_env)
    click.echo(
        f"Activation command scripts are created in this autocompletion path: {autocomplete_path}"
    )
    if click.confirm(
            f"Do you want to add the above autocompletion scripts to your {shell} profile?"
    ):
        if shell == 'bash':
            script_path = Path('~').expanduser() / '/.bash_completion'
            command_to_execute = f"source {autocomplete_path}"
            write_to_shell(command_to_execute, script_path, breeze_comment)
        elif shell == 'zsh':
            script_path = Path('~').expanduser() / '/.zshrc'
            command_to_execute = f"source {autocomplete_path}"
            write_to_shell(command_to_execute, script_path, breeze_comment)
        elif shell == 'fish':
            # Include steps for fish shell
            script_path = Path(
                '~').expanduser() / f'/.config/fish/completions/{NAME}.fish'
            with open(path) as source_file, open(script_path,
                                                 'w') as destination_file:
                for line in source_file:
                    destination_file.write(line)
        else:
            # Include steps for powershell
            subprocess.check_call([
                'powershell',
                'Set-ExecutionPolicy Unrestricted -Scope CurrentUser'
            ])
            script_path = subprocess.check_output(
                ['powershell', '-NoProfile', 'echo $profile']).strip()
            command_to_execute = f". {autocomplete_path}"
            write_to_shell(command_to_execute, script_path.decode("utf-8"),
                           breeze_comment)
    else:
        click.echo(
            f"Link for manually adding the autocompletion script to {shell} profile"
        )
Exemplo n.º 4
0
def verdi_completioncommand():
    """Return the code to activate bash completion.

    \b
    This command is mainly for back-compatibility.
    You should rather use: eval "$(_VERDI_COMPLETE=source verdi)"
    """
    from click_completion import get_auto_shell, get_code
    click.echo(get_code(shell=get_auto_shell()))
Exemplo n.º 5
0
def completion_uninstall(shell, path):

    import click_completion  # pylint: disable=import-outside-toplevel,import-error

    shell = shell or click_completion.get_auto_shell()
    path = path or get_completion_install_path(shell)
    uninstall_completion_code(shell, path)
    click.echo(
        "PlatformIO CLI completion has been uninstalled for %s shell from %s \n"
        "Please restart a current shell session." %
        (click.style(shell, fg="cyan"), click.style(path, fg="blue")))
Exemplo n.º 6
0
def shell(shell, install):
    '''Installs or prints shell code for completions.'''
    try:
        if not shell:
            shell = click_completion.get_auto_shell(),
    except click.exceptions.UsageError as e:
        print(e.message)

    if install:
        click_completion.install(shell)
    else:
        click.echo(click_completion.get_code(shell))