diff --git a/aar_doc/core.py b/aar_doc/core.py index 8a4d61d..48a5625 100644 --- a/aar_doc/core.py +++ b/aar_doc/core.py @@ -188,40 +188,41 @@ def parse_options(ctx: typer.Context) -> dict: .replace("\n", " ") .strip() ) - details["display_type"] = details.get("type", "str") - details["display_default"] = "" - if details["display_type"] == "bool": - details["display_default"] = ( - "true" if details.get("default", False) else "false" - ) - elif details["display_type"] == "list": - if default := details.get("default", None): - details["display_default"] = json.dumps(default) - if "elements" in details: - if (details["elements"] == "dict") and ("options" in details): - details["display_type"] = ( - f"list of dicts of '{option}' options" - ) - else: - details["display_type"] = ( - "list of '" + details["elements"] + "'" - ) - elif details["display_type"] == "dict": - if default := details.get("default", None): - details["display_default"] = json.dumps(default) + + display_type = details.get("type", "str") + + if display_type == "list": + elements = details.get("elements", "") + if elements == "dict" and "options" in details: + display_type = f"list of dicts of '{option}' options" + else: + display_type = f"list of '{elements}'" + elif display_type == "dict": if "options" in details: - details["display_type"] = f"dict of '{option}' options" - elif details["display_type"] == "str": - try: - details["display_default"] = details.get("default", "").strip() - except AttributeError as exc: - typer.echo( - f"The default value of the argument {option} " - f"is of type {type(details.get('default')).__name__}, need str", + display_type = f"dict of '{option}' options" + + details["display_type"] = display_type + + if "default" in details: + default_value = details.get("default", "") + details["display_default"] = str(default_value).strip() + + if display_type in ["list", "dict"]: + details["display_default"] = ( + json.dumps(default_value) if default_value else "" ) - raise typer.Exit(code=1) from exc + + elif display_type == "str": + if not isinstance(default_value, str): + typer.echo( + f"The default value of the argument {option} " + f"is of type {type(default_value).__name__}, need str", + ) + raise typer.Exit(1) + else: - details["display_default"] = str(details.get("default", "")).strip() + details["display_default"] = "" + entrypoint_options[entrypoint] = gathered_options return entrypoint_options diff --git a/tests/fixtures/roles/extended/README.md b/tests/fixtures/roles/extended/README.md index 7830c7f..052f881 100644 --- a/tests/fixtures/roles/extended/README.md +++ b/tests/fixtures/roles/extended/README.md @@ -112,10 +112,10 @@ The bool entry point for the extended role. |Option|Description|Type|Required|Default| |---|---|---|---|---| -| bool_true | A true boolean value | bool | no | true | -| bool_false | A false boolean value | bool | no | false | -| bool_yes | A truthy boolean value | bool | no | true | -| bool_no | A falsy boolean value | bool | no | false | +| bool_true | A true boolean value | bool | no | True | +| bool_false | A false boolean value | bool | no | False | +| bool_yes | A truthy boolean value | bool | no | yes | +| bool_no | A falsy boolean value | bool | no | no | diff --git a/tests/fixtures/roles/meta_main_yaml/README.md b/tests/fixtures/roles/meta_main_yaml/README.md index 78fdabe..e913dd8 100644 --- a/tests/fixtures/roles/meta_main_yaml/README.md +++ b/tests/fixtures/roles/meta_main_yaml/README.md @@ -102,10 +102,10 @@ The bool entry point for the extended role. |Option|Description|Type|Required|Default| |---|---|---|---|---| -| bool_true | A true boolean value | bool | no | true | -| bool_false | A false boolean value | bool | no | false | -| bool_yes | A truthy boolean value | bool | no | true | -| bool_no | A falsy boolean value | bool | no | false | +| bool_true | A true boolean value | bool | no | True | +| bool_false | A false boolean value | bool | no | False | +| bool_yes | A truthy boolean value | bool | no | yes | +| bool_no | A falsy boolean value | bool | no | no |