From 8b2ae35faea003391583b2328b3a524d0ecb7b84 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Mon, 15 Sep 2025 11:54:22 +0100 Subject: [PATCH 1/2] Fix for problem described in https://www.mobileread.com/forums/showthread.php?t=369898, can't sort by custom columns --- src/calibre/db/cli/cmd_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/db/cli/cmd_list.py b/src/calibre/db/cli/cmd_list.py index ebe16113fc..d28b1dae24 100644 --- a/src/calibre/db/cli/cmd_list.py +++ b/src/calibre/db/cli/cmd_list.py @@ -55,7 +55,7 @@ def implementation( for sf in sort_fields: if sf not in afields: return f'Unknown sort field: {sf}' - sort_spec = [(sf, ascending) for sf in sort_fields] + sort_spec = [((sf if not sf.startswith('*') else '#'+sf[1:]), ascending) for sf in sort_fields] if not set(fields).issubset(afields): return 'Unknown fields: {}'.format(', '.join(set(fields) - afields)) if search_text: From b47670d4f8ef9641d97ec8b40acb6827bb6a2590 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Mon, 15 Sep 2025 12:05:08 +0100 Subject: [PATCH 2/2] Fix the help text for --sort-by --- src/calibre/db/cli/cmd_list.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/calibre/db/cli/cmd_list.py b/src/calibre/db/cli/cmd_list.py index d28b1dae24..0b9395d635 100644 --- a/src/calibre/db/cli/cmd_list.py +++ b/src/calibre/db/cli/cmd_list.py @@ -284,7 +284,11 @@ List the books available in the calibre database. '--sort-by', default=None, help=_( - 'The field by which to sort the results. You can specify multiple fields by separating them with commas.\nAvailable fields: {0}\nDefault: {1}' + 'The field by which to sort the results. You can specify multiple fields by' + ' separating them with commas.\nAvailable fields: {0}\nDefault: {1}.' + ' In addition to the builtin fields above, custom fields are' + ' also available as *field_name, for example, for a custom field' + ' #rating, use the name: *rating' ).format(', '.join(sorted(FIELDS)), 'id') ) parser.add_option(