Skip to content
Snippets Groups Projects
Commit eb23a8cc authored by richardmaw-codethink's avatar richardmaw-codethink
Browse files

cli: Add support for auto-completing artifact ref names

parent 8fc6cd22
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !920. Comments created here will be created in the context of that merge request.
......@@ -112,6 +112,18 @@ def complete_target(args, incomplete):
return complete_path("File", incomplete, base_directory=base_directory)
def complete_artifact(args, incomplete):
from .._context import Context
ctx = Context()
config = None
for i, arg in enumerate(args):
if arg in ('-c', '--config'):
config = args[i + 1]
ctx.load(config)
return [ref for ref in ctx.artifactcache.cas.list_refs() if ref.startswith(incomplete)]
def override_completions(cmd, cmd_param, args, incomplete):
"""
:param cmd_param: command definition
......@@ -126,13 +138,15 @@ def override_completions(cmd, cmd_param, args, incomplete):
# We can't easily extend click's data structures without
# modifying click itself, so just do some weak special casing
# right here and select which parameters we want to handle specially.
if isinstance(cmd_param.type, click.Path) and \
(cmd_param.name == 'elements' or
cmd_param.name == 'element' or
cmd_param.name == 'except_' or
cmd_param.opts == ['--track'] or
cmd_param.opts == ['--track-except']):
return complete_target(args, incomplete)
if isinstance(cmd_param.type, click.Path):
if (cmd_param.name == 'elements' or
cmd_param.name == 'element' or
cmd_param.name == 'except_' or
cmd_param.opts == ['--track'] or
cmd_param.opts == ['--track-except']):
return complete_target(args, incomplete)
if cmd_param.name == 'artifacts':
return complete_artifact(args, incomplete)
raise CompleteUnhandled()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment