refactor: replace nested conditionals in get_var_attrs with declarative token registry - #178
Open
bhagathkrishnacdac wants to merge 1 commit into
Open
Conversation
…ve token registry Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
There was a problem hiding this comment.
Pull request overview
Refactors BESS CLI auto-completion token handling in bessctl by replacing a large conditional chain in get_var_attrs() with a declarative token registry and helper candidate fetchers, aiming to simplify maintenance of completion behavior.
Changes:
- Introduced helper fetchers (
_fetch_candidates,_get_workers,_get_ports, etc.) to centralize RPC-backed candidate collection. - Added a
TOKEN_REGISTRYmapping tokens to(type, description, provider)to eliminate the largeif/elifchain. - Simplified
get_var_attrs()into a registry lookup + provider dispatch.
Suppressed comments (2)
bessctl/commands.py:285
[PORT_NUMBER]describes a port number but the text says "HTTP server address". This is user-facing help text shown during CLI guidance, so it should refer to the port.
'[PORT_NUMBER]': ('int', 'HTTP server address to listen on (default: 5000)', []),
bessctl/commands.py:283
[PAUSE_WORKERS]description dropped the default value information that existed previously, which is useful in the interactive help output. Consider restoring the default note.
'[PAUSE_WORKERS]': ('pause_workers', 'determines whether to pause workers',
['pause', 'no_pause']),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+300
to
+301
| import inspect | ||
| sig = inspect.signature(provider) |
Comment on lines
+277
to
+280
| '[TCPDUMP_OPTS...]': ('opts', 'tcpdump(1) command-line options', []), | ||
| '[TSHARK_OPTS...]': ('opts', 'tshark(1) command-line options', []), | ||
| '[GRAPHEASY_OPTS...]': ('opts', 'graph-easy(1p) command-line options', []), | ||
| '[BESSD_OPTS...]': ('opts', 'bess daemon command-line options', []), |
Comment on lines
+200
to
+204
| try: | ||
| return processor(func()) | ||
| except (AttributeError, Exception): | ||
| # We ignore errors here as this is only for CLI auto-completion | ||
| return [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors commands.py for improved code quality. This PR focuses on refactoring the CLI auto-completion logic to eliminate a massive if/elif chain in get_var_attrs.
Key Changes