feat:add filter/sort/limit to | shell completion | download #793
+1,425
−128
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.
feat: Add filter and output to subnets & metagraph,shell completion
Summary
This PR adds advanced filtering, sorting, column-selection, limiting, and structured output options to the
subnets listcommand and extends the same usability flags to thesubnets metagraphcommand. It also introduces a top-levelbtcli completioncommand for easy shell completion installation and a set of improvements to output handling and documentation.Description of Changes
btcli completioncommand to generate and optionally install shell completion scripts for Bash, Zsh, Fish, and PowerShell. README updated with instructions.subnets listcommand with many usability flags (filter, sort, limit, columns, output format, pager, header control, wide mode).subnets metagraphcommand so users can filter/sort/limit neurons, select columns, and export JSON/YAML.subnets listandsubnets metagraph.BTCLI_PAGERenvironment variable to page large table outputs.Motivation and Context
Working with large subnet lists or full metagraphs can be cumbersome. These changes give users granular control over list-like outputs (filtering, sorting, limiting, and column selection), allow structured export (JSON/YAML), and improve developer experience via modular helpers and tests. Shell completion increases productivity for interactive use.
Files Changed (high level)
README.md— shell completion docs and output tipsbittensor_cli/cli.py— added flags and validation,completioncommand, pass-through of new optionsbittensor_cli/src/commands/subnets/subnets.py—filter_sort_limit_subnets(existing commit) andfilter_sort_limit_metagraph_rowshelperssubnets_listandmetagraph_cmdto accept and honor new options (output, columns, no-header, wide, uids/hotkey-contains, sort-by, sort-order, limit)BTCLI_PAGERis settests/unit_tests/test_subnets_list_sort_filter.py— unit tests for subnets list helpertests/unit_tests/test_metagraph_list_sort_filter.py— unit tests for metagraph helper (new)(See commit for exact diffs and line-level changes.)
New CLI Flags (examples)
--netuids/-n--uids/-u--name-contains/--name--hotkey-contains/--hotkey--sort-by--sort-orderasc) or descending (desc).--limit/--top--output/-otable,json,yaml. Overrides legacy--json-output.--columns--no-header--wide/-wUsage Examples
Filter + sort + limit (subnets):
btcli subnets list \ --netuids 0,2 \ --name-contains "AI" \ --sort-by market_cap \ --sort-order desc \ --limit 5 \ --output json \ --columns netuid,name,market_cap \ --no-header \ --wideMetagraph: list top 10 neurons by global stake for a subnet, output as YAML:
Metagraph: filter by hotkey substring and show columns in a wide table:
Shell completion installation (examples):
Testing Performed
btcli completionfor supported shells (script output and--install).subnets listandsubnets metagraphwith combinations of filters,--columns,--output,--limit, and--wide.tests/unit_tests/test_subnets_list_sort_filter.py(existing)tests/unit_tests/test_metagraph_list_sort_filter.py(new)To run the new tests locally:
Backwards compatibility & notes
--outputflag supersedes--json-outputwhen provided; legacy--json-outputbehavior is preserved unless overridden by--output.--html(metagraph) is mutually exclusive with structuredjson/yamloutputs.--columnsoverrides the per-user configmetagraph_colsfor that invocation only.