diff --git a/out.gif b/out.gif new file mode 100644 index 0000000..e4f0a60 Binary files /dev/null and b/out.gif differ diff --git a/src/guajillo/utils/cli.py b/src/guajillo/utils/cli.py index cf8cf4c..3e360ff 100644 --- a/src/guajillo/utils/cli.py +++ b/src/guajillo/utils/cli.py @@ -38,16 +38,14 @@ def build_args(self, args: list["str"]) -> None: "-o", "--out", dest="output", + choices=["json", "yaml", "boolean"], help="Output method will auto detect if possable, use this to force or set to json for json output", ) - self.parser.add_argument( - "--out-list", help="list known output methods", action="store_true" - ) self.parser.add_argument( "--output-file", dest="output_file", help="Output File" ) self.parser.add_argument( - "-L", + "-l", "--log", dest="log_level", choices=["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"], @@ -101,17 +99,10 @@ def help(self, doexit: bool = True): options.add_row( "-o", "--out", - "OUTPUT", - "currently not used, but will let uses force output style", + "{json, yaml, boolean}", + "force output style through a known output", "auto", ) - options.add_row( - "", - "--out-list", - "", - "list known output types, currently not implimented", - "", - ) options.add_row( "", "--output-file", @@ -127,7 +118,7 @@ def help(self, doexit: bool = True): "30", ) options.add_row( - "-L", + "-l", "--log", "{[bold red]CRITICAL[/bold red],[red]ERROR[/red],[yellow]WARNING[/yellow],[blue]INFO[/blue],[green]DEBUG[/green]}", "console log level", diff --git a/src/guajillo/utils/conn.py b/src/guajillo/utils/conn.py index 69fc668..37f10a2 100644 --- a/src/guajillo/utils/conn.py +++ b/src/guajillo/utils/conn.py @@ -194,9 +194,20 @@ async def taskMan(self, async_comms: dict["str", Any]) -> None: if "tag" in output["return"][0]: job_type = "master" jid = output["return"][0]["jid"] - else: + elif "jid" in output["return"][0]: job_type = "minion" jid = output["return"][0]["jid"] + else: + job_type = "error" + output_event = { + "meta": { + "output": "json", + "step": "final", + }, + "output": output, + } + self.async_comms["events"].append(output_event) + self.async_comms["update"].set() else: output_event = { "meta": { diff --git a/src/guajillo/utils/outputs.py b/src/guajillo/utils/outputs.py index bc14cfd..a300340 100644 --- a/src/guajillo/utils/outputs.py +++ b/src/guajillo/utils/outputs.py @@ -59,6 +59,9 @@ async def boolean(self, event: dict[str, Any]) -> None: for item in nonreturned: self.console.print(f"[red]✘ {item}[/red]") + async def string(self, output: str) -> None: + self.console.print(output) + async def taskMan(self, async_comms: dict[str, Any]) -> None: try: log.info("Starting output Task Manager") @@ -72,6 +75,8 @@ async def taskMan(self, async_comms: dict[str, Any]) -> None: if event["meta"]["step"] == "final": self.cstatus.stop() log.debug(f"calling outputer {event["meta"]["output"]}") + if event["output"]["return"][0] == {}: + await self.string("No known minions matched target") await getattr(self, event["meta"]["output"])(event["output"]) await asyncio.sleep(0.5) self.async_comms["one"] = True diff --git a/tests/unit/utils/test_cli.py b/tests/unit/utils/test_cli.py index 18c8132..9bf5d5d 100644 --- a/tests/unit/utils/test_cli.py +++ b/tests/unit/utils/test_cli.py @@ -43,18 +43,6 @@ def test_cli_out_fail(): assert excinfo.value.code == 2 -def test_cli_out_list(): - testing = CliParse() - testing.build_args(["--out-list"]) - assert testing.parsed_args.out_list - - -def test_cli_out_list_default(): - testing = CliParse() - testing.build_args(["-c", "/fake/file"]) - assert not testing.parsed_args.out_list - - def test_cli_output_file(): testing = CliParse() testing.build_args(["--output-file", "/fake/file"]) @@ -70,14 +58,14 @@ def test_cli_output_file_fail(): def test_cli_log(): testing = CliParse() - testing.build_args(["-L", "DEBUG"]) + testing.build_args(["-l", "DEBUG"]) assert testing.parsed_args.log_level == "DEBUG" def test_cli_log_fail(): testing = CliParse() with pytest.raises(SystemExit) as excinfo: - testing.build_args(["-L", "ALL"]) + testing.build_args(["-l", "ALL"]) assert excinfo.value.code == 2 @@ -104,14 +92,9 @@ def test_help(): │ │ │ │ config file to │ │ │ │ │ │ use as login │ │ │ │ │ │ info │ │ -│ -o │ --out │ OUTPUT │ currently not │ auto │ -│ │ │ │ used, but will │ │ -│ │ │ │ let uses force │ │ -│ │ │ │ output style │ │ -│ │ --out-list │ │ list known │ │ -│ │ │ │ output types, │ │ -│ │ │ │ currently not │ │ -│ │ │ │ implimented │ │ +│ -o │ --out │ {json, yaml, │ force output │ auto │ +│ │ │ boolean} │ style through a │ │ +│ │ │ │ known output │ │ │ │ --output-file │ OUTPUT_FILE │ Not implimented, │ │ │ │ │ │ output file to │ │ │ │ │ │ dump output to │ │ @@ -119,7 +102,7 @@ def test_help(): │ │ │ │ internal │ │ │ │ │ │ operations, │ │ │ │ │ │ loops to fetch │ │ -│ -L │ --log │ {CRITICAL,ERRO… │ console log │ WARNING │ +│ -l │ --log │ {CRITICAL,ERRO… │ console log │ WARNING │ │ │ │ │ level │ │ └───────┴───────────────┴─────────────────┴──────────────────┴─────────────────┘ @@ -127,5 +110,5 @@ def test_help(): """ assert capture.get() == expected - with pytest.raises(SystemExit) as excinfo: + with pytest.raises(SystemExit): testing.build_args(["-h"])