diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py index 85632959fe34e3cc3a3b52995e327676e6827ed0..ecc7a4e3007e0e6f00fd843554e82ccb472fce82 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -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()