-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): implement list --shared argument (#692)
Adds new `--shared`, `--shared-by`, and `--shared-with` arguments to the `list` CLI command to display workflows along with their sharing information. Closes #687
- Loading branch information
1 parent
8645594
commit b7851dc
Showing
3 changed files
with
224 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,25 @@ def workflow_sharing_group(ctx): | |
default=False, | ||
help="Include deleted workflows in the output.", | ||
) | ||
@click.option( | ||
"--shared", | ||
"shared", | ||
is_flag=True, | ||
default=False, | ||
help="List all shared (owned and unowned) workflows.", | ||
) | ||
@click.option( | ||
"--shared-by", | ||
"shared_by", | ||
default=None, | ||
help="List workflows shared by the specified user(s).", | ||
) | ||
@click.option( | ||
"--shared-with", | ||
"shared_with", | ||
default=None, | ||
help="List workflows shared with the specified user(s).", | ||
) | ||
@add_access_token_options | ||
@add_pagination_options | ||
@check_connection | ||
|
@@ -179,21 +198,42 @@ def workflows_list( # noqa: C901 | |
include_progress, | ||
include_workspace_size, | ||
show_deleted_runs: bool, | ||
shared, | ||
shared_by, | ||
shared_with, | ||
): # noqa: D301 | ||
"""List all workflows and sessions. | ||
The ``list`` command lists workflows and sessions. By default, the list of | ||
workflows is returned. If you would like to see the list of your open | ||
interactive sessions, you need to pass the ``--sessions`` command-line | ||
option. | ||
option. If you would like to see the list of all workflows, including those | ||
shared with you, you need to pass the ``--shared`` command-line option. | ||
Example:\n | ||
Along with specific user emails, you can pass the following special values | ||
to the ``--shared-by`` and ``--shared-with`` command-line options:\n | ||
\t - ``--shared-by anybody``: list workflows shared with you by anybody.\n | ||
\t - ``--shared-with anybody``: list your shared workflows exclusively.\n | ||
\t - ``--shared-with nobody``: list your unshared workflows exclusively.\n | ||
\t - ``--shared-with [email protected],[email protected]``: list workflows shared with either [email protected] or [email protected] | ||
Examples:\n | ||
\t $ reana-client list --all\n | ||
\t $ reana-client list --sessions\n | ||
\t $ reana-client list --verbose --bytes | ||
\t $ reana-client list --verbose --bytes\n | ||
\t $ reana-client list --shared\n | ||
\t $ reana-client list --shared-by [email protected]\n | ||
\t $ reana-client list --shared-with anybody | ||
""" | ||
from reana_client.api.client import get_workflows | ||
|
||
if shared_by and shared_with: | ||
display_message( | ||
"Please provide either --shared-by or --shared-with, not both.", | ||
msg_type="error", | ||
) | ||
sys.exit(1) | ||
|
||
logging.debug("command: {}".format(ctx.command_path.replace(" ", "."))) | ||
for p in ctx.params: | ||
logging.debug("{param}: {value}".format(param=p, value=ctx.params[p])) | ||
|
@@ -224,13 +264,23 @@ def workflows_list( # noqa: C901 | |
include_progress=include_progress, | ||
include_workspace_size=include_workspace_size, | ||
workflow=workflow, | ||
shared=shared, | ||
shared_by=shared_by, | ||
shared_with=shared_with, | ||
) | ||
verbose_headers = ["id", "user"] | ||
workspace_size_header = ["size"] | ||
progress_header = ["progress"] | ||
duration_header = ["duration"] | ||
headers = { | ||
"batch": ["name", "run_number", "created", "started", "ended", "status"], | ||
"batch": [ | ||
"name", | ||
"run_number", | ||
"created", | ||
"started", | ||
"ended", | ||
"status", | ||
], | ||
"interactive": [ | ||
"name", | ||
"run_number", | ||
|
@@ -249,6 +299,14 @@ def workflows_list( # noqa: C901 | |
if verbose or include_duration: | ||
headers[type] += duration_header | ||
|
||
if shared: | ||
headers[type] += ["shared_with", "shared_by"] | ||
else: | ||
if shared_with: | ||
headers[type] += ["shared_with"] | ||
if shared_by: | ||
headers[type] += ["shared_by"] | ||
|
||
data = [] | ||
for workflow in response: | ||
name, run_number = get_workflow_name_and_run_number(workflow["name"]) | ||
|
@@ -271,6 +329,10 @@ def workflows_list( # noqa: C901 | |
"run_started_at" if header == "started" else "run_finished_at" | ||
) | ||
value = workflow.get("progress", {}).get(_key) or "-" | ||
if header == "shared_by": | ||
value = workflow.get("owner_email") | ||
if header == "shared_with": | ||
value = workflow.get("shared_with") | ||
if not value: | ||
value = workflow.get(header) | ||
row.append(value) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters