summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin David <valentin.david@codethink.co.uk>2018-05-01 15:46:37 +0200
committerValentin David <valentin.david@codethink.co.uk>2018-06-07 16:57:41 +0200
commit28d22030796fc7952ddef5c9701cab9147432d2d (patch)
tree6a4e7a2b0d3756fc71fc683c0c617ea028930221
parentd64a8ee234fcef742af39e73b85cc6323f5284ab (diff)
downloadbuildstream-28d22030796fc7952ddef5c9701cab9147432d2d.tar.gz
buildstream/_frontend/cli.py: Add support for multiple element parameters to 'workspace open'
-rw-r--r--buildstream/_frontend/cli.py105
-rw-r--r--tests/completions/completions.py2
2 files changed, 82 insertions, 25 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 2b5483ec8..38bb4dc30 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -585,39 +585,94 @@ def workspace():
##################################################################
# Workspace Open Command #
##################################################################
-@workspace.command(name='open', short_help="Open a new workspace")
-@click.option('--no-checkout', default=False, is_flag=True,
- help="Do not checkout the source, only link to the given directory")
-@click.option('--force', '-f', default=False, is_flag=True,
- help="Overwrite files existing in checkout directory")
-@click.option('--track', 'track_', default=False, is_flag=True,
- help="Track and fetch new source references before checking out the workspace")
-@click.argument('element',
- type=click.Path(dir_okay=False, readable=True))
-@click.argument('directory', type=click.Path(file_okay=False))
-@click.pass_obj
-def workspace_open(app, no_checkout, force, track_, element, directory):
+def workspace_open(app, no_checkout, force, track_, elements, directory):
"""Open a workspace for manual source modification"""
with app.initialized():
- if not os.path.isabs(directory):
- directory = os.path.join(app.context.workspacedir, directory)
+ targets = app.stream.load_selection(elements)
+ for target in targets:
+ targetdir = directory
+ if not targetdir:
+ targetdir, element_ext = os.path.splitext(target.name)
+ if element_ext != '.bst':
+ targetdir.append(element_ext)
+
+ if not os.path.isabs(targetdir):
+ targetdir = os.path.join(app.context.workspacedir, targetdir)
+
+ if os.path.exists(targetdir):
+
+ if not os.path.isdir(targetdir):
+ click.echo("Checkout directory is not a directory: {}".format(targetdir), err=True)
+ sys.exit(-1)
+
+ if not (no_checkout or force) and os.listdir(targetdir):
+ click.echo("Checkout directory is not empty: {}".format(targetdir), err=True)
+ sys.exit(-1)
+
+ app.stream.workspace_open(target.name, targetdir,
+ no_checkout=no_checkout,
+ track_first=track_,
+ force=force)
+
+
+def workspace_open_options(fun):
+ options = []
+ options.append(click.option('--no-checkout', default=False, is_flag=True,
+ help="Do not checkout the source, only link to the given directory"))
+ options.append(click.option('--force', '-f', default=False, is_flag=True,
+ help="Overwrite files existing in checkout directory"))
+ options.append(click.option('--track', 'track_', default=False, is_flag=True,
+ help="Track and fetch new source references before checking out the workspace"))
+ for option in options:
+ fun = option(fun)
+ return fun
+
+
+@workspace.command(name='open', short_help="Open new workspaces")
+@workspace_open_options
+@click.option('--multiple', 'multiple', default=False, is_flag=True,
+ help="Behave has open-multiple command. Otherwise this command is the same as open-single")
+@click.argument('arguments', nargs=-1, type=click.UNPROCESSED)
+@click.pass_obj
+@click.pass_context
+def workspace_open_base(ctx, app, multiple, arguments, **kwargs):
+ if multiple:
+ new_ctx = click.Context(workspace_open_multiple, parent=ctx)
+ workspace_open_multiple.parse_args(new_ctx, list(arguments))
+ new_ctx.forward(workspace_open_multiple, **kwargs)
+ else:
+ new_ctx = click.Context(workspace_open_single, parent=ctx)
+ workspace_open_single.parse_args(new_ctx, list(arguments))
+ new_ctx.forward(workspace_open_single, **kwargs)
- if os.path.exists(directory):
- if not os.path.isdir(directory):
- click.echo("Checkout directory is not a directory: {}".format(directory), err=True)
- sys.exit(-1)
+@workspace.command(name='open-single',
+ short_help="Open a new workspace")
+@workspace_open_options
+@click.argument('element',
+ nargs=1,
+ required=True,
+ type=click.Path(dir_okay=False, readable=True))
+@click.argument('directory',
+ nargs=1,
+ required=False,
+ type=click.Path(file_okay=False))
+@click.pass_obj
+def workspace_open_single(app, no_checkout, force, track_, element, directory):
+ workspace_open(app, no_checkout, force, track_, (element,), directory)
- if not (no_checkout or force) and os.listdir(directory):
- click.echo("Checkout directory is not empty: {}".format(directory), err=True)
- sys.exit(-1)
- app.stream.workspace_open(element, directory,
- no_checkout=no_checkout,
- track_first=track_,
- force=force)
+@workspace.command(name='open-multiple', short_help="Open new workspaces")
+@workspace_open_options
+@click.argument('elements',
+ nargs=-1,
+ required=True,
+ type=click.Path(dir_okay=False, readable=True))
+@click.pass_obj
+def workspace_open_multiple(app, no_checkout, force, track_, elements):
+ workspace_open(app, no_checkout, force, track_, elements, None)
##################################################################
diff --git a/tests/completions/completions.py b/tests/completions/completions.py
index d6d0fde81..27e28c1de 100644
--- a/tests/completions/completions.py
+++ b/tests/completions/completions.py
@@ -50,6 +50,8 @@ WORKSPACE_COMMANDS = [
'close ',
'list ',
'open ',
+ 'open-multiple ',
+ 'open-single ',
'reset '
]