diff options
| author | Jakub Kicinski <kuba@kernel.org> | 2026-01-31 12:30:29 -0800 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2026-02-02 17:06:14 -0800 |
| commit | 71a58ec6672fbb7ae9f1b4a8ee1b5c352af93c0d (patch) | |
| tree | 4968a27ed035ebdac3c8a0057a2f98dc9696785f /tools | |
| parent | ba9c5611f0888f143ff5faf28a73eac6ea20eaaf (diff) | |
tools: ynl: cli: make the output compact
Make the default (non-JSON) output more compact. Looking at RSS
context dumps is pretty much impossible without this, because
default print shows the indirection table with line per entry:
'indir': [0,
1,
2,
...
And indirection tables have 100-200 entries each.
The compact output is far more readable:
'indir': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/20260131203029.1173492-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/net/ynl/pyynl/cli.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py index fdac1ab10a40..94a5ba348b69 100755 --- a/tools/net/ynl/pyynl/cli.py +++ b/tools/net/ynl/pyynl/cli.py @@ -44,6 +44,10 @@ def color(text, modifiers): return f"{modifiers}{text}{Colors.RESET}" return text +def term_width(): + """ Get terminal width in columns (80 if stdout is not a terminal) """ + return shutil.get_terminal_size().columns + def schema_dir(): """ Return the effective schema directory, preferring in-tree before @@ -103,8 +107,7 @@ def print_attr_list(ynl, attr_names, attr_set, indent=2): if attr.yaml.get('doc'): doc_prefix = prefix + ' ' * 4 - term_width = shutil.get_terminal_size().columns - doc_text = textwrap.fill(attr.yaml['doc'], width=term_width, + doc_text = textwrap.fill(attr.yaml['doc'], width=term_width(), initial_indent=doc_prefix, subsequent_indent=doc_prefix) attr_info += f"\n{doc_text}" @@ -264,7 +267,7 @@ def main(): if args.output_json: print(json.dumps(msg, cls=YnlEncoder)) else: - pprint.PrettyPrinter().pprint(msg) + pprint.pprint(msg, width=term_width(), compact=True) if args.list_families: for filename in sorted(os.listdir(spec_dir())): |
