Skip to content

Commit

Permalink
Merge pull request #5054 from sellout/better-CLI-error-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
aryairani authored Jul 5, 2024
2 parents a74d4e8 + 8be432b commit 2b60344
Show file tree
Hide file tree
Showing 11 changed files with 1,601 additions and 202 deletions.
22 changes: 21 additions & 1 deletion unison-cli/src/Unison/CommandLine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,27 @@ parseInput codebase currentPath numberedArgs patterns segments = runExceptT do
Left (NoFZFOptions argDesc) -> throwError (noCompletionsMessage argDesc)
Left FZFCancelled -> pure Nothing
Right resolvedArgs -> do
parsedInput <- except . parse $ resolvedArgs
parsedInput <-
except
. first
( \msg ->
P.warnCallout $
P.wrap "Sorry, I wasn’t sure how to process your request:"
<> P.newline
<> P.newline
<> P.indentN 2 msg
<> P.newline
<> P.newline
<> P.wrap
( P.text $
"You can run `help "
<> Text.pack command
<> "` for more information on using `"
<> Text.pack command
<> "`."
)
)
$ parse resolvedArgs
pure $ Just (Left command : resolvedArgs, parsedInput)
Nothing ->
throwE
Expand Down
11 changes: 10 additions & 1 deletion unison-cli/src/Unison/CommandLine/InputPattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ data InputPattern = InputPattern
visibility :: Visibility, -- Allow hiding certain commands when debugging or work-in-progress
args :: [(ArgumentDescription, IsOptional, ArgumentType)],
help :: P.Pretty CT.ColorText,
parse :: Arguments -> Either (P.Pretty CT.ColorText) Input
-- | Parse the arguments and return either an error message or a command `Input`.
--
-- __NB__: This function should return `Left` only on failure. For commands (like `help`) that simply produce
-- formatted output, use `pure . Input.CreateMessage`. The failure output should be fully formatted (using
-- `wrap`, etc.), but shouldn’t include any general error components like a warninng flag or the full help
-- message, and shouldn’t plan for the context it is being output to (e.g., don’t `P.indentN` the entire
-- message).
parse ::
Arguments ->
Either (P.Pretty CT.ColorText) Input
}

data ArgumentType = ArgumentType
Expand Down
Loading

0 comments on commit 2b60344

Please sign in to comment.