def completion(): """Output completion (to be eval'd). For bash or zsh, add the following to your .bashrc or .zshrc: eval "$(doitlive completion)" For fish, add the following to ~/.config/fish/completions/doitlive.fish: eval (doitlive completion) """ shell = env.get('SHELL', None) if env.get('SHELL', None): echo( click_completion.get_code( shell=shell.split(os.sep)[-1], prog_name='doitlive' ) ) else: echo( 'Please ensure that the {SHELL} environment ' 'variable is set.'.format(SHELL=style('SHELL', bold=True)) ) sys.exit(1)
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()
async def run(self) -> None: if click_completion is None: raise self.UsageError( 'Missing required dependency, but this is easy to fix.\n' 'Run `pip install click_completion` from your virtualenv\n' 'and try again!') self.say(click_completion.get_code(shell=self.shell()))
async def run(self) -> None: """Dump click completion script for Faust CLI.""" if click_completion is None: raise self.UsageError( "Missing required dependency, but this is easy to fix.\n" "Run `pip install click_completion` from your virtualenv\n" "and try again!") self.say(click_completion.get_code(shell=self.shell()))
def is_completion_code_installed(shell, path): if shell == "fish" or not os.path.exists(path): return False import click_completion # pylint: disable=import-error,import-outside-toplevel with open(path) as fp: return click_completion.get_code(shell=shell) in fp.read()
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()))
def setup_completion(shell, show_code): """Setup CLI completion for shell""" click.echo('Setup completion for shell {!r}'.format(shell)) if show_code: code = click_completion.get_code(shell=shell) click.echo('Installing code: \n{}'.format(code)) shell_, path = click_completion.install(shell=shell) click.secho('Installed completion in path {!r}'.format(path))
def cli( ctx: click.Context, quiet: bool = False, verbose: bool = False, completion: bool = False, ): if completion: print( click_completion.get_code(shell="fish", prog_name=__version__.__name__)) ctx.obj = ctx.params
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))
def uninstall_completion_code(shell, path): if not os.path.exists(path): return True if shell == "fish": os.remove(path) return True import click_completion # pylint: disable=import-error,import-outside-toplevel with open(path, "r+") as fp: contents = fp.read() fp.seek(0) fp.truncate() fp.write(contents.replace(click_completion.get_code(shell=shell), "")) return True
def cli(ctx, state, where=False, venv=False, rm=False, bare=False, three=False, python=False, help=False, py=False, site_packages=False, envs=False, man=False, completion=False, pypi_mirror=None, support=None, clear=False, **kwargs): # Handle this ASAP to make shell startup fast. if completion: from .. import shells try: shell = shells.detect_info()[0] except shells.ShellDetectionFailure: echo( "Fail to detect shell. Please provide the {0} environment " "variable.".format(crayons.normal("PIPENV_SHELL", bold=True)), err=True, ) ctx.abort() print(click_completion.get_code(shell=shell, prog_name="pipenv")) return 0 from ..core import ( system_which, do_py, warn_in_virtualenv, do_where, project, spinner, cleanup_virtualenv, ensure_project, format_help, do_clear, ) if man: if system_which("man"): path = os.sep.join([os.path.dirname(__file__), "pipenv.1"]) os.execle(system_which("man"), "man", path, os.environ) return 0 else: secho("man does not appear to be available on your system.", fg="yellow", bold=True, err=True) return 1 if envs: echo( "The following environment variables can be set, to do various things:\n" ) for key in environments.__dict__: if key.startswith("PIPENV"): echo(" - {0}".format(crayons.normal(key, bold=True))) echo("\nYou can learn more at:\n {0}".format( crayons.green( "http://docs.pipenv.org/advanced/#configuration-with-environment-variables" ))) return 0 warn_in_virtualenv() if ctx.invoked_subcommand is None: # --where was passed… if where: do_where(bare=True) return 0 elif py: do_py() return 0 # --support was passed… elif support: from ..help import get_pipenv_diagnostics get_pipenv_diagnostics() return 0 # --clear was passed… elif clear: do_clear() return 0 # --venv was passed… elif venv: # There is no virtualenv yet. if not project.virtualenv_exists: echo( crayons.red( "No virtualenv has been created for this project yet!" ), err=True, ) ctx.abort() else: echo(project.virtualenv_location) return 0 # --rm was passed… elif rm: # Abort if --system (or running in a virtualenv). if environments.PIPENV_USE_SYSTEM: echo( crayons.red( "You are attempting to remove a virtualenv that " "Pipenv did not create. Aborting.")) ctx.abort() if project.virtualenv_exists: loc = project.virtualenv_location echo( crayons.normal(u"{0} ({1})…".format( crayons.normal("Removing virtualenv", bold=True), crayons.green(loc), ))) with spinner(): # Remove the virtualenv. cleanup_virtualenv(bare=True) return 0 else: echo( crayons.red( "No virtualenv has been created for this project yet!", bold=True, ), err=True, ) ctx.abort() # --two / --three was passed… if (state.python or state.three is not None) or site_packages: ensure_project( three=state.three, python=state.python, warn=True, site_packages=state.site_packages, pypi_mirror=state.pypi_mirror, clear=state.clear, ) # Check this again before exiting for empty ``pipenv`` command. elif ctx.invoked_subcommand is None: # Display help to user, if no commands were passed. echo(format_help(ctx.get_help()))
def cli( ctx, where=False, venv=False, rm=False, bare=False, three=False, python=False, help=False, py=False, site_packages=False, envs=False, man=False, completion=False, ): if completion: # Handle this ASAP to make shell startup fast. from . import shells try: shell = shells.detect_info()[0] except shells.ShellDetectionFailure: echo( 'Fail to detect shell. Please provide the {0} environment ' 'variable.'.format(crayons.normal('PIPENV_SHELL', bold=True)), err=True, ) sys.exit(1) print(click_completion.get_code(shell=shell, prog_name='pipenv')) sys.exit(0) from .core import (system_which, do_py, warn_in_virtualenv, do_where, project, spinner, cleanup_virtualenv, ensure_project, format_help) if man: if system_which('man'): path = os.sep.join([os.path.dirname(__file__), 'pipenv.1']) os.execle(system_which('man'), 'man', path, os.environ) else: echo('man does not appear to be available on your system.', err=True) if envs: echo( 'The following environment variables can be set, to do various things:\n' ) for key in environments.__dict__: if key.startswith('PIPENV'): echo(' - {0}'.format(crayons.normal(key, bold=True))) echo('\nYou can learn more at:\n {0}'.format( crayons.green( 'http://docs.pipenv.org/advanced/#configuration-with-environment-variables' ))) sys.exit(0) warn_in_virtualenv() if ctx.invoked_subcommand is None: # --where was passed... if where: do_where(bare=True) sys.exit(0) elif py: do_py() sys.exit() # --venv was passed... elif venv: # There is no virtualenv yet. if not project.virtualenv_exists: echo( crayons.red( 'No virtualenv has been created for this project yet!' ), err=True, ) sys.exit(1) else: echo(project.virtualenv_location) sys.exit(0) # --rm was passed... elif rm: # Abort if --system (or running in a virtualenv). if environments.PIPENV_USE_SYSTEM: echo( crayons.red( 'You are attempting to remove a virtualenv that ' 'Pipenv did not create. Aborting.')) sys.exit(1) if project.virtualenv_exists: loc = project.virtualenv_location echo( crayons.normal(u'{0} ({1})…'.format( crayons.normal('Removing virtualenv', bold=True), crayons.green(loc), ))) with spinner(): # Remove the virtualenv. cleanup_virtualenv(bare=True) sys.exit(0) else: echo( crayons.red( 'No virtualenv has been created for this project yet!', bold=True, ), err=True, ) sys.exit(1) # --two / --three was passed... if (python or three is not None) or site_packages: ensure_project(three=three, python=python, warn=True, site_packages=site_packages) # Check this again before exiting for empty ``pipenv`` command. elif ctx.invoked_subcommand is None: # Display help to user, if no commands were passed. echo(format_help(ctx.get_help()))
def show(shell, case_insensitive): """Show the click-completion-command completion code""" extra_env = {'_CLICK_COMPLETION_COMMAND_CASE_INSENSITIVE_COMPLETE': 'ON'} if case_insensitive else {} click.echo(click_completion.get_code(shell, extra_env=extra_env))
def cli(ctx, where=False, venv=False, rm=False, bare=False, three=False, python=False, help=False, update=False, py=False, site_packages=False, envs=False, man=False, completion=False): if completion: # Handle this ASAP to make shell startup fast. if PIPENV_SHELL: click.echo( click_completion.get_code(shell=PIPENV_SHELL.split(os.sep)[-1], prog_name='pipenv')) else: click.echo('Please ensure that the {0} environment variable ' 'is set.'.format(crayons.normal('SHELL', bold=True)), err=True) sys.exit(1) sys.exit(0) from . import core if not update: if core.need_update_check(): # Spun off in background thread, not unlike magic. core.check_for_updates() else: # Update pip to latest version. core.ensure_latest_pip() # Upgrade self to latest version. core.ensure_latest_self() sys.exit() if man: if core.system_which('man'): path = os.sep.join([os.path.dirname(__file__), 'pipenv.1']) os.execle(core.system_which('man'), 'man', path, os.environ) else: click.echo('man does not appear to be available on your system.', err=True) if envs: click.echo( 'The following environment variables can be set, to do various things:\n' ) for key in environments.__dict__: if key.startswith('PIPENV'): click.echo(' - {0}'.format(crayons.normal(key, bold=True))) click.echo('\nYou can learn more at:\n {0}'.format( crayons.green( 'http://docs.pipenv.org/advanced/#configuration-with-environment-variables' ))) sys.exit(0) core.warn_in_virtualenv() if ctx.invoked_subcommand is None: # --where was passed... if where: core.do_where(bare=True) sys.exit(0) elif py: core.do_py() sys.exit() # --venv was passed... elif venv: # There is no virtualenv yet. if not core.project.virtualenv_exists: click.echo(crayons.red( 'No virtualenv has been created for this project yet!'), err=True) sys.exit(1) else: click.echo(core.project.virtualenv_location) sys.exit(0) # --rm was passed... elif rm: # Abort if --system (or running in a virtualenv). if PIPENV_USE_SYSTEM: click.echo( crayons.red( 'You are attempting to remove a virtualenv that ' 'Pipenv did not create. Aborting.')) sys.exit(1) if core.project.virtualenv_exists: loc = core.project.virtualenv_location click.echo( crayons.normal(u'{0} ({1})…'.format( crayons.normal('Removing virtualenv', bold=True), crayons.green(loc)))) with core.spinner(): # Remove the virtualenv. core.cleanup_virtualenv(bare=True) sys.exit(0) else: click.echo(crayons.red( 'No virtualenv has been created for this project yet!', bold=True), err=True) sys.exit(1) # --two / --three was passed... if (python or three is not None) or site_packages: core.ensure_project(three=three, python=python, warn=True, site_packages=site_packages) # Check this again before exiting for empty ``pipenv`` command. elif ctx.invoked_subcommand is None: # Display help to user, if no commands were passed. click.echo(core.format_help(ctx.get_help()))
def show(shell): """Show the completion code""" extra_env = {CASE_INSENSITIVE_ENV: 'ON'} if config.completion.case_insensitive else {} click.echo(click_completion.get_code(shell, extra_env=extra_env))
def autocomplete_install(shell): click.echo(click_completion.get_code(shell))
def cli( ctx, where=False, venv=False, rm=False, bare=False, three=False, python=False, help=False, py=False, site_packages=False, envs=False, man=False, completion=False, pypi_mirror=None, support=None, clear=False, ): # Handle this ASAP to make shell startup fast. if completion: from . import shells try: shell = shells.detect_info()[0] except shells.ShellDetectionFailure: echo( "Fail to detect shell. Please provide the {0} environment " "variable.".format(crayons.normal("PIPENV_SHELL", bold=True)), err=True, ) sys.exit(1) print(click_completion.get_code(shell=shell, prog_name="pipenv")) sys.exit(0) from .core import ( system_which, do_py, warn_in_virtualenv, do_where, project, spinner, cleanup_virtualenv, ensure_project, format_help, do_clear, ) if man: if system_which("man"): path = os.sep.join([os.path.dirname(__file__), "pipenv.1"]) os.execle(system_which("man"), "man", path, os.environ) else: echo("man does not appear to be available on your system.", err=True) if envs: echo("The following environment variables can be set, to do various things:\n") for key in environments.__dict__: if key.startswith("PIPENV"): echo(" - {0}".format(crayons.normal(key, bold=True))) echo( "\nYou can learn more at:\n {0}".format( crayons.green( "http://docs.pipenv.org/advanced/#configuration-with-environment-variables" ) ) ) sys.exit(0) warn_in_virtualenv() if ctx.invoked_subcommand is None: # --where was passed… if where: do_where(bare=True) sys.exit(0) elif py: do_py() sys.exit() # --support was passed… elif support: from .help import get_pipenv_diagnostics get_pipenv_diagnostics() sys.exit(0) # --clear was passed… elif clear: do_clear() sys.exit(0) # --venv was passed… elif venv: # There is no virtualenv yet. if not project.virtualenv_exists: echo( crayons.red("No virtualenv has been created for this project yet!"), err=True, ) sys.exit(1) else: echo(project.virtualenv_location) sys.exit(0) # --rm was passed… elif rm: # Abort if --system (or running in a virtualenv). if environments.PIPENV_USE_SYSTEM: echo( crayons.red( "You are attempting to remove a virtualenv that " "Pipenv did not create. Aborting." ) ) sys.exit(1) if project.virtualenv_exists: loc = project.virtualenv_location echo( crayons.normal( u"{0} ({1})…".format( crayons.normal("Removing virtualenv", bold=True), crayons.green(loc), ) ) ) with spinner(): # Remove the virtualenv. cleanup_virtualenv(bare=True) sys.exit(0) else: echo( crayons.red( "No virtualenv has been created for this project yet!", bold=True, ), err=True, ) sys.exit(1) # --two / --three was passed… if (python or three is not None) or site_packages: ensure_project( three=three, python=python, warn=True, site_packages=site_packages, pypi_mirror=pypi_mirror, clear=clear, ) # Check this again before exiting for empty ``pipenv`` command. elif ctx.invoked_subcommand is None: # Display help to user, if no commands were passed. echo(format_help(ctx.get_help()))
async def run(self) -> None: self.say(click_completion.get_code(shell=self.shell()))