[PATCH net-next v2 3/3] tools: ynl: cli: Display enum values in --list-attrs output

Gal Pressman
2025-11-18T14:31:40Z

When listing attributes with --list-attrs, display the actual enum
values for attributes that reference an enum type.

# ./cli.py --family netdev --list-attrs dev-get
[..]
- xdp-features: u64 (enum: xdp-act)
Flags: basic, redirect, ndo-xmit, xsk-zerocopy, hw-offload, rx-sg, ndo-xmit-sg
Bitmask of enabled xdp-features.
[..]

Reviewed-by: Nimrod Oren <noren@nvidia.com>
Signed-off-by: Gal Pressman <gal@nvidia.com>
---
tools/net/ynl/pyynl/cli.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py
index 6655ee61081a..ff81ff083764 100755
--- a/tools/net/ynl/pyynl/cli.py
+++ b/tools/net/ynl/pyynl/cli.py
@@ -48,7 +48,13 @@ def print_attr_list(ynl, attr_names, attr_set, indent=2):
attr = attr_set.attrs[attr_name]
attr_info = f'{prefix}- {attr_name}: {attr.type}'
if 'enum' in attr.yaml:
- attr_info += f" (enum: {attr.yaml['enum']})"
+ enum_name = attr.yaml['enum']
+ attr_info += f" (enum: {enum_name})"
+ # Print enum values if available
+ 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)}"

# Show nested attributes reference and recursively display them
nested_set_name = None
--
2.40.1