diff options
| author | Jakub Kicinski <kuba@kernel.org> | 2026-01-10 15:31:41 -0800 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2026-01-12 13:29:31 -0800 |
| commit | 6ccc421b14613aac32b2647462ae4d40f5dd43b8 (patch) | |
| tree | a480e2e11fded31c3a656b4c58b685f493939a54 | |
| parent | 45b99bb464eb62da555ecbef31583d9701881d43 (diff) | |
tools: ynl: cli: extract the event/notify handling in --list-attrs
Event and notify handling is quite different from do / dump
handling. Forcing it into print_mode_attrs() doesn't really
buy us anything as events and notifications do not have requests.
Call print_attr_list() directly. Apart form subjective code
clarity this also removes the word "reply" from the output:
Before:
Event reply attributes:
Now:
Event attributes:
Tested-by: Gal Pressman <gal@nvidia.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/20260110233142.3921386-7-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
| -rwxr-xr-x | tools/net/ynl/pyynl/cli.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py index 6975efa7874f..6d2f0412dde0 100755 --- a/tools/net/ynl/pyynl/cli.py +++ b/tools/net/ynl/pyynl/cli.py @@ -120,11 +120,11 @@ def print_attr_list(ynl, attr_names, attr_set, indent=2): print_attr_list(ynl, nested_names, nested_set, indent + 4) -def print_mode_attrs(ynl, mode, mode_spec, attr_set, print_request=True): +def print_mode_attrs(ynl, mode, mode_spec, attr_set): """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']: + if 'request' in mode_spec and 'attributes' in mode_spec['request']: print(f'\n{mode_title} request attributes:') print_attr_list(ynl, mode_spec['request']['attributes'], attr_set) @@ -132,25 +132,28 @@ def print_mode_attrs(ynl, mode, mode_spec, attr_set, print_request=True): print(f'\n{mode_title} reply attributes:') print_attr_list(ynl, mode_spec['reply']['attributes'], attr_set) - if 'attributes' in mode_spec: - print(f'\n{mode_title} attributes:') - print_attr_list(ynl, mode_spec['attributes'], attr_set) - def do_doc(ynl, op): """Handle --list-attrs $op, print the attr information to stdout""" print(f'Operation: {color(op.name, Colors.BOLD)}') print(op.yaml['doc']) - for mode in ['do', 'dump', 'event']: + for mode in ['do', 'dump']: if mode in op.yaml: - print_mode_attrs(ynl, mode, op.yaml[mode], op.attr_set, True) + print_mode_attrs(ynl, mode, op.yaml[mode], op.attr_set) + + if 'attributes' in op.yaml.get('event', {}): + print('\nEvent attributes:') + print_attr_list(ynl, op.yaml['event']['attributes'], op.attr_set) if 'notify' in op.yaml: mode_spec = op.yaml['notify'] ref_spec = ynl.msgs.get(mode_spec).yaml.get('do') + if not ref_spec: + ref_spec = ynl.msgs.get(mode_spec).yaml.get('dump') if ref_spec: - print_mode_attrs(ynl, 'notify', ref_spec, op.attr_set, False) + print('\nNotification attributes:') + print_attr_list(ynl, ref_spec['reply']['attributes'], op.attr_set) if 'mcgrp' in op.yaml: print(f"\nMulticast group: {op.yaml['mcgrp']}") |
