Skip to content

Commit

Permalink
dump api
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan committed Apr 8, 2024
1 parent 16ed5d7 commit bcfb276
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
37 changes: 37 additions & 0 deletions demisto_sdk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
logging_setup,
)
from demisto_sdk.commands.common.tools import (
convert_path_to_str,
find_type,
get_last_remote_release_version,
get_release_note_entries,
Expand Down Expand Up @@ -3809,5 +3810,41 @@ def xsoar_linter(
main.add_command(typer.main.get_command(xsoar_linter_app), "xsoar-lint")


# ====================== export ====================== #

export_app = typer.Typer(name="dump-api")


@export_app.command(
context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
)
def dump_api(
ctx: typer.Context,
output_path: Path = typer.Option(
CONTENT_PATH,
"-o",
"--output",
help="The output directory to save the exported demisto-sdk api.",
),
):
output_json: dict = {}
for command_name, command in main.commands.items():
if isinstance(command, click.Group):
output_json[command_name] = {}
for sub_command_name, sub_command in command.commands.items():
output_json[command_name][sub_command_name] = sub_command.to_info_dict(
ctx
)
else:
output_json[command_name] = command.to_info_dict(ctx)
convert_path_to_str(output_json)
if output_path.is_dir():
output_path = output_path / "demisto-sdk-api.json"
output_path.write_text(json.dumps(output_json, indent=4))


main.add_command(typer.main.get_command(export_app), "dump-api")


if __name__ == "__main__":
main()
20 changes: 20 additions & 0 deletions demisto_sdk/commands/common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4490,3 +4490,23 @@ def get_relative_path(file_path: Union[str, Path], relative_to: Path) -> Path:
if file_path.is_absolute():
file_path = file_path.relative_to(relative_to)
return file_path


def convert_path_to_str(data: Union[dict, list]):
"""This converts recursively all Path objects to strings in the given data.
Args:
data (Union[dict, list]): The data to convert.
"""
if isinstance(data, dict):
for key, value in data.items():
if isinstance(value, (dict, list)):
convert_path_to_str(value)
elif isinstance(value, Path):
data[key] = str(value)
elif isinstance(data, list):
for index, item in enumerate(data):
if isinstance(item, (dict, list)):
convert_path_to_str(item)
elif isinstance(item, Path):
data[index] = str(item)

0 comments on commit bcfb276

Please sign in to comment.