Skip to content

Commit e902643

Browse files
authored
[core][feat] Improve the display name of the property (#2073)
1 parent 5bd2fe5 commit e902643

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

fixcore/fixcore/cli/command.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,16 @@
5555
from detect_secrets.core import scan, plugins
5656
from detect_secrets.core.potential_secret import PotentialSecret
5757
from detect_secrets.settings import configure_settings_from_baseline, default_settings
58-
from parsy import Parser, string, ParseError
5958
from fixclient.models import Model as RCModel, Kind as RCKind
59+
from fixdatalink import EngineConfig
60+
from fixdatalink.batch_stream import BatchStream
61+
from fixdatalink.collect_plugins import update_sql
62+
from parsy import Parser, string, ParseError
63+
from rich.padding import Padding
64+
from rich.panel import Panel
65+
from rich.table import Table
66+
from rich.text import Text
67+
6068
from fixcore import version
6169
from fixcore.async_extensions import run_async
6270
from fixcore.cli import (
@@ -170,9 +178,6 @@
170178
respond_cytoscape,
171179
)
172180
from fixcore.worker_task_queue import WorkerTask, WorkerTaskName
173-
from fixdatalink import EngineConfig
174-
from fixdatalink.batch_stream import BatchStream
175-
from fixdatalink.collect_plugins import update_sql
176181
from fixlib.core import CLIEnvelope
177182
from fixlib.durations import parse_duration
178183
from fixlib.parse_util import (
@@ -188,10 +193,6 @@
188193
)
189194
from fixlib.utils import safe_members_in_tarfile, get_local_tzinfo
190195
from fixlib.x509 import write_cert_to_file, write_key_to_file
191-
from rich.padding import Padding
192-
from rich.panel import Panel
193-
from rich.table import Table
194-
from rich.text import Text
195196

196197
if TYPE_CHECKING:
197198
from fixcore.dependencies import TenantDependencies
@@ -2638,7 +2639,11 @@ def parse(self, arg: Optional[str] = None, ctx: CLIContext = EmptyContext, **kwa
26382639
is_aggregate: bool = ctx.query is not None and ctx.query.aggregate is not None
26392640

26402641
def display(name: str) -> str:
2641-
return " ".join(word.capitalize() for word in name.split("_"))
2642+
return " \u279E ".join(
2643+
" ".join((word[0].upper() + word[1:]).strip("`") for word in part.replace("_", " ").split(" ") if word)
2644+
for part in PropertyPath.from_string(name).path
2645+
if part is not None and part not in Section.content
2646+
)
26422647

26432648
def default_props_to_show(
26442649
props_setting: Tuple[List[PropToShow], List[PropToShow], List[PropToShow], List[PropToShow]]
@@ -2725,7 +2730,7 @@ def parse_props_to_show(props_arg: str) -> List[PropToShow]:
27252730
for prop, as_name in list_arg_parse.parse(props_arg):
27262731
path = adjust_path(prop)
27272732
as_name = path[-1] if prop == as_name or as_name is None else as_name
2728-
props.append(PropToShow(path, as_name, display(as_name), prop))
2733+
props.append(PropToShow(path, as_name, display(prop), prop))
27292734
return props
27302735

27312736
def create_unique_names(all_props: List[PropToShow]) -> List[PropToShow]:

fixcore/tests/fixcore/cli/command_test.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ async def test_list_command(cli: CLI) -> None:
611611
{"display": "Name", "kind": "string", "name": "name", "path": "/name"},
612612
{"display": "Some Int", "kind": "int32", "name": "some_int", "path": "/some_int"},
613613
{
614-
"display": "Foo․bla․bar.test.rest.best.",
614+
"display": "Tags ➞ foo․bla․bar.test.rest.best.",
615615
"kind": "string",
616616
"name": "foo․bla․bar.test.rest.best.",
617617
"path": "/tags.`foo․bla․bar.test.rest.best.`",
@@ -649,6 +649,37 @@ async def test_list_command(cli: CLI) -> None:
649649
result = await cli.execute_cli_command("search is (foo) | aggregate kind: sum(1) as count | list", list_sink)
650650
assert result[0][0] == "kind=foo, count=10"
651651

652+
# properties to display are rendered correctly
653+
result = await cli.execute_cli_command(
654+
'search all {account_setting: <-- } account_setting.reported.bucket_public_access_block_configuration.{block_public_acls != true or ignore_public_acls != true or block_public_policy != true or restrict_public_buckets != true} and bucket_public_access_block_configuration.{block_public_acls != true or ignore_public_acls != true or block_public_policy != true or restrict_public_buckets != true} and (bucket_acl.grants[*].{permission in ["READ","READ_ACP","WRITE","WRITE_ACP","FULL_CONTROL"] and grantee.uri = "http://acs.amazonaws.com/groups/global/AllUsers"} or bucket_policy.Statement[*].{Effect = "Allow" and (Principal = "*" or Principal.AWS = "*" or Principal.CanonicalUser = "*") and (Action in ["s3:GetObject","s3:PutObject","s3:Get*","s3:Put*","s3:*","*"] or Action[*] in ["s3:GetObject","s3:PutObject","s3:Get*","s3:Put*","s3:*","*"])}) | list --json-table', # noqa
655+
list_sink,
656+
)
657+
assert [a["display"] for a in result[0][0]["columns"]] == [
658+
"Kind",
659+
"Id",
660+
"Name",
661+
"Bucket Acl ➞ Grants[] ➞ Permission",
662+
"Bucket Acl ➞ Grants[] ➞ Grantee ➞ Uri",
663+
"Bucket Policy ➞ Statement[] ➞ Effect",
664+
"Bucket Policy ➞ Statement[] ➞ Principal",
665+
"Bucket Policy ➞ Statement[] ➞ Principal ➞ AWS",
666+
"Bucket Policy ➞ Statement[] ➞ Principal ➞ CanonicalUser",
667+
"Bucket Policy ➞ Statement[] ➞ Action",
668+
"Bucket Policy ➞ Statement[] ➞ Action[]",
669+
"Bucket Public Access Block Configuration ➞ Block Public Acls",
670+
"Bucket Public Access Block Configuration ➞ Ignore Public Acls",
671+
"Bucket Public Access Block Configuration ➞ Block Public Policy",
672+
"Bucket Public Access Block Configuration ➞ Restrict Public Buckets",
673+
"Account Setting ➞ Bucket Public Access Block Configuration ➞ Block Public Acls",
674+
"Account Setting ➞ Bucket Public Access Block Configuration ➞ Ignore Public Acls",
675+
"Account Setting ➞ Bucket Public Access Block Configuration ➞ Block Public Policy",
676+
"Account Setting ➞ Bucket Public Access Block Configuration ➞ Restrict Public Buckets",
677+
"Age",
678+
"Cloud",
679+
"Account",
680+
"Region / Zone",
681+
]
682+
652683

653684
@pytest.mark.asyncio
654685
async def test_jq_command(cli: CLI) -> None:

0 commit comments

Comments
 (0)