From 577e99ae3974650a6670827eca4b16e340b13841 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Thu, 7 Nov 2024 14:46:37 -0800 Subject: [PATCH] Print CLI tags when using the print command --- comictaggerlib/cli.py | 17 +++++++++++++++-- comictaggerlib/ctsettings/commandline.py | 11 +++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py index 3cd3b6c..7344415 100644 --- a/comictaggerlib/cli.py +++ b/comictaggerlib/cli.py @@ -94,6 +94,13 @@ class CLI: def run(self) -> int: if len(self.config.Runtime_Options__files) < 1: + if self.config.Commands__command == Action.print: + res = self.print(None) + if res.status != Status.success: + return_code = 3 + if self.config.Runtime_Options__json: + print(json.dumps(dataclasses.asdict(res), cls=OutputEncoder, indent=2)) + return 0 logger.error("You must specify at least one filename. Use the -h option for more info") return 1 return_code = 0 @@ -279,7 +286,14 @@ class CLI: return (md, tags_used) - def print(self, ca: ComicArchive) -> Result: + def print(self, ca: ComicArchive | None) -> Result: + md = None + if ca is None: + if not self.config.Auto_Tag__metadata.is_empty: + if not self.config.Auto_Tag__metadata.is_empty: + self.output("--------- CLI tags ---------") + self.output(self.config.Auto_Tag__metadata) + return Result(Action.print, Status.success, None, md=md) # type: ignore if not self.config.Runtime_Options__tags_read: page_count = ca.get_number_of_pages() @@ -304,7 +318,6 @@ class CLI: self.output() - md = None for tag_id, tag in tags.items(): if not self.config.Runtime_Options__tags_read or tag_id in self.config.Runtime_Options__tags_read: if ca.has_tags(tag_id): diff --git a/comictaggerlib/ctsettings/commandline.py b/comictaggerlib/ctsettings/commandline.py index 27b4f8b..da8910b 100644 --- a/comictaggerlib/ctsettings/commandline.py +++ b/comictaggerlib/ctsettings/commandline.py @@ -287,12 +287,11 @@ def validate_commandline_settings(config: settngs.Config[ct_ns], parser: settngs if config[0].Runtime_Options__tags_read and not config[0].Runtime_Options__tags_write: config[0].Runtime_Options__tags_write = config[0].Runtime_Options__tags_read - if ( - config[0].Commands__command not in (Action.save_config, Action.list_plugins) - and config[0].Runtime_Options__no_gui - and not config[0].Runtime_Options__files - ): - parser.exit(message="Command requires at least one filename!\n", status=1) + if config[0].Runtime_Options__no_gui and not config[0].Runtime_Options__files: + if config[0].Commands__command == Action.print and not config[0].Auto_Tag__metadata.is_empty: + ... # allow printing the metadata provided on the commandline + elif config[0].Commands__command not in (Action.save_config, Action.list_plugins): + parser.exit(message="Command requires at least one filename!\n", status=1) if config[0].Commands__command == Action.delete and not config[0].Runtime_Options__tags_write: parser.exit(message="Please specify the tags to delete with --tags-write\n", status=1)