Skip to content

Commit 99d56f0

Browse files
committed
Add structured arg checking to ParameterType
This allows us to incrementally expand numbered arguments, only doing so when we want a Unison value and not unstructured text. Fixes unisonweb#2805.
1 parent 88cf6b3 commit 99d56f0

File tree

8 files changed

+273
-230
lines changed

8 files changed

+273
-230
lines changed

unison-cli/src/Unison/Codebase/Editor/HandleInput.hs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -714,31 +714,24 @@ loop e = do
714714
DebugFuzzyOptionsI command args -> do
715715
Cli.Env {codebase} <- ask
716716
currentBranch <- Branch.withoutTransitiveLibs <$> Cli.getCurrentBranch0
717-
maybe
718-
(Cli.respond $ DebugFuzzyOptionsNoCommand command)
719-
( \IP.InputPattern {params} ->
720-
either (Cli.respond . DebugFuzzyOptionsIncorrectArgs) snd $
721-
IP.foldArgs
722-
( \(paramName, IP.ParameterType {fzfResolver}) arg ->
723-
( *>
724-
if arg == "_"
725-
then
726-
maybe
727-
(Cli.respond DebugFuzzyOptionsNoResolver)
728-
( \IP.FZFResolver {getOptions} -> do
729-
pp <- Cli.getCurrentProjectPath
730-
results <- liftIO $ getOptions codebase pp currentBranch
731-
Cli.respond (DebugDisplayFuzzyOptions paramName (Text.unpack <$> results))
732-
)
733-
fzfResolver
734-
else pure ()
735-
)
736-
)
737-
(pure ())
738-
params
739-
args
740-
)
741-
$ Map.lookup command InputPatterns.patternMap
717+
case Map.lookup command InputPatterns.patternMap of
718+
Just IP.InputPattern {params} ->
719+
either (Cli.respond . DebugFuzzyOptionsIncorrectArgs) (pure . fst)
720+
=<< IP.foldParamsWithM
721+
( \_ (paramName, IP.ParameterType {fzfResolver}) arg ->
722+
if arg == "_"
723+
then case fzfResolver of
724+
Just IP.FZFResolver {getOptions} -> do
725+
pp <- Cli.getCurrentProjectPath
726+
results <- liftIO $ getOptions codebase pp currentBranch
727+
(,[]) <$> Cli.respond (DebugDisplayFuzzyOptions paramName (Text.unpack <$> results))
728+
Nothing -> (,[]) <$> Cli.respond DebugFuzzyOptionsNoResolver
729+
else pure ((), [])
730+
)
731+
()
732+
params
733+
args
734+
Nothing -> Cli.respond $ DebugFuzzyOptionsNoCommand command
742735
DebugFormatI -> do
743736
env <- ask
744737
void $ runMaybeT do

unison-cli/src/Unison/Codebase/Transcript/Runner.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ import Unison.Codebase.Transcript.Parser qualified as Transcript
4848
import Unison.Codebase.Verbosity (Verbosity, isSilent)
4949
import Unison.Codebase.Verbosity qualified as Verbosity
5050
import Unison.CommandLine
51-
import Unison.CommandLine.InputPattern (InputPattern (aliases, patternName))
52-
import Unison.CommandLine.InputPatterns (validInputs)
51+
import Unison.CommandLine.InputPattern (aliases, patternName)
52+
import Unison.CommandLine.InputPatterns qualified as IP
5353
import Unison.CommandLine.OutputMessages (notifyNumbered, notifyUser)
5454
import Unison.CommandLine.Welcome (asciiartUnison)
5555
import Unison.Parser.Ann (Ann)
@@ -174,7 +174,7 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL
174174
expectFailure <- newIORef False
175175
hasErrors <- newIORef False
176176
mBlock <- newIORef Nothing
177-
let patternMap = Map.fromList $ (\p -> (patternName p, p) : ((,p) <$> aliases p)) =<< validInputs
177+
let patternMap = Map.fromList $ (\p -> (patternName p, p) : ((,p) <$> aliases p)) =<< IP.validInputs
178178
let output' :: Bool -> Stanza -> IO ()
179179
output' inputEcho msg = do
180180
hide <- hideOutput inputEcho
@@ -326,7 +326,8 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL
326326
liftIO (parseInput codebase curPath getProjectRoot numberedArgs patternMap args)
327327
>>= either
328328
-- invalid command is treated as a failure
329-
( \msg -> do
329+
( \failure -> do
330+
let msg = reportParseFailure failure
330331
liftIO $ outputUcmResult msg
331332
liftIO $ maybeDieWithMsg msg
332333
Cli.returnEarlyWithoutOutput

0 commit comments

Comments
 (0)