diff --git a/resotocore/resotocore/cli/model.py b/resotocore/resotocore/cli/model.py index 17f0cdb4f0..e3214618a1 100644 --- a/resotocore/resotocore/cli/model.py +++ b/resotocore/resotocore/cli/model.py @@ -348,6 +348,7 @@ class AliasTemplate: # only use args_description if the template does not use explicit parameters args_description: Dict[str, str] = field(factory=dict) allowed_in_source_position: bool = False + infra_app_parameters: Optional[Dict[str, Any]] = None # todo: remove this abomination def render(self, props: Json) -> str: return render_template(self.template, props) @@ -378,6 +379,28 @@ def param_info(p: AliasTemplateParameter) -> str: if self.description: for line in self.description.splitlines(): desc += f"\n{indent}{line}" + + if self.infra_app_parameters: + + def param_info_infra_apps(name: str, arg_info: Dict[str, Any]) -> str: + default = f" [default: {arg_info.get('default')}]" if arg_info.get("default") else "" + return f"- `{name}`{default}: {arg_info.get('help')}" + + arg_info = f"\n{indent}".join( + param_info_infra_apps(name, arg) for name, arg in self.infra_app_parameters.items() + ) + result = dedent( + f""" + {self.name}: {self.info} + ```shell + {self.name} {args} + ``` + {desc} + ## Parameters + {arg_info}""" + ) + return result + return dedent( f""" {self.name}: {self.info} @@ -395,7 +418,7 @@ def param_info(p: AliasTemplateParameter) -> str: ## Example ```shell - # Executing this alias template + # Executing this command > {self.name} {minimal} # Will expand to this command > {self.render({p.name: p.example_value() for p in self.parameters})} @@ -417,6 +440,8 @@ def help_no_params_args(self) -> str: ) def help(self) -> str: + if self.infra_app_parameters: # todo: remove this abomination + return self.help_with_params() return self.help_with_params() if self.parameters else self.help_no_params_args() def rendered_help(self, ctx: CLIContext) -> str: diff --git a/resotocore/resotocore/infra_apps/local_runtime.py b/resotocore/resotocore/infra_apps/local_runtime.py index cab4af5593..9bae84f6f3 100644 --- a/resotocore/resotocore/infra_apps/local_runtime.py +++ b/resotocore/resotocore/infra_apps/local_runtime.py @@ -43,15 +43,10 @@ async def execute( """ Runtime implementation that runs the app locally. """ - try: - async for line in self.generate_template(graph, manifest, config, stdin, argv): - async with (await self._interpret_line(line, ctx)).stream() as streamer: - async for item in streamer: - yield item - - except Exception as e: - msg = f"Error running infrastructure app: {e}" - log.exception(msg) + async for line in self.generate_template(graph, manifest, config, stdin, argv): + async with (await self._interpret_line(line, ctx)).stream() as streamer: + async for item in streamer: + yield item async def generate_template( self, diff --git a/resotocore/resotocore/infra_apps/package_manager.py b/resotocore/resotocore/infra_apps/package_manager.py index 02b3a02390..b8f7644a30 100644 --- a/resotocore/resotocore/infra_apps/package_manager.py +++ b/resotocore/resotocore/infra_apps/package_manager.py @@ -105,6 +105,7 @@ def _setup_custom_commands(self, manifests: List[AppManifest]) -> None: template=f"apps run {manifest.name}" + r" {{args}}", description=manifest.readme, allowed_in_source_position=True, + infra_app_parameters=manifest.args_schema, ) self.add_command_alias(alias_template) diff --git a/resotocore/tests/resotocore/cli/model_test.py b/resotocore/tests/resotocore/cli/model_test.py index e1665181f3..7ff573c6ca 100644 --- a/resotocore/tests/resotocore/cli/model_test.py +++ b/resotocore/tests/resotocore/cli/model_test.py @@ -50,7 +50,7 @@ def test_alias_template() -> None: ## Example ```shell - # Executing this alias template + # Executing this command > foo --a "test_a" # Will expand to this command > test_a | bv