From 0f16d87a4ef218f59fcb9612d0b03b99150ed17f Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Fri, 26 Jul 2019 17:22:29 +0100 Subject: [PATCH 1/2] add autocompletion callback for Options Note: `Choices` take precedant over autocompletions --- click_completion/core.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/click_completion/core.py b/click_completion/core.py index d7209a5..5f44568 100644 --- a/click_completion/core.py +++ b/click_completion/core.py @@ -110,7 +110,10 @@ def get_choices(cli, prog_name, args, incomplete): break choices = [] if optctx: - choices += [c if isinstance(c, tuple) else (c, None) for c in optctx.type.complete(ctx, incomplete)] + choices += [c if isinstance(c, tuple) else(c, None) for c in optctx.type.complete(ctx, incomplete)] + if not choices and hasattr(optctx, 'autocompletion') and optctx.autocompletion is not None: + dynamic_completions = optctx.autocompletion(ctx=ctx, args=args, incomplete=incomplete) + choices += [c if isinstance(c, tuple) else (c, None) for c in dynamic_completions] else: for param in ctx.command.get_params(ctx): if (completion_configuration.complete_options or incomplete and not incomplete[:1].isalnum()) and isinstance(param, Option): From 30708e831aba29a6d665047b407576945ed4387b Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Tue, 30 Jul 2019 16:38:37 +0100 Subject: [PATCH 2/2] review fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Gaƫtan Lehmann --- click_completion/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/click_completion/core.py b/click_completion/core.py index 5f44568..5ae21cb 100644 --- a/click_completion/core.py +++ b/click_completion/core.py @@ -110,7 +110,7 @@ def get_choices(cli, prog_name, args, incomplete): break choices = [] if optctx: - choices += [c if isinstance(c, tuple) else(c, None) for c in optctx.type.complete(ctx, incomplete)] + choices += [c if isinstance(c, tuple) else (c, None) for c in optctx.type.complete(ctx, incomplete)] if not choices and hasattr(optctx, 'autocompletion') and optctx.autocompletion is not None: dynamic_completions = optctx.autocompletion(ctx=ctx, args=args, incomplete=incomplete) choices += [c if isinstance(c, tuple) else (c, None) for c in dynamic_completions]