From bfa69f1bc2d077b9a40a926e1aff1f9af8cf2982 Mon Sep 17 00:00:00 2001 From: speriaswamy-amd Date: Fri, 14 Aug 2026 16:13:19 -0400 Subject: [PATCH] refactor(cli_plugins): hoist _emit_error onto SubcommandPlugin exec_plugin.py had its own _emit_error (print to stderr in JSON mode so stdout stays valid JSON, else stdout). A second plugin needing the same behavior is coming next in this stack; move it onto the shared base rather than paste a second copy. AIMVT-276. --- cvs/cli_plugins/base.py | 7 +++++++ cvs/cli_plugins/exec_plugin.py | 4 ---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cvs/cli_plugins/base.py b/cvs/cli_plugins/base.py index fafe1ad17..7bd32f01c 100644 --- a/cvs/cli_plugins/base.py +++ b/cvs/cli_plugins/base.py @@ -1,3 +1,6 @@ +import sys + + class SubcommandPlugin: """Base class for CLI subcommand plugins.""" @@ -6,6 +9,10 @@ class SubcommandPlugin: "exec": 1000, # High number to ensure exec appears last } + def _emit_error(self, msg, json_mode): + """Print an error message. In JSON mode, writes to stderr so stdout stays valid JSON.""" + print(msg, file=sys.stderr if json_mode else sys.stdout) + def get_name(self): raise NotImplementedError diff --git a/cvs/cli_plugins/exec_plugin.py b/cvs/cli_plugins/exec_plugin.py index b1ac79fcb..226aeb133 100644 --- a/cvs/cli_plugins/exec_plugin.py +++ b/cvs/cli_plugins/exec_plugin.py @@ -160,10 +160,6 @@ def _run_on_hosts( return True, output - def _emit_error(self, msg, json_mode): - """Print an error message. In JSON mode, writes to stderr so stdout stays valid JSON.""" - print(msg, file=sys.stderr if json_mode else sys.stdout) - def _print_text_output(self, label, host_output): """Print host results in human-readable format.""" for host, out in host_output.items():