Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow UCM commands to have “unprocessed” arguments #5549

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

sellout
Copy link
Contributor

@sellout sellout commented Jan 17, 2025

Overview

There are some commands (like run) that don’t want expanded arguments passed to them. E.g., run main 1 should pass “1” to main, not the numbered result from a previous command.

Fixes #2805

Implementation notes

This makes a couple changes. First, it creates a Parameters structure that gives a more precise definition of the arguments a command can receive, and eliminates incorrect parameter definitions. It then adds an isStructured field to the ParameterType (née ArgumentType) record, which indicates whether arguments to parameters of that type should be parsed & have numbers expanded.

One of the complicated bits (as seen in foldParamsWithM) is that an “input argument” can be expanded to multiple arguments, and we have to process the arguments left to right, because we don’t know which parameter an argument applies to until after we’ve expanded all the ones ahead of it.

Test coverage

This adds a transcript for run that shows the new behavior (as best we can without capturing run output in transcripts).

Loose ends

This is an improved version of the first half of #5480, which also “fixed” #5193. The work here is also progress toward #5193, but the approach in #5480 isn’t great.

The new transcript here also explicitly use lib.install @unison/base, despite being in the transcripts-using-base directory, which I would think would make that unnecessary.

It shows that we can’t pass numbers to `run`.

**NB**: I don’t think this should `lib.install @unison/base`, but
otherwise the transcript fails to find any definitions.
- distinguish between “parameters” and “arguments” – a command has a
  fixed number of parameters, each of which maps to some number of
  arguments (from 0 to many, depending on the parameter)
- change the type of parameters to eliminate invalid parameter structures
- require `InputPattern` parameters to cover all arguments (there are a
  number of commands whose parameters were under-specified).
This allows us to incrementally expand numbered arguments, only doing so when
we want a Unison value and not unstructured text.

Fixes unisonweb#2805.
Now that the arguments to `parse` are universally checked, the
individual parsers don’t need to handle the cases as precisely.
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.

ucm run : Numeric arguments are changed to find results
1 participant