Support unprocessed UCM command arguments #5470
Closed
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.
Overview
Give
InputPattern
s access to the originalString
arguments, before expanding numbers or fuzzy resolution. This means that literal numbers can now be provided to commands that take advantage of this (notablyrun
).Fixes #2805.
Implementation notes
Previously
unsupportedStructuredArg
was used to error if an argument that shouldn’t be a numbered arg was. That has been replaced with accesses of the original number provided in the UCM command.Interesting/controversial decisions
Some zero-argument commands used to just ignore extra arguments. They now consistently fail if extra args are provided. This is trivial to revert if it goes against the intention of those commands.
Test coverage
Unfortunately, Unison doesn’t capture
run
output in transcripts, so this isn’t very testable, but the following example (from #2805) now does the expected thing:Loose ends
This is a draft because I’m not 100% sold on the implementation (but it was easy).
The most serious issue is that the list of unprocessed arguments doesn’t necessarily line up with the expanded arguments. This is because of ranges.
find 1-3
has 1 unprocessed argument (the string"1-3"
), but 0-3 processed arguments (the first three numbered args from a previous result). This is an issue for commands likerun
, where the first arg gets processed, but latter ones aren’t. E.g., with the changes in this PRrun 1 2 3 4
will expand1
to the appropriate numbered arg, then pass"2" 3" "4"
as command-line args;run 1–3 4
will expand1-3
to numbered args, use the first as the function, discard the rest, and pass"4"
as a command-line arg (this might be fine, but maybe it should error); butdisplay.to 1-3 4
definitely misbehaves – It uses1-3
as a filename (correct), but then displays numbered args 2–4 to the file, rather than just numbered arg4
. This is because the string args are["1-3", "4"]
and the processed args are[expandNumber 1, expandNumber 2, expandNumber 3, expandNumber 4]
. So when wetake
the first string arg anddrop
the first processed arg, we end up with overlap.A secondary issue is that we add the expanded form to the history, before knowing which arguments the command wants to expand. It executes the correct command, but using the history will result in the incorrect command in future.
The solution to both of these is to give each command the option to incrementally expand arguments as it wants them. The
standardParser
andbareParser
helpers will expand all or none, respectively, leaving just a handful of commands that need to explicitly manage that.