From d46f9c7746cf4bdfa7a325f36ad44f7df2960fc0 Mon Sep 17 00:00:00 2001 From: Matthias Veit Date: Wed, 29 Nov 2023 18:26:25 +0100 Subject: [PATCH] [resoto][fix] Handle backticks in list command (#1842) * [resoto][fix] Handle backticks in list command * make linter happy --- resotocore/resotocore/cli/command.py | 6 +++--- resotocore/resotocore/model/model.py | 3 +++ resotocore/tests/resotocore/cli/command_test.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/resotocore/resotocore/cli/command.py b/resotocore/resotocore/cli/command.py index 388164567..6b1ab1313 100644 --- a/resotocore/resotocore/cli/command.py +++ b/resotocore/resotocore/cli/command.py @@ -2549,7 +2549,6 @@ class ListCommand(CLICommand, OutputTransformer): + default_history_properties_to_show + default_live_properties_to_show } - dot_re = re.compile("[.]") @property def name(self) -> str: @@ -2600,7 +2599,8 @@ def default_props_to_show() -> List[Tuple[List[str], str]]: for name in chain(predicate_names, sort_names): if name not in self.all_default_props and name not in local_paths: local_paths.add(name) - result.append((self.dot_re.split(name), name.rsplit(".", 1)[-1])) + path = PropertyPath.from_path(name).unescaped_parts() + result.append((path, path[-1])) if ctx.query_options.get("history") is not True: result.extend(self.default_live_properties_to_show) # add all context properties @@ -2608,7 +2608,7 @@ def default_props_to_show() -> List[Tuple[List[str], str]]: return result def adjust_path(prop_path: str) -> List[str]: - return self.dot_re.split(ctx.variable_in_section(prop_path)) + return PropertyPath.from_path(ctx.variable_in_section(prop_path)).unescaped_parts() def to_str(name: str, elem: JsonElement) -> str: if isinstance(elem, dict): diff --git a/resotocore/resotocore/model/model.py b/resotocore/resotocore/model/model.py index 6bcf32af4..2b892cac4 100644 --- a/resotocore/resotocore/model/model.py +++ b/resotocore/resotocore/model/model.py @@ -179,6 +179,9 @@ def child(self, part: Optional[str]) -> PropertyPath: update.append(part) return PropertyPath(update) + def unescaped_parts(self) -> List[str]: + return [p.strip("`") for p in self.path if p is not None] + @property def last_part(self) -> Optional[str]: return self.path[-1] if self.path else None diff --git a/resotocore/tests/resotocore/cli/command_test.py b/resotocore/tests/resotocore/cli/command_test.py index 54e53c3bf..01a4fbe92 100644 --- a/resotocore/tests/resotocore/cli/command_test.py +++ b/resotocore/tests/resotocore/cli/command_test.py @@ -584,7 +584,7 @@ async def test_list_command(cli: CLI) -> None: # List supports csv output result = await cli.execute_cli_command( - f"json {json.dumps(props)} | list --csv a,b,c,d,e,f,non_existent", stream.list + f"json {json.dumps(props)} | list --csv a,`b`,c,`d`,e,`f`,non_existent", stream.list ) assert result[0] == ['"a","b","c","d","e","f","non_existent"', '"a",True,False,"",12,1.234,""']