1818from collections import defaultdict
1919from contextlib import suppress
2020from datetime import timedelta , datetime
21- from functools import partial , lru_cache
21+ from functools import partial , lru_cache , cached_property
2222from itertools import dropwhile , chain
2323from pathlib import Path
2424from typing import (
@@ -2444,8 +2444,12 @@ class PropToShow:
24442444 alternative_path : Optional [List [str ]] = None
24452445 override_kind : Optional [str ] = None
24462446
2447+ @cached_property
2448+ def path_str (self ) -> str :
2449+ return "." .join (self .path )
2450+
24472451 def full_path (self ) -> str :
2448- return self .path_access or "." . join ( self .path )
2452+ return self .path_access or self .path_str
24492453
24502454 def value (self , node : JsonElement ) -> Optional [JsonElement ]:
24512455 result = js_value_at (node , self .path )
@@ -2502,8 +2506,9 @@ class ListCommand(CLICommand, OutputTransformer):
25022506 ## Options
25032507
25042508 - `--csv` [optional]: format the output as CSV. Can't be used together with `--markdown`.
2505-
25062509 - `--markdown` [optional]: format the output as Markdown table. Can't be used together with `--csv`.
2510+ - `--json-table` [optional]: format the output as JSON table.
2511+ - `--with-defaults` [optional]: show the default properties in addition to the defined ones.
25072512
25082513 ## Examples
25092514
@@ -2619,6 +2624,7 @@ def args_info(self) -> ArgsInfo:
26192624 ArgInfo ("--csv" , help_text = "format" , option_group = "format" ),
26202625 ArgInfo ("--markdown" , help_text = "format" , option_group = "format" ),
26212626 ArgInfo ("--json-table" , help_text = "format" , option_group = "format" ),
2627+ ArgInfo ("--with-defaults" ),
26222628 ArgInfo (
26232629 expects_value = True ,
26242630 help_text = "comma separated list of properties to show" ,
@@ -2632,6 +2638,7 @@ def parse(self, arg: Optional[str] = None, ctx: CLIContext = EmptyContext, **kwa
26322638 output_type .add_argument ("--csv" , dest = "csv" , action = "store_true" )
26332639 output_type .add_argument ("--markdown" , dest = "markdown" , action = "store_true" )
26342640 output_type .add_argument ("--json-table" , dest = "json_table" , action = "store_true" )
2641+ parser .add_argument ("--with-defaults" , dest = "with_defaults" , action = "store_true" )
26352642 parsed , properties_list = parser .parse_known_args (arg .split () if arg else [])
26362643 properties = " " .join (properties_list ) if properties_list else None
26372644 is_aggregate : bool = ctx .query is not None and ctx .query .aggregate is not None
@@ -2766,7 +2773,15 @@ def unique_name(path: List[str], current: str) -> str:
27662773 def props_to_show (
27672774 props_setting : Tuple [List [PropToShow ], List [PropToShow ], List [PropToShow ], List [PropToShow ]]
27682775 ) -> List [PropToShow ]:
2769- props = parse_props_to_show (properties ) if properties is not None else default_props_to_show (props_setting )
2776+ if properties :
2777+ props = parse_props_to_show (properties )
2778+ if parsed .with_defaults :
2779+ paths = {prop .path_str for prop in props }
2780+ for prop in default_props_to_show (props_setting ):
2781+ if prop .path_str not in paths :
2782+ props .append (prop )
2783+ else :
2784+ props = default_props_to_show (props_setting )
27702785 return create_unique_names (props )
27712786
27722787 def fmt_json (elem : Json ) -> JsonElement :
0 commit comments