Skip to content

Commit 8575891

Browse files
committed
Lots of CLI UI fixes and refinements
Tweak the XSL to sort out some over-run in the terminal styles; add a --str-limit option to prevent outputting insanely long string samples to the console (output lengths instead of values for these strs). This also replaces --show-lengths with --show-count to show counts for everything relevant (containers, scalars, etc.)
1 parent ec82a30 commit 8575891

File tree

3 files changed

+168
-49
lines changed

3 files changed

+168
-49
lines changed

structa/ui/cli.py

+48-25
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,33 @@ def get_config(args):
8787
help="The proportion of string values permitted to be empty without "
8888
"preventing the pattern from being reported; the proportion of "
8989
'"empty" data permitted in a field (default: %(default)s)')
90+
parser.add_argument(
91+
'--str-limit', type=num, metavar='NUM', default=20,
92+
help="The length beyond which only the lengths of strs will be "
93+
"reported; below this the actual value of the string will be "
94+
"displayed (default: %(default)s)")
95+
parser.add_argument(
96+
'--hide-count', action='store_false', dest='show_count',
97+
default=False)
98+
parser.add_argument(
99+
'--show-count', action='store_true',
100+
help="If set, show the count of items in containers, the count of "
101+
"unique scalar values, and the count of all sample values (if "
102+
"--show-samples is set). If disabled, counts will be hidden")
103+
parser.add_argument(
104+
'--hide-lengths', action='store_false', dest='show_lengths',
105+
default=False)
106+
parser.add_argument(
107+
'--show-lengths', action='store_true',
108+
help="If set, display the range of lengths of string fields in the "
109+
"same format as specified by --show-range")
110+
parser.add_argument(
111+
'--hide-pattern', action='store_false', dest='show_pattern',
112+
default=True)
113+
parser.add_argument(
114+
'--show-pattern', action='store_true',
115+
help="If set, show the pattern determined for fixed length string "
116+
"fields. If disabled, pattern information will be hidden")
90117
parser.add_argument(
91118
'--hide-range', action='store_const', dest='show_range',
92119
const='hidden', default='limits')
@@ -99,19 +126,12 @@ def get_config(args):
99126
"displays a crude chart showing the positions of the quartiles "
100127
"relative to the limits. Use --hide-range to hide all range info")
101128
parser.add_argument(
102-
'--hide-pattern', action='store_false', dest='show_pattern',
103-
default=True)
104-
parser.add_argument(
105-
'--show-pattern', action='store_true',
106-
help="If set, show the pattern determined for fixed length string "
107-
"fields. If disabled, pattern information will be hidden")
108-
parser.add_argument(
109-
'--hide-lengths', action='store_false', dest='show_lengths',
129+
'--hide-samples', action='store_false', dest='show_samples',
110130
default=False)
111131
parser.add_argument(
112-
'--show-lengths', action='store_true',
113-
help="If set, display the range of lengths of string fields in the "
114-
"same format as specified by --show-range")
132+
'--show-samples', action='store_true',
133+
help="If set, show samples of non-unique scalar values including the "
134+
"most and least common values. If disabled, samples will be hidden")
115135
parser.add_argument(
116136
'--min-timestamp', type=min_timestamp, metavar='WHEN',
117137
default='20 years',
@@ -200,22 +220,25 @@ def get_structure(config):
200220
def print_structure(config, structure):
201221
term = Terminal()
202222
styles = {
203-
'normal-style': term.normal,
204-
'unique-style': term.red('*'),
205-
'key-style': '',
206-
'type-style': term.cyan,
207-
'stats-style': term.normal,
208-
'pattern-style': term.bold,
209-
'literal-style': term.normal,
210-
'req-style': '',
211-
'opt-style': term.red('?'),
212-
'ellipsis': term.green('..'),
213-
'truncation': term.green('$'),
223+
'normal-style': term.normal,
224+
'unique-style': term.underline,
225+
'type-style': term.cyan,
226+
'fill-style': term.green,
227+
'suffix-style': term.green,
228+
'pattern-style': term.yellow,
229+
'literal-style': term.normal,
230+
'required-suffix': '',
231+
'optional-suffix': term.red('?'),
232+
'ellipsis': term.green('..'),
233+
'truncation': term.green('$'),
214234
}
215235
params = {
216-
'show-pattern': str(int(config.show_pattern)),
217-
'show-lengths': str(int(config.show_lengths)),
218-
'show-range': str(RANGE_CONFIGS[config.show_range]),
236+
'show-count': str(int(config.show_count)),
237+
'show-pattern': str(int(config.show_pattern)),
238+
'show-samples': str(int(config.show_samples)),
239+
'show-lengths': str(int(config.show_lengths)),
240+
'show-range': str(RANGE_CONFIGS[config.show_range]),
241+
'str-limit': str(int(config.str_limit)),
219242
}
220243
transform = get_transform('cli.xsl')
221244
# XML 1.0 doesn't permit controls characters (other than whitespace) so

0 commit comments

Comments
 (0)