refactor(cmdeploy): add Out class with --verbose, section timing, and coloured shell output

Move the Out output-printer class to cmdeploy/util.py so it is shared
across CLI modules.  All print/shell calls in lxc/cli.py, lxc/incus.py,
and dns.py now route through Out instead of bare print().

Key additions:
- Out.section() / Out.section_line(): coloured section headers scaled
  to the current terminal width (or $_CMDEPLOY_WIDTH for sub-processes).
- Out.shell(): merges stdout/stderr, prefixes each output line, and
  prints a red error line with the exit code on failure.
- Out.new_prefixed_out(): indented sub-printer that shares section_timings.
- 'cmdeploy -v / -vv' exposes the verbosity levels.
- shell(), collapse(), get_git_hash() and get_version_string() helpers.
- Tests for Out added to test_util.py.

Also update chatmaild MockOut fixture to match the new Out API.
This commit is contained in:
holger krekel
2026-03-30 08:06:28 +02:00
committed by j4n
parent c6d9d27a84
commit 2ba13610bf
3 changed files with 292 additions and 3 deletions

View File

@@ -85,13 +85,13 @@ def mockout():
captured_green = []
captured_plain = []
def red(self, msg):
def red(self, msg, **kw):
self.captured_red.append(msg)
def green(self, msg):
def green(self, msg, **kw):
self.captured_green.append(msg)
def __call__(self, msg):
def print(self, msg="", **kw):
self.captured_plain.append(msg)
return MockOut()