Include help output on all CLI command failures

```ucm
@unison/base/main> lib.install blah.blah.blah

  Sorry, I couldn’t understand your request. I expected a project or
  branch, but saw ”blah.blah.blah”.

  Usage:
  The `lib.install` command installs a dependency into the `lib` namespace.

  `lib.install @unison/base/releases/latest`  installs the latest release of `@unison/base`
  `lib.install @unison/base/releases/3.0.0`   installs version 3.0.0 of `@unison/base`
  `lib.install @unison/base/topic`            installs the `topic` branch of `@unison/base`
```
This commit is contained in:
Greg Pfeil 2024-06-04 18:31:21 -06:00
parent e656aa861c
commit 565da6d4a0
No known key found for this signature in database
GPG Key ID: 1193ACD196ED61F2
3 changed files with 84 additions and 35 deletions

View File

@ -149,7 +149,19 @@ 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.indentN 2 $
P.wrap (P.text "Sorry, I couldnt understand your request. " <> msg)
<> P.newline
<> P.newline
<> P.text "Usage:"
<> P.newline
<> P.indentN 2 help
)
$ parse resolvedArgs
pure $ Just (Left command : resolvedArgs, parsedInput)
Nothing ->
throwE

View File

@ -1732,30 +1732,25 @@ pullImpl name aliases pullMode addendum = do
These sourceProject sourceBranch ->
Right (Input.LibInstallI True (ProjectAndBranch sourceProject (Just sourceBranch)))
(Right source, Left _, Right path) ->
Left . P.indentN 2 $
P.wrap
( "I think you're wanting to merge"
<> case source of
RemoteRepo.ReadShare'LooseCode _sourcePath -> "some non-project code"
RemoteRepo.ReadShare'ProjectBranch (This sourceProject) ->
prettyProjectNameSlash sourceProject
RemoteRepo.ReadShare'ProjectBranch (That ProjectBranchNameOrLatestRelease'LatestRelease) ->
"the latest release"
RemoteRepo.ReadShare'ProjectBranch (That (ProjectBranchNameOrLatestRelease'Name sourceBranch)) ->
prettySlashProjectBranchName sourceBranch
RemoteRepo.ReadShare'ProjectBranch (These sourceProject ProjectBranchNameOrLatestRelease'LatestRelease) ->
"the latest release of" <> prettyProjectName sourceProject
RemoteRepo.ReadShare'ProjectBranch (These sourceProject (ProjectBranchNameOrLatestRelease'Name sourceBranch)) ->
prettyProjectAndBranchName (ProjectAndBranch sourceProject sourceBranch)
<> "into the"
<> prettyPath' path
<> "namespace, but the"
<> makeExample' pull
<> "command only supports merging into the top level of a local project branch."
)
<> P.newline
<> P.newline
<> P.wrap "Use `help pull` to see some examples."
Left $
"I think you're wanting to merge"
<> case source of
RemoteRepo.ReadShare'LooseCode _sourcePath -> "some non-project code"
RemoteRepo.ReadShare'ProjectBranch (This sourceProject) ->
prettyProjectNameSlash sourceProject
RemoteRepo.ReadShare'ProjectBranch (That ProjectBranchNameOrLatestRelease'LatestRelease) ->
"the latest release"
RemoteRepo.ReadShare'ProjectBranch (That (ProjectBranchNameOrLatestRelease'Name sourceBranch)) ->
prettySlashProjectBranchName sourceBranch
RemoteRepo.ReadShare'ProjectBranch (These sourceProject ProjectBranchNameOrLatestRelease'LatestRelease) ->
"the latest release of" <> prettyProjectName sourceProject
RemoteRepo.ReadShare'ProjectBranch (These sourceProject (ProjectBranchNameOrLatestRelease'Name sourceBranch)) ->
prettyProjectAndBranchName (ProjectAndBranch sourceProject sourceBranch)
<> "into the"
<> prettyPath' path
<> "namespace, but the"
<> makeExample' pull
<> "command only supports merging into the top level of a local project branch."
args -> wrongArgsLength "no more than two arguments" args
}

View File

@ -30,12 +30,33 @@ test/main> pull @aryairani/test-almost-empty/main lib.base_latest
test/main> pull @aryairani/test-almost-empty/main a.b
I think you're wanting to merge
@aryairani/test-almost-empty/main into the a.b namespace, but
the `pull` command only supports merging into the top level of
a local project branch.
Sorry, I couldnt understand your request. I think you're
wanting to merge @aryairani/test-almost-empty/main into the
a.b namespace, but the `pull` command only supports merging
into the top level of a local project branch.
Use `help pull` to see some examples.
Usage:
The `pull` command merges a remote namespace into a local
branch
`pull @unison/base/main` merges the branch
`main` of the Unison
Share hosted project
`@unison/base` into
the current branch
`pull @unison/base/main my-base/topic` merges the branch
`main` of the Unison
Share hosted project
`@unison/base` into
the branch `topic`
of the local
`my-base` project
where `remote` is a project or project branch, such as:
Project (defaults to the /main branch) `@unison/base`
Project Branch `@unison/base/feature`
Contributor Branch `@unison/base/@johnsmith/feature`
Project Release `@unison/base/releases/1.0.0`
test/main> pull @aryairani/test-almost-empty/main a
@ -46,11 +67,32 @@ test/main> pull @aryairani/test-almost-empty/main a
test/main> pull @aryairani/test-almost-empty/main .a
I think you're wanting to merge
@aryairani/test-almost-empty/main into the .a namespace, but
the `pull` command only supports merging into the top level of
a local project branch.
Sorry, I couldnt understand your request. I think you're
wanting to merge @aryairani/test-almost-empty/main into the .a
namespace, but the `pull` command only supports merging into
the top level of a local project branch.
Use `help pull` to see some examples.
Usage:
The `pull` command merges a remote namespace into a local
branch
`pull @unison/base/main` merges the branch
`main` of the Unison
Share hosted project
`@unison/base` into
the current branch
`pull @unison/base/main my-base/topic` merges the branch
`main` of the Unison
Share hosted project
`@unison/base` into
the branch `topic`
of the local
`my-base` project
where `remote` is a project or project branch, such as:
Project (defaults to the /main branch) `@unison/base`
Project Branch `@unison/base/feature`
Contributor Branch `@unison/base/@johnsmith/feature`
Project Release `@unison/base/releases/1.0.0`
```