This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch richardmaw/wip-artifact-subcommands in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 5a68f313facba52d49639ea4ccce8275643788ca Author: Richard Maw <[email protected]> AuthorDate: Thu Nov 1 15:22:48 2018 +0000 cli: Add support for auto-completing artifact ref names --- buildstream/_frontend/cli.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py index ef0dadb..e3a88a5 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -116,6 +116,18 @@ 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) + 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 @@ -130,13 +142,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()
