dotbot/cli: read swarm group options only before the subcommand - #299
Merged
Merged
Conversation
`flash -s` is `--start`, but every token was scanned, so it read as `--swarm-id` and the config swarm id was never injected. The same boundary lets `flash <name>` resolve after group options such as `-d`. AI-assisted: Claude Opus 5.5
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #299 +/- ##
==========================================
+ Coverage 84.65% 84.71% +0.05%
==========================================
Files 204 204
Lines 25336 25410 +74
Branches 1822 1821 -1
==========================================
+ Hits 21449 21526 +77
+ Misses 3880 3876 -4
- Partials 7 8 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Symptom
dotbot swarm flash -y -s <file>did not pick up the swarm id from config. The same invocation without-sdid.Root cause
dotbot swarmprepends--conn/--swarm-idfrom the resolved config before handing the arguments to swarmit, unless the user already passed one of those flags. The "did the user pass it?" check scanned every token on the command line.-sis--swarm-idat the group level, but underflashit is--start, soflash -swas read as an explicit swarm id and the config value was never injected.Fix
The injection now only looks at the group options, the tokens before the subcommand name. A new
subcommand_index()walks the arguments using swarmit's own group definition, so it knows which group options take a value (-d ADDR,-sA001,--conn=..., short clusters like-vd ADDR) and stops at the first positional token. Anything after that belongs to the subcommand and can reuse short letters freely.--helpanywhere still disables injection.The same boundary fixes a second case:
flash <name>(resolving a bundled app name to its fetched.bin) only triggered whenflashwas the very first token. With group options in front, such asdotbot swarm -d <addr> flash <name>, the name was passed through unresolved. It now resolves wherever the subcommand sits.Open question for the reviewer
dotbot swarm -d X calibrate-lh2 ...is still not intercepted. Thecalibrate-lh2intercept only matches when it is the first token, so with a group option in front the command falls through to the swarmit passthrough instead of the PyDotBot-native handler that carries the resolved config. Routing it through the intercept as-is would silently drop-d. My recommendation is an explicit error ("group options are not supported beforecalibrate-lh2") rather than a silent drop, but I left it out of this PR to keep it to the injection fix. Happy to add it here if you prefer.Validation
Unit tests in
dotbot/tests/test_cli_swarm_inject.pyagainst a stub group shaped like swarmit's:flash -sno longer counts as a swarm id, group-level-s/--swarm-id/ attached-sA001still win over config,-dvalues and short clusters are skipped correctly, andflash <name>resolves after-d. Not run against a live swarm.dotbot/cli/_swarm_inject.pydotbot/tests/test_cli_swarm_inject.pydotbot/cli/swarm.py