#!/usr/bin/env python3 """Fi-Wi test framework CLI — maps and SSH env files resolve to this file’s directory.""" import os import sys def _consume_early_config_argv(argv: list[str]) -> list[str]: """ Apply ``-c`` / ``--config`` (INI profile or ``*.ini`` path) as ``FIWI_CONFIG``, and drop those tokens so :mod:`getopt` in :mod:`fiwi.cli` does not treat ``-c`` as unknown. """ out: list[str] = [] i = 0 while i < len(argv): a = argv[i] if a in ("-c", "--config"): if i + 1 < len(argv): os.environ["FIWI_CONFIG"] = argv[i + 1].strip() i += 2 continue out.append(a) i += 1 continue if a.startswith("--config="): os.environ["FIWI_CONFIG"] = a.partition("=")[2].strip() i += 1 continue out.append(a) i += 1 return out if len(sys.argv) > 1: sys.argv[1:] = _consume_early_config_argv(sys.argv[1:]) import fiwi.paths as _paths _paths.configure(os.path.dirname(os.path.abspath(__file__))) def _prefer_line_buffered_stdio() -> None: """Flush stdout/stderr after each newline when attached to a pipe (e.g. SSH capture).""" for stream in (sys.stdout, sys.stderr): reconf = getattr(stream, "reconfigure", None) if reconf is None: continue try: reconf(line_buffering=True) except (OSError, ValueError, AttributeError): pass _prefer_line_buffered_stdio() from fiwi.cli import main if __name__ == "__main__": raise SystemExit(main())