summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.com>2019-01-17 13:00:00 +0100
committerJames Ennis <james.ennis@codethink.com>2019-01-22 12:32:43 +0000
commit9eefe8634a95f181593f4f4b3b18564dd0fa0693 (patch)
treea1ed5bc6f263b0015b526cfe562701367ea9ad91
parenta3fc350fdf64897ae386aa913a55318d6b048276 (diff)
downloadbuildstream-9eefe8634a95f181593f4f4b3b18564dd0fa0693.tar.gz
cli: Add artifact checkout subcommand
'artifact checkout' has slightly different behaviour from 'checkout', that is, either '--directory' or '--tar' are now required options. This is a step towards allowing checkout to take multiple args.
-rw-r--r--buildstream/_frontend/cli.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index d0a99ec74..416a8529e 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -957,6 +957,75 @@ def artifact():
"""Manipulate cached artifacts"""
+#####################################################################
+# Artifact Checkout Command #
+#####################################################################
+@artifact.command(name='checkout', short_help="Checkout contents of an artifact")
+@click.option('--force', '-f', default=False, is_flag=True,
+ help="Allow files to be overwritten")
+@click.option('--deps', '-d', default=None,
+ type=click.Choice(['run', 'build', 'none']),
+ help='The dependencies to checkout (default: run)')
+@click.option('--integrate/--no-integrate', default=None, is_flag=True,
+ help="Whether to run integration commands")
+@click.option('--hardlinks', default=False, is_flag=True,
+ help="Checkout hardlinks instead of copying if possible")
+@click.option('--tar', default=None, metavar='LOCATION',
+ type=click.Path(),
+ help="Create a tarball from the artifact contents instead "
+ "of a file tree. If LOCATION is '-', the tarball "
+ "will be dumped to the standard output.")
+@click.option('--directory', default=None,
+ type=click.Path(file_okay=False),
+ help="The directory to checkout the artifact to")
+@click.argument('element', required=False,
+ type=click.Path(readable=False))
+@click.pass_obj
+def artifact_checkout(app, force, deps, integrate, hardlinks, tar, directory, element):
+ """Checkout contents of an artifact"""
+ from ..element import Scope
+
+ if hardlinks and tar is not None:
+ click.echo("ERROR: options --hardlinks and --tar conflict", err=True)
+ sys.exit(-1)
+
+ if tar is None and directory is None:
+ click.echo("ERROR: One of --directory or --tar must be provided", err=True)
+ sys.exit(-1)
+
+ if tar is not None and directory is not None:
+ click.echo("ERROR: options --directory and --tar conflict", err=True)
+ sys.exit(-1)
+
+ if tar is not None:
+ location = tar
+ tar = True
+ else:
+ location = os.getcwd() if directory is None else directory
+ tar = False
+
+ if deps == "build":
+ scope = Scope.BUILD
+ elif deps == "none":
+ scope = Scope.NONE
+ else:
+ scope = Scope.RUN
+
+ with app.initialized():
+ if not element:
+ element = app.context.guess_element()
+ if not element:
+ raise AppError('Missing argument "ELEMENT".')
+
+ app.stream.checkout(element,
+ location=location,
+ force=force,
+ scope=scope,
+ integrate=True if integrate is None else integrate,
+ hardlinks=hardlinks,
+ tar=tar)
+
+
################################################################
# Artifact Pull Command #
################################################################