diff --git a/calm/dsl/cli/runbook_commands.py b/calm/dsl/cli/runbook_commands.py index f51dd6a0..06f2b2de 100644 --- a/calm/dsl/cli/runbook_commands.py +++ b/calm/dsl/cli/runbook_commands.py @@ -44,7 +44,7 @@ ) @click.option("--limit", "-l", default=20, help="Number of results to return") @click.option( - "--offset", "-o", default=0, help="Offset results by the specified amount" + "--offset", "-s", default=0, help="Offset results by the specified amount" ) @click.option( "--quiet", "-q", is_flag=True, default=False, help="Show only runbook names." @@ -52,10 +52,18 @@ @click.option( "--all-items", "-a", is_flag=True, help="Get all items, including deleted ones" ) -def _get_runbook_list(name, filter_by, limit, offset, quiet, all_items): +@click.option( + "--out", + "-o", + "out", + type=click.Choice(["text", "json"]), + default="text", + help="output format", +) +def _get_runbook_list(name, filter_by, limit, offset, quiet, all_items, out): """Get the runbooks, optionally filtered by a string""" - get_runbook_list(name, filter_by, limit, offset, quiet, all_items) + get_runbook_list(name, filter_by, limit, offset, quiet, all_items, out) @get.command("runbook_executions", feature_min_version="3.0.0", experimental=True) diff --git a/calm/dsl/cli/runbooks.py b/calm/dsl/cli/runbooks.py index 9595244d..282e1293 100644 --- a/calm/dsl/cli/runbooks.py +++ b/calm/dsl/cli/runbooks.py @@ -46,7 +46,7 @@ LOG = get_logging_handle(__name__) -def get_runbook_list(name, filter_by, limit, offset, quiet, all_items): +def get_runbook_list(name, filter_by, limit, offset, quiet, all_items, out): """Get the runbooks, optionally filtered by a string""" client = get_api_client() @@ -75,7 +75,12 @@ def get_runbook_list(name, filter_by, limit, offset, quiet, all_items): LOG.warning("Cannot fetch runbooks from {}".format(pc_ip)) return - json_rows = res.json()["entities"] + res = res.json() + if out == "json": + click.echo(json.dumps(res, indent=4, separators=(",", ": "))) + return + + json_rows = res["entities"] if not json_rows: click.echo(highlight_text("No runbook found !!!\n")) return