Reusable create_table() Utility for Consistent Table Styling
#790
+91
−153
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 introduces a new
create_table()utility function that eliminates code duplication and ensures consistent table styling throughout the CLI. The function reduces repetitive table configuration code from 11+ lines down to 1-4 lines while maintaining full flexibility.Changes
New Utility Function
Added
create_table()tobittensor_cli/src/bittensor/utils.py:Refactored Locations
Updated three table creation sites in
bittensor_cli/src/commands/subnets/subnets.py:subnets_list()functionExamples
Pattern 1: Simple Table (Add Columns Later)
Before (11 lines):
After (2 lines):
Pattern 2: Table with Column Objects
Before (17 lines):
After (8 lines):
Pattern 3: Custom Overrides
Visual Examples
Here's how the tables look when rendered:
Manual Verification
Tested actual usage in the CLI commands:
Breaking Changes
None.
Files Changed
bittensor_cli/src/bittensor/utils.py- Addedcreate_table()functionbittensor_cli/src/commands/subnets/subnets.py- Refactored 3 table creationsbittensor_cli/src/commands/stake/bittensor_cli/src/commands/liquidity/bittensor_cli/src/commands/crowd/Contribution by Gittensor, learn more at https://gittensor.io/