summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2018-11-01 15:22:48 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2018-12-12 16:31:38 +0000
commit3697a61107ea484f6a119ab0275441b75292acce (patch)
tree8e4aa5dbad5a70cb0828ccb1c0975482966eed40
parentec909605039d4b96ed6cfc935907502c0c7079c1 (diff)
downloadbuildstream-3697a61107ea484f6a119ab0275441b75292acce.tar.gz
cli: Add support for auto-completing artifact ref names
-rw-r--r--buildstream/_frontend/cli.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index f2f87e721..7673a2d71 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -107,6 +107,23 @@ def complete_target(args, incomplete):
return complete_list
+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)
+
+ # element targets are valid artifact names
+ complete_list = complete_target(args, incomplete)
+ complete_list.extend(ref for ref in ctx.artifactcache.cas.list_refs() if ref.startswith(incomplete))
+
+ return complete_list
+
+
def override_completions(cmd, cmd_param, args, incomplete):
"""
:param cmd_param: command definition
@@ -121,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()