Skip to content

Commit

Permalink
[resoto][fix] Handle backticks in list command (#1842)
Browse files Browse the repository at this point in the history
* [resoto][fix] Handle backticks in list command

* make linter happy
  • Loading branch information
aquamatthias committed Nov 29, 2023
1 parent 2506c1a commit d46f9c7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions resotocore/resotocore/cli/command.py
Expand Up @@ -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:
Expand Down Expand Up @@ -2600,15 +2599,16 @@ 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
result.extend(self.default_context_properties_to_show)
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):
Expand Down
3 changes: 3 additions & 0 deletions resotocore/resotocore/model/model.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion resotocore/tests/resotocore/cli/command_test.py
Expand Up @@ -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,""']

Expand Down

0 comments on commit d46f9c7

Please sign in to comment.