0

i am currently trying to get a compiled python project which is using click 8.0.4 running with shell_completion.

My project contains multiple downstream scripts, which should support the shell_completion. I am trying to compile this script and make it an executable in /usr/local/bin. Also activating it with

eval "$(_COMPLETE=source_bash main)"

however I get no output here and if i try to test the autocompletion, bash just shows the files of the current directory.

Now my question would be: is this even possible with click/shell_complete in a compiled script? I've tried already a small script where it used to work, however i've now using click.groups and multiple files/scripts and an entry-point.

main.py:

import sys
from commands import cli

def main():
    try:
        cli()
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    main()

commands/__init__.py:

import click
from .config import config
from .deployment import deployment
from .k import k
from .k9s import k9s
from .setup import setup
from .usage import usage

@click.group()
def cli():
    pass

cli.add_command(config)
cli.add_command(deployment)
cli.add_command(k)
cli.add_command(k9s)
cli.add_command(setup)
cli.add_command(usage)

def main():
    cli()

if __name__ == "__main__":
    main()

utils/autocomplete.py:

import click

def runtime_autocomplete(ctx, param, incomplete):
    values = ["TEST1", "TEST2"]
    return [click.shell_complete.CompletionItem(value) for value in values if value.startswith(incomplete)]

commands/setup.py:

from utils.autocomplete import runtime_autocomplete, interaction_autocomplete
@click.option('--runtime', "-r", type=click.Choice(["TEST1", "TEST2"]), required=True, help="Specify the runtime", shell_complete=runtime_autocomplete)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.