Skip to content

Commit

Permalink
cli: allow sorting using uppercase column names
Browse files Browse the repository at this point in the history
Closes #673.
  • Loading branch information
giuseppe-steduto committed Oct 20, 2023
1 parent c447697 commit 4dde3bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changes
=======

Version 0.9.2 (UNRELEASED)
--------------------------

- Fixes ``list`` command to be case-insensitive when using the ``--sort`` flag to sort the workflow runs by a specific column name.

Version 0.9.1 (2023-09-27)
--------------------------

Expand Down
16 changes: 9 additions & 7 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def workflow_execution_group(ctx):
@human_readable_or_raw_option
@click.option(
"--sort",
"sort_columm_name",
"sort_column_name",
default="CREATED",
help="Sort the output by specified column",
)
Expand Down Expand Up @@ -164,7 +164,7 @@ def workflows_list( # noqa: C901
show_all,
verbose,
human_readable_or_raw,
sort_columm_name,
sort_column_name,
page,
size,
filters,
Expand Down Expand Up @@ -269,17 +269,19 @@ def workflows_list( # noqa: C901
row.append(value)
data.append(row)

sort_column_id = 2
sort_column_name = sort_column_name.lower()
if sort_column_name in headers[type]:
sort_column_id = headers[type].index(sort_column_name)

# Sort by given column, making sure that `None` is at the bottom of the list.
def get_sort_key(x, column_id):
if sort_columm_name == "run_number":
if headers[type][column_id] == "run_number":
return list(map(int, x[column_id].split(".")))
elif sort_columm_name in workspace_size_header:
elif headers[type][column_id] in workspace_size_header:
return x[column_id]["raw"]
return x[column_id] is not None, x[column_id]

sort_column_id = 2
if sort_columm_name.lower() in headers[type]:
sort_column_id = headers[type].index(sort_columm_name.lower())
data = sorted(
data,
key=lambda x: get_sort_key(x, sort_column_id),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_deleted_workflows(cli_options: List[str], expected_status_filter: List[
"cli_options, expected_output",
[
(
["list", "-t", "000000", "--sort", "run_number"],
["list", "-t", "000000", "--sort", "Run_NUMber"],
(
"mytest 15 2018-06-13T10:55:37 - - running\n"
"mytest 2 2018-06-13T09:55:35 - - running\n"
Expand Down

0 comments on commit 4dde3bb

Please sign in to comment.