From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me,
donald.hunter@gmail.com, gal@nvidia.com,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 1/7] tools: ynl: cli: introduce formatting for attr names in --list-attrs
Date: Sat, 10 Jan 2026 15:31:36 -0800 [thread overview]
Message-ID: <20260110233142.3921386-2-kuba@kernel.org> (raw)
In-Reply-To: <20260110233142.3921386-1-kuba@kernel.org>
It's a little hard to make sense of the output of --list-attrs,
it looks like a wall of text. Sprinkle a little bit of formatting -
make op and attr names bold, and Enum: / Flags: keywords italics.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/pyynl/cli.py | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py
index 5fee45e48bbf..aa50d42e35ac 100755
--- a/tools/net/ynl/pyynl/cli.py
+++ b/tools/net/ynl/pyynl/cli.py
@@ -20,6 +20,29 @@ from lib import YnlFamily, Netlink, NlError, SpecFamily, SpecException, YnlExcep
SYS_SCHEMA_DIR='/usr/share/ynl'
RELATIVE_SCHEMA_DIR='../../../../Documentation/netlink'
+# pylint: disable=too-few-public-methods,too-many-locals
+class Colors:
+ """ANSI color and font modifier codes"""
+ RESET = '\033[0m'
+
+ BOLD = '\033[1m'
+ ITALICS = '\033[3m'
+ UNDERLINE = '\033[4m'
+ INVERT = '\033[7m'
+
+
+def color(text, modifiers):
+ """Add color to text if output is a TTY
+
+ Returns:
+ Colored text if stdout is a TTY, otherwise plain text
+ """
+ if sys.stdout.isatty():
+ # Join the colors if they are a list, if it's a string this a noop
+ modifiers = "".join(modifiers)
+ return f"{modifiers}{text}{Colors.RESET}"
+ return text
+
def schema_dir():
"""
Return the effective schema directory, preferring in-tree before
@@ -60,7 +83,7 @@ RELATIVE_SCHEMA_DIR='../../../../Documentation/netlink'
for attr_name in attr_names:
if attr_name in attr_set.attrs:
attr = attr_set.attrs[attr_name]
- attr_info = f'{prefix}- {attr_name}: {attr.type}'
+ attr_info = f'{prefix}- {color(attr_name, Colors.BOLD)}: {attr.type}'
if 'enum' in attr.yaml:
enum_name = attr.yaml['enum']
attr_info += f" (enum: {enum_name})"
@@ -68,7 +91,8 @@ RELATIVE_SCHEMA_DIR='../../../../Documentation/netlink'
if enum_name in ynl.consts:
const = ynl.consts[enum_name]
enum_values = list(const.entries.keys())
- attr_info += f"\n{prefix} {const.type.capitalize()}: {', '.join(enum_values)}"
+ type_fmted = color(const.type.capitalize(), Colors.ITALICS)
+ attr_info += f"\n{prefix} {type_fmted}: {', '.join(enum_values)}"
# Show nested attributes reference and recursively display them
nested_set_name = None
@@ -226,7 +250,7 @@ RELATIVE_SCHEMA_DIR='../../../../Documentation/netlink'
print(f'Operation {args.list_attrs} not found')
sys.exit(1)
- print(f'Operation: {op.name}')
+ print(f'Operation: {color(op.name, Colors.BOLD)}')
print(op.yaml['doc'])
for mode in ['do', 'dump', 'event']:
--
2.52.0
next prev parent reply other threads:[~2026-01-10 23:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-10 23:31 [PATCH net-next v2 0/7] tools: ynl: cli: improve the help and doc Jakub Kicinski
2026-01-10 23:31 ` Jakub Kicinski [this message]
2026-01-10 23:31 ` [PATCH net-next v2 2/7] tools: ynl: cli: wrap the doc text if it's long Jakub Kicinski
2026-01-10 23:31 ` [PATCH net-next v2 3/7] tools: ynl: cli: improve --help Jakub Kicinski
2026-01-10 23:31 ` [PATCH net-next v2 4/7] tools: ynl: cli: add --doc as alias to --list-attrs Jakub Kicinski
2026-01-10 23:31 ` [PATCH net-next v2 5/7] tools: ynl: cli: factor out --list-attrs / --doc handling Jakub Kicinski
2026-01-10 23:31 ` [PATCH net-next v2 6/7] tools: ynl: cli: extract the event/notify handling in --list-attrs Jakub Kicinski
2026-01-10 23:31 ` [PATCH net-next v2 7/7] tools: ynl: cli: print reply in combined format if possible Jakub Kicinski
2026-01-11 7:56 ` [PATCH net-next v2 0/7] tools: ynl: cli: improve the help and doc Gal Pressman
2026-01-11 20:19 ` Stanislav Fomichev
2026-01-12 2:05 ` Donald Hunter
2026-01-13 2:27 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260110233142.3921386-2-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=horms@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox