You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:53:05 UTC

[buildstream] 08/13: cli: Add artifact list subcommand

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to branch richardmaw/artifact-subcommands
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 2ca28df61a4d5b6cefa3aa15c7e8c0b2971f0448
Author: Richard Maw <ri...@codethink.co.uk>
AuthorDate: Wed Dec 12 18:44:05 2018 +0000

    cli: Add artifact list subcommand
---
 buildstream/_frontend/cli.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 09d25cc..5f7a059 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -150,6 +150,8 @@ def override_completions(cmd, cmd_param, args, incomplete):
             complete_list = complete_target(args, incomplete)
             complete_list.extend(complete_artifact(args, incomplete))
             return complete_list
+        if cmd_param.name == 'artifact_prefix':
+            return complete_artifact(args, incomplete)
 
     raise CompleteUnhandled()
 
@@ -1188,6 +1190,28 @@ def artifact_delete(app, artifacts):
             cache.cas.remove(ref, defer_prune=(i != len(artifacts)))
 
 
+#################################################################
+#                     Artifact List Command                     #
+#################################################################
+@artifact.command(name='list', short_help="List artifacts that match the prefix")
+@click.option('--null', '-z', default=False, is_flag=True,
+              help="Separate tokens with NUL bytes instead of newlines")
+@click.argument('artifact_prefix', type=click.Path(), nargs=-1)
+@click.pass_obj
+def artifact_list(app, null, artifact_prefix):
+    """List artifact refs that match the prefix"""
+
+    sentinel = '\0' if null else '\n'
+
+    with app.initialized():
+        cas = app.context.artifactcache.cas
+
+        prefixes = _classify_artifact_refs(artifact_prefix, cas)
+        print(sentinel.join(ref for ref in cas.list_refs()
+                            if any(ref.startswith(pfx) for pfx in prefixes)),
+              end=sentinel)
+
+
 ##################################################################
 #                      DEPRECATED Commands                       #
 ##################################################################