YNL CLI --list-attrs argument
Subsystems (4)
cover YNL CLI --list-attrs argument
When experimenting with the YNL CLI, I found the process of going back and forth to examine the YAML spec files in order to figure out how to use each command quite tiring.
The addition of --list-attrs helps by providing all information needed directly in the tool. I figured others would likely find it useful as well.
Gal Pressman (3):
tools: ynl: cli: Add --list-attrs option to show operation attributes
tools: ynl: cli: Parse nested attributes in --list-attrs output
tools: ynl: cli: Display enum values in --list-attrs output
tools/net/ynl/pyynl/cli.py | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
Signature · 1 line
2.40.1
PATCH 1/3 tools: ynl: cli: Add --list-attrs option to show operation attributes
Add a --list-attrs option to the YNL CLI that displays information about netlink operations, including request and reply attributes. This eliminates the need to manually inspect YAML spec files to determine the JSON structure required for operations, or understand the structure of the reply.
Example usage:
# ./cli.py --family netdev --list-attrs dev-get Operation: dev-get
Do request attributes:
- ifindex: u32
netdev ifindex
Do reply attributes:
- ifindex: u32
netdev ifindex
- xdp-features: u64 (enum: xdp-act)
Bitmask of enabled xdp-features.
- xdp-zc-max-segs: u32
max fragment count supported by ZC driver
- xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
Bitmask of supported XDP receive metadata features. See Documentation/networking/xdp-rx-metadata.rst for more details.
- xsk-features: u64 (enum: xsk-flags)
Bitmask of enabled AF_XDP features.
Dump reply attributes:
- ifindex: u32
netdev ifindex
- xdp-features: u64 (enum: xdp-act)
Bitmask of enabled xdp-features.
- xdp-zc-max-segs: u32
max fragment count supported by ZC driver
- xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
Bitmask of supported XDP receive metadata features. See Documentation/networking/xdp-rx-metadata.rst for more details.
- xsk-features: u64 (enum: xsk-flags)
Bitmask of enabled AF_XDP features.
--- tools/net/ynl/pyynl/cli.py | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
tools/net/ynl/pyynl/cli.py +55 -0
@@ -7,6 +7,7 @@ import os import pathlib import pprint import sys +import textwrap sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix()) from lib import YnlFamily, Netlink, NlError
@@ -70,6 +71,8 @@ def main(): group.add_argument('--dump', dest='dump', metavar='DUMP-OPERATION', type=str) group.add_argument('--list-ops', action='store_true') group.add_argument('--list-msgs', action='store_true') + group.add_argument('--list-attrs', dest='list_attrs', metavar='OPERATION', type=str, + help='List attributes for an operation') parser.add_argument('--duration', dest='duration', type=int, help='when subscribed, watch for DURATION seconds')
@@ -128,6 +131,40 @@ def main(): if args.ntf: ynl.ntf_subscribe(args.ntf) + def print_attr_list(attr_names, attr_set): + """Print a list of attributes with their types and documentation.""" + for attr_name in attr_names: + if attr_name in attr_set.attrs: + attr = attr_set.attrs[attr_name] + attr_info = f' - {attr_name}: {attr.type}' + if 'enum' in attr.yaml: + attr_info += f" (enum: {attr.yaml['enum']})" + if attr.yaml.get('doc'): + doc_text = textwrap.indent(attr.yaml['doc'], ' ') + attr_info += f"\n{doc_text}" + print(attr_info) + else: + print(f' - {attr_name}') + + def print_mode_attrs(mode, mode_spec, attr_set, print_request=True): + """Print a given mode (do/dump/event/notify).""" + mode_title = mode.capitalize() + + if print_request and 'request' in mode_spec and 'attributes' in mode_spec['request']: + print(f'\n{mode_title} request attributes:') + print_attr_list(mode_spec['request']['attributes'], attr_set) + + if 'reply' in mode_spec and 'attributes' in mode_spec['reply']: + print(f'\n{mode_title} reply attributes:') + print_attr_list(mode_spec['reply']['attributes'], attr_set) + + if 'attributes' in mode_spec: + print(f'\n{mode_title} attributes:') + print_attr_list(mode_spec['attributes'], attr_set) + + if 'mcgrp' in mode_spec: + print(f"Multicast group: {op.yaml['mcgrp']}") + if args.list_ops: for op_name, op in ynl.ops.items(): print(op_name, " [", ", ".join(op.modes), "]")
@@ -135,6 +172,24 @@ def main(): for op_name, op in ynl.msgs.items(): print(op_name, " [", ", ".join(op.modes), "]") + if args.list_attrs: + op = ynl.msgs.get(args.list_attrs) + if not op: + print(f'Operation {args.list_attrs} not found') + exit(1) + + print(f'Operation: {op.name}') + + for mode in ['do', 'dump', 'event']: + if mode in op.yaml: + print_mode_attrs(mode, op.yaml[mode], op.attr_set, True) + + if 'notify' in op.yaml: + mode_spec = op.yaml['notify'] + ref_spec = ynl.msgs.get(mode_spec).yaml.get('do') + if ref_spec: + print_mode_attrs(mode, ref_spec, op.attr_set, False) + try: if args.do: reply = ynl.do(args.do, attrs, args.flags)
Signature · 1 line
2.40.1
Donald Hunter
maintainerRe: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
Quoted 5 lines · Gal Pressman
Add a --list-attrs option to the YNL CLI that displays information about netlink operations, including request and reply attributes. This eliminates the need to manually inspect YAML spec files to determine the JSON structure required for operations, or understand the structure of the reply.
Thanks for the contribution, it's been on my wishlist for a while.
[...]
Quoted 4 lines
tools/net/ynl/pyynl/cli.py +4
-0+ def print_attr_list(attr_names, attr_set): + """Print a list of attributes with their types and documentation.""" + for attr_name in attr_names: + if attr_name in attr_set.attrs:
tools/net/ynl/pyynl/cli.py def main(): · line 147
Quoted 10 lines
tools/net/ynl/pyynl/cli.py +10
-0+ attr = attr_set.attrs[attr_name] + attr_info = f' - {attr_name}: {attr.type}' + if 'enum' in attr.yaml: + attr_info += f" (enum: {attr.yaml['enum']})" + if attr.yaml.get('doc'): + doc_text = textwrap.indent(attr.yaml['doc'], ' ') + attr_info += f"\n{doc_text}" + print(attr_info) + else: + print(f' - {attr_name}')
Does this line execute? I think this scenario indicates a malformed spec that would fail codegen.
Quoted 33 lines
tools/net/ynl/pyynl/cli.py +26
-0+ def print_mode_attrs(mode, mode_spec, attr_set, print_request=True): + """Print a given mode (do/dump/event/notify).""" + mode_title = mode.capitalize() + + if print_request and 'request' in mode_spec and 'attributes' in mode_spec['request']: + print(f'\n{mode_title} request attributes:') + print_attr_list(mode_spec['request']['attributes'], attr_set) + + if 'reply' in mode_spec and 'attributes' in mode_spec['reply']: + print(f'\n{mode_title} reply attributes:') + print_attr_list(mode_spec['reply']['attributes'], attr_set) + + if 'attributes' in mode_spec: + print(f'\n{mode_title} attributes:') + print_attr_list(mode_spec['attributes'], attr_set) + + if 'mcgrp' in mode_spec: + print(f"Multicast group: {op.yaml['mcgrp']}") + if args.list_ops: for op_name, op in ynl.ops.items(): print(op_name, " [", ", ".join(op.modes), "]")@@ -135,6 +172,24 @@ def main(): for op_name, op in ynl.msgs.items(): print(op_name, " [", ", ".join(op.modes), "]") + if args.list_attrs: + op = ynl.msgs.get(args.list_attrs) + if not op: + print(f'Operation {args.list_attrs} not found') + exit(1) + + print(f'Operation: {op.name}')
tools/net/ynl/pyynl/cli.py def main(): · line 191
Quoted 10 lines
tools/net/ynl/pyynl/cli.py +10
-0+ + for mode in ['do', 'dump', 'event']: + if mode in op.yaml: + print_mode_attrs(mode, op.yaml[mode], op.attr_set, True) + + if 'notify' in op.yaml: + mode_spec = op.yaml['notify'] + ref_spec = ynl.msgs.get(mode_spec).yaml.get('do') + if ref_spec: + print_mode_attrs(mode, ref_spec, op.attr_set, False)
I guess mode is set to 'event' after the for loop. I'd prefer to not see it used outside the loop, and just use literal 'event' here.
Quoted 4 lines
tools/net/ynl/pyynl/cli.py +1
-0+ try: if args.do: reply = ynl.do(args.do, attrs, args.flags)
Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
Quoted 15 lines · Donald Hunter
Quoted 4 lines
tools/net/ynl/pyynl/cli.py +4
-0+ def print_attr_list(attr_names, attr_set): + """Print a list of attributes with their types and documentation.""" + for attr_name in attr_names: + if attr_name in attr_set.attrs:tools/net/ynl/pyynl/cli.py def main(): · line 147
Quoted 10 lines
tools/net/ynl/pyynl/cli.py +10
-0+ attr = attr_set.attrs[attr_name] + attr_info = f' - {attr_name}: {attr.type}' + if 'enum' in attr.yaml: + attr_info += f" (enum: {attr.yaml['enum']})" + if attr.yaml.get('doc'): + doc_text = textwrap.indent(attr.yaml['doc'], ' ') + attr_info += f"\n{doc_text}" + print(attr_info) + else: + print(f' - {attr_name}')
Quoted 2 lines
Does this line execute? I think this scenario indicates a malformed spec that would fail codegen.
You're right, removed.
Quoted 12 lines
Quoted 12 lines
tools/net/ynl/pyynl/cli.py +12
-0+ if args.list_attrs: + op = ynl.msgs.get(args.list_attrs) + if not op: + print(f'Operation {args.list_attrs} not found') + exit(1) + + print(f'Operation: {op.name}') + + for mode in ['do', 'dump', 'event']: + if mode in op.yaml: + print_mode_attrs(mode, op.yaml[mode], op.attr_set, True) +
Quoted 8 lines
tools/net/ynl/pyynl/cli.py def main(): · line 191
Quoted 5 lines
tools/net/ynl/pyynl/cli.py +5
-0+ if 'notify' in op.yaml: + mode_spec = op.yaml['notify'] + ref_spec = ynl.msgs.get(mode_spec).yaml.get('do') + if ref_spec: + print_mode_attrs(mode, ref_spec, op.attr_set, False)I guess mode is set to 'event' after the for loop. I'd prefer to not see it used outside the loop, and just use literal 'event' here.
This is actually a bug, mode needs to be 'notify'.
Jakub Kicinski
maintainerRe: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
In reply to Gal PressmanQuoted 26 lines · On Sun, 16 Nov 2025 21:28:43 +0200 Gal Pressman wrote:
Add a --list-attrs option to the YNL CLI that displays information about netlink operations, including request and reply attributes. This eliminates the need to manually inspect YAML spec files to determine the JSON structure required for operations, or understand the structure of the reply.
Example usage:
# ./cli.py --family netdev --list-attrs dev-get Operation: dev-getDo request attributes:
- ifindex: u32
netdev ifindexDo reply attributes:
- ifindex: u32
netdev ifindex
- xdp-features: u64 (enum: xdp-act)
Bitmask of enabled xdp-features.
- xdp-zc-max-segs: u32
max fragment count supported by ZC driver
- xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
Bitmask of supported XDP receive metadata features. SeeDocumentation/networking/xdp-rx-metadata.rstfor more details.
- xsk-features: u64 (enum: xsk-flags)
Bitmask of enabledAF_XDPfeatures.
Quoted 11 lines
Dump reply attributes:
- ifindex: u32
netdev ifindex
- xdp-features: u64 (enum: xdp-act)
Bitmask of enabled xdp-features.
- xdp-zc-max-segs: u32
max fragment count supported by ZC driver
- xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
Bitmask of supported XDP receive metadata features. SeeDocumentation/networking/xdp-rx-metadata.rstfor more details.
- xsk-features: u64 (enum: xsk-flags)
Bitmask of enabledAF_XDPfeatures.
Could you try to detect that do and dump replies are identical and combine them? They are the same more often than not so I think it'd be nice to avoid printing the same info twice.
Quoted 28 lines
Reviewed-by Nimrod Oren <[email protected]>Signed-off-by Gal Pressman <[email protected]>--- tools/net/ynl/pyynl/cli.py | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)tools/net/ynl/pyynl/cli.py +3
-0@@ -7,6 +7,7 @@ import os import pathlib import pprint import sys +import textwrap sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix()) from lib import YnlFamily, Netlink, NlError@@ -70,6 +71,8 @@ def main(): group.add_argument('--dump', dest='dump', metavar='DUMP-OPERATION', type=str) group.add_argument('--list-ops', action='store_true') group.add_argument('--list-msgs', action='store_true') + group.add_argument('--list-attrs', dest='list_attrs', metavar='OPERATION', type=str, + help='List attributes for an operation') parser.add_argument('--duration', dest='duration', type=int, help='when subscribed, watch for DURATION seconds')
tools/net/ynl/pyynl/cli.py def main(): · line 134
Quoted 4 lines
tools/net/ynl/pyynl/cli.py +1
-0@@ -128,6 +131,40 @@ def main(): if args.ntf: ynl.ntf_subscribe(args.ntf) + def print_attr_list(attr_names, attr_set):
It nesting functions inside main() a common pattern for Python? Having a function declared in the middle of another function, does not seem optimal to me, but for some reason Claude loves to do that.
Quoted 14 lines
tools/net/ynl/pyynl/cli.py +14
-0+ """Print a list of attributes with their types and documentation.""" + for attr_name in attr_names: + if attr_name in attr_set.attrs: + attr = attr_set.attrs[attr_name] + attr_info = f' - {attr_name}: {attr.type}' + if 'enum' in attr.yaml: + attr_info += f" (enum: {attr.yaml['enum']})" + if attr.yaml.get('doc'): + doc_text = textwrap.indent(attr.yaml['doc'], ' ') + attr_info += f"\n{doc_text}" + print(attr_info) + else: + print(f' - {attr_name}') +
Donald Hunter
maintainerRe: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
Quoted 8 lines · Jakub Kicinski
Quoted 2 lines · On Sun, 16 Nov 2025 21:28:43 +0200 Gal Pressman wrote:
+ def
print_attr_list(attr_names, attr_set):It nesting functions inside
main()a common pattern for Python? Having a function declared in the middle of another function, does not seem optimal to me, but for some reason Claude loves to do that.
It's common for closure-like things and for scoping. Reviewing this again, these add a lot of noise to main() and would be better separated out.
To be fair, I started it with def output(msg) but I'd argue it is a closure-like scoped helper thing :-)
Quoted 14 lines
Quoted 14 lines
tools/net/ynl/pyynl/cli.py +14
-0+ """Print a list of attributes with their types and documentation.""" + for attr_name in attr_names: + if attr_name in attr_set.attrs: + attr = attr_set.attrs[attr_name] + attr_info = f' - {attr_name}: {attr.type}' + if 'enum' in attr.yaml: + attr_info += f" (enum: {attr.yaml['enum']})" + if attr.yaml.get('doc'): + doc_text = textwrap.indent(attr.yaml['doc'], ' ') + attr_info += f"\n{doc_text}" + print(attr_info) + else: + print(f' - {attr_name}') +
Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
In reply to Jakub KicinskiQuoted 24 lines · Jakub Kicinski
Quoted 12 lines
Do reply attributes:
- ifindex: u32
netdev ifindex
- xdp-features: u64 (enum: xdp-act)
Bitmask of enabled xdp-features.
- xdp-zc-max-segs: u32
max fragment count supported by ZC driver
- xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
Bitmask of supported XDP receive metadata features. SeeDocumentation/networking/xdp-rx-metadata.rstfor more details.
- xsk-features: u64 (enum: xsk-flags)
Bitmask of enabledAF_XDPfeatures.Quoted 11 lines
Dump reply attributes:
- ifindex: u32
netdev ifindex
- xdp-features: u64 (enum: xdp-act)
Bitmask of enabled xdp-features.
- xdp-zc-max-segs: u32
max fragment count supported by ZC driver
- xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
Bitmask of supported XDP receive metadata features. SeeDocumentation/networking/xdp-rx-metadata.rstfor more details.
- xsk-features: u64 (enum: xsk-flags)
Bitmask of enabledAF_XDPfeatures.
Quoted 3 lines
Could you try to detect that do and dump replies are identical and combine them? They are the same more often than not so I think it'd be nice to avoid printing the same info twice.
We need to take care of both cases where the whole operation is identical (e.g., ethtool debug-get), and cases where only the replies are identical (e.g., netdev dev-get). This kind of complicates the code.
I'll give it a few more attempts, but maybe this should come as a followup to this series.
Quoted 10 lines
tools/net/ynl/pyynl/cli.py def main(): · line 134
Quoted 5 lines
tools/net/ynl/pyynl/cli.py +1
-0@@ -128,6 +131,40 @@ def main(): if args.ntf: ynl.ntf_subscribe(args.ntf) + def print_attr_list(attr_names, attr_set):It nesting functions inside
main()a common pattern for Python? Having a function declared in the middle of another function, does not seem optimal to me, but for some reason Claude loves to do that.
I used output() as a reference, but I'll move it outside.
Jakub Kicinski
maintainerRe: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
Quoted 7 lines · On Tue, 18 Nov 2025 11:38:04 +0200 Gal Pressman wrote:
Quoted 3 lines
Could you try to detect that do and dump replies are identical and combine them? They are the same more often than not so I think it'd be nice to avoid printing the same info twice.
We need to take care of both cases where the whole operation is identical (e.g., ethtool debug-get), and cases where only the replies are identical (e.g., netdev dev-get). This kind of complicates the code.
I was thinking just the reply. This is mostly for GET type operations. Request doesn't exist for DUMP, but for DO it carries ID.
Quoted 2 lines
I'll give it a few more attempts, but maybe this should come as a followup to this series.
Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
Quoted 11 lines · Jakub Kicinski
Quoted 7 lines · On Tue, 18 Nov 2025 11:38:04 +0200 Gal Pressman wrote:
Quoted 3 lines
Could you try to detect that do and dump replies are identical and combine them? They are the same more often than not so I think it'd be nice to avoid printing the same info twice.
We need to take care of both cases where the whole operation is identical (e.g., ethtool debug-get), and cases where only the replies are identical (e.g., netdev dev-get). This kind of complicates the code.
I was thinking just the reply. This is mostly for GET type operations. Request doesn't exist for DUMP, but for DO it carries ID.
Some dumps have requests, like ethtool's debug-get or strset-get. I have a patch that detects identical replies, but it's quite ugly TBH. I'd prefer to keep the code as is, but up to you.
Jakub Kicinski
maintainerRe: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
Quoted 6 lines · On Wed, 19 Nov 2025 13:36:09 +0200 Gal Pressman wrote:
Quoted 5 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 18 Nov 2025 11:38:04 +0200 Gal Pressman wrote:
We need to take care of both cases where the whole operation is identical (e.g., ethtool debug-get), and cases where only the replies are identical (e.g., netdev dev-get). This kind of complicates the code.
Quoted 6 lines
Quoted 2 lines
I was thinking just the reply. This is mostly for GET type operations. Request doesn't exist for DUMP, but for DO it carries ID.
Some dumps have requests, like ethtool's debug-get or strset-get. I have a patch that detects identical replies, but it's quite ugly TBH. I'd prefer to keep the code as is, but up to you.
It's alright. I'll poke at it after merging, but if we can't find a clean way it's fine.
Jakub Kicinski
maintainerRe: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
In reply to Gal PressmanQuoted 5 lines · On Sun, 16 Nov 2025 21:28:43 +0200 Gal Pressman wrote:
Add a --list-attrs option to the YNL CLI that displays information about netlink operations, including request and reply attributes. This eliminates the need to manually inspect YAML spec files to determine the JSON structure required for operations, or understand the structure of the reply.
I _think_ these two pylint issues are new / should be fixed:
tools/net/ynl/pyynl/cli.py:166:0: W0311: Bad indentation. Found 16 spaces, expected 12 (bad-indentation)
tools/net/ynl/pyynl/cli.py:166:42: E0606: Possibly using variable 'op' before assignment (possibly-used-before-assignment)
Signature · 1 line
pw-bot: cr
Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
Quoted 7 lines · Jakub Kicinski
Quoted 5 lines · On Sun, 16 Nov 2025 21:28:43 +0200 Gal Pressman wrote:
Add a --list-attrs option to the YNL CLI that displays information about netlink operations, including request and reply attributes. This eliminates the need to manually inspect YAML spec files to determine the JSON structure required for operations, or understand the structure of the reply.
Quoted 5 lines
I _think_ these two pylint issues are new / should be fixed:
tools/net/ynl/pyynl/cli.py:166:0: W0311: Bad indentation. Found 16 spaces, expected 12 (bad-indentation)
tools/net/ynl/pyynl/cli.py:166:42: E0606: Possibly using variable 'op' before assignment (possibly-used-before-assignment)
Will do.
PATCH 2/3 tools: ynl: cli: Parse nested attributes in --list-attrs output
In reply to Gal PressmanEnhance the --list-attrs option to recursively display nested attributes instead of just showing "nest" as the type.
Nested attributes now show their attribute set name and expand to display their contents.
# ./cli.py --family ethtool --list-attrs rss-get
[..]
Do request attributes:
- header: nest -> header
- dev-index: u32
- dev-name: string
- flags: u32 (enum: header-flags)
- phy-index: u32
- context: u32
[..]--- tools/net/ynl/pyynl/cli.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
tools/net/ynl/pyynl/cli.py +21 -4
@@ -131,20 +131,37 @@ def main(): if args.ntf: ynl.ntf_subscribe(args.ntf) - def print_attr_list(attr_names, attr_set): + def print_attr_list(attr_names, attr_set, indent=2): """Print a list of attributes with their types and documentation.""" + prefix = ' ' * indent for attr_name in attr_names: if attr_name in attr_set.attrs: attr = attr_set.attrs[attr_name] - attr_info = f' - {attr_name}: {attr.type}' + attr_info = f'{prefix}- {attr_name}: {attr.type}' if 'enum' in attr.yaml: attr_info += f" (enum: {attr.yaml['enum']})" + + # Show nested attributes reference and recursively display them + nested_set_name = None + if attr.type == 'nest' and 'nested-attributes' in attr.yaml: + nested_set_name = attr.yaml['nested-attributes'] + attr_info += f" -> {nested_set_name}" + if attr.yaml.get('doc'): - doc_text = textwrap.indent(attr.yaml['doc'], ' ') + doc_text = textwrap.indent(attr.yaml['doc'], prefix + ' ') attr_info += f"\n{doc_text}" print(attr_info) + + # Recursively show nested attributes + if nested_set_name in ynl.attr_sets: + nested_set = ynl.attr_sets[nested_set_name] + # Filter out 'unspec' and other unused attrs + nested_names = [n for n in nested_set.attrs.keys() + if nested_set.attrs[n].type != 'unused'] + if nested_names: + print_attr_list(nested_names, nested_set, indent + 4) else: - print(f' - {attr_name}') + print(f'{prefix}- {attr_name}') def print_mode_attrs(mode, mode_spec, attr_set, print_request=True): """Print a given mode (do/dump/event/notify)."""
Signature · 1 line
2.40.1
Re: [PATCH net-next 2/3] tools: ynl: cli: Parse nested attributes in --list-attrs output
Quoted 16 lines · Gal Pressman
Enhance the --list-attrs option to recursively display nested attributes instead of just showing "nest" as the type.
Nested attributes now show their attribute set name and expand to display their contents.# ./cli.py --family ethtool --list-attrs rss-get [..] Do request attributes: - header: nest -> header - dev-index: u32 - dev-name: string - flags: u32 (enum: header-flags) - phy-index: u32 - context: u32 [..]
Quoted 2 lines
Reviewed-by Nimrod Oren <[email protected]>Signed-off-by Gal Pressman <[email protected]>
PATCH 3/3 tools: ynl: cli: Display enum values in --list-attrs output
In reply to Gal PressmanWhen 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)
Values: basic, redirect, ndo-xmit, xsk-zerocopy, hw-offload, rx-sg, ndo-xmit-sg
Bitmask of enabled xdp-features.
[..]--- tools/net/ynl/pyynl/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/net/ynl/pyynl/cli.py +6 -1
@@ -139,7 +139,12 @@ def main(): 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: + enum_values = list(ynl.consts[enum_name].entries.keys()) + attr_info += f"\n{prefix} Values: {', '.join(enum_values)}" # Show nested attributes reference and recursively display them nested_set_name = None
Signature · 1 line
2.40.1
Donald Hunter
maintainerRe: [PATCH net-next 3/3] tools: ynl: cli: Display enum values in --list-attrs output
Quoted 21 lines · Gal Pressman
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) Values: basic, redirect, ndo-xmit, xsk-zerocopy, hw-offload, rx-sg, ndo-xmit-sg Bitmask of enabled xdp-features. [..]Reviewed-by Nimrod Oren <[email protected]>Signed-off-by Gal Pressman <[email protected]>--- tools/net/ynl/pyynl/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)tools/net/ynl/pyynl/cli.py +0
-0
tools/net/ynl/pyynl/cli.py def main(): · line 143
Quoted 6 lines
tools/net/ynl/pyynl/cli.py +2
-1@@ -139,7 +139,12 @@ def main(): 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})"
Would be good to say enum | flags so that people know what semantics are valid.
tools/net/ynl/pyynl/cli.py def main(): · line 147
Quoted 4 lines
tools/net/ynl/pyynl/cli.py +4
-0+ # Print enum values if available + if enum_name in ynl.consts: + enum_values = list(ynl.consts[enum_name].entries.keys()) + attr_info += f"\n{prefix} Values: {', '.join(enum_values)}"
This produces quite noisy output for e.g.
./tools/net/ynl/pyynl/cli.py --family ethtool --list-attrs rss-get
Not sure what to suggest to improve readability but maybe it doesn't need 'Values:' or commas, or perhaps only output each enum once?
Quoted 3 lines
tools/net/ynl/pyynl/cli.py +0
-0# Show nested attributes reference and recursively display them nested_set_name = None
Re: [PATCH net-next 3/3] tools: ynl: cli: Display enum values in --list-attrs output
Quoted 5 lines · Donald Hunter
Quoted 5 lines
tools/net/ynl/pyynl/cli.py +0
-0@@ -139,7 +139,12 @@ def main():
Quoted 8 lines
tools/net/ynl/pyynl/cli.py def main(): · line 143
Quoted 6 lines
tools/net/ynl/pyynl/cli.py +2
-1attr = 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})"Would be good to say enum | flags so that people know what semantics are valid.
I changed "Values: " to "enum:"/"flags:".
Quoted 6 lines
tools/net/ynl/pyynl/cli.py def main(): · line 147
Quoted 5 lines
tools/net/ynl/pyynl/cli.py +4
-0+ # Print enum values if available + if enum_name in ynl.consts: + enum_values = list(ynl.consts[enum_name].entries.keys()) + attr_info += f"\n{prefix} Values: {', '.join(enum_values)}"
Quoted 6 lines
This produces quite noisy output for e.g.
./tools/net/ynl/pyynl/cli.py--family ethtool --list-attrs rss-getNot sure what to suggest to improve readability but maybe it doesn't need 'Values:' or commas, or perhaps only output each enum once?
Values was replaced, I don't see how removing the commas improves the situation.