Skip to content

Comments

Rework list-exported-commands and fix embed/statement parsing#39

Merged
maxim-uvarov merged 14 commits intomainfrom
list-exported-commands-rework
Feb 12, 2026
Merged

Rework list-exported-commands and fix embed/statement parsing#39
maxim-uvarov merged 14 commits intomainfrom
list-exported-commands-rework

Conversation

@maxim-uvarov
Copy link
Member

@maxim-uvarov maxim-uvarov commented Feb 12, 2026

Summary

  • Refactor list-exported-commands into two focused commands: extract-exported-commands (AST-based export detection) and list-module-interface / list-module-exports, replacing fragile regex patterns
  • Fix split-statements to count braces correctly, handling match blocks and multi-brace tokens
  • Fix examples-update to parse list/record result values (bracket depth tracking) and escape $ to prevent regex backreference loss
  • Fix extract-exported-commands to strip single quotes from export use entries
  • Add tests for list-module-interface (3 tests) and update coverage fixture (was stale on main)
  • Chore: Nushell style fixes, $nu.temp-dir migration, README formatting, regression tests

Test plan

  • nu toolkit.nu test passes (72 passed, 0 failed)
  • Verify list-module-exports and list-module-interface produce correct output on real modules
  • Verify examples-update handles $-containing and list/record result values

🤖 Generated with Claude Code

maxim-uvarov and others added 14 commits January 9, 2026 22:57
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add AST-based detection for selective re-export syntax used in mod.nu
files. When --export flag is used and no 'export def' statements are
found, fall back to parsing 'export use module.nu [commands]' pattern
to extract the re-exported command names.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ands

Replace mixed regex/AST approach with a single function that handles both
`export def` and `export use [...commands]` patterns using AST parsing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
BREAKING CHANGE: Remove `list-exported-commands` command.

Replace with two specialized commands:
- `list-module-exports` - lists all exported definitions (export def + export use)
- `list-module-interface` - lists module's callable interface (main commands)

This provides clearer separation between finding what a module exports
vs what commands become available when using a module.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The str replace -r command interprets $ as a regex backreference,
causing result values containing $ to lose those characters. Escaping
$ as $$ before replacement preserves the literal dollar signs.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…racket depth

Previously only the first token `[` was captured when parsing --result values
like `['no-run' 'try']`. Now tracks bracket depth to find matching closing
bracket for proper parsing of list and record result values.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add three regression tests to prevent reintroduction of fixed bugs:
- find-examples parses list result values (bracket depth fix)
- find-examples parses record result values (bracket depth fix)
- examples-update preserves dollar signs in results ($ escaping fix)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…i-brace tokens

The depth tracker had two bugs:
- Tokens with both { and } were assumed net-zero, but a token like
  "{ }\n}" (else block + closing brace) has net -1
- match block opening braces appear as shape_gap, not shape_block,
  so they were invisible to depth tracking

Count all { and } in shape_block, shape_closure, and shape_gap tokens
instead of binary has/hasn't check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…commands

`export use` with single-quoted names (e.g., `'capture start'`) were not
getting quotes stripped, causing mismatches with the dependency graph.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@maxim-uvarov maxim-uvarov merged commit 6132372 into main Feb 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants