mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-20 23:07:13 +03:00
Merge pull request #5185 from unisonweb/arya/commandline-helpers
This commit is contained in:
commit
222bd48515
@ -39,6 +39,7 @@ import Unison.CommandLine.FuzzySelect qualified as Fuzzy
|
|||||||
import Unison.CommandLine.Helpers (warn)
|
import Unison.CommandLine.Helpers (warn)
|
||||||
import Unison.CommandLine.InputPattern (InputPattern (..))
|
import Unison.CommandLine.InputPattern (InputPattern (..))
|
||||||
import Unison.CommandLine.InputPattern qualified as InputPattern
|
import Unison.CommandLine.InputPattern qualified as InputPattern
|
||||||
|
import Unison.CommandLine.InputPatterns qualified as IPs
|
||||||
import Unison.Parser.Ann (Ann)
|
import Unison.Parser.Ann (Ann)
|
||||||
import Unison.Prelude
|
import Unison.Prelude
|
||||||
import Unison.Project.Util (ProjectContext, projectContextFromPath)
|
import Unison.Project.Util (ProjectContext, projectContextFromPath)
|
||||||
@ -117,12 +118,10 @@ parseInput codebase currentPath numberedArgs patterns segments = runExceptT do
|
|||||||
<> P.newline
|
<> P.newline
|
||||||
<> P.newline
|
<> P.newline
|
||||||
<> P.wrap
|
<> P.wrap
|
||||||
( P.text $
|
( "You can run"
|
||||||
"You can run `help "
|
<> IPs.makeExample IPs.help [fromString command]
|
||||||
<> Text.pack command
|
<> "for more information on using"
|
||||||
<> "` for more information on using `"
|
<> IPs.makeExampleEOS pat []
|
||||||
<> Text.pack command
|
|
||||||
<> "`."
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
$ parse resolvedArgs
|
$ parse resolvedArgs
|
||||||
@ -131,9 +130,11 @@ parseInput codebase currentPath numberedArgs patterns segments = runExceptT do
|
|||||||
throwE
|
throwE
|
||||||
. warn
|
. warn
|
||||||
. P.wrap
|
. P.wrap
|
||||||
$ "I don't know how to "
|
$ "I don't know how to"
|
||||||
<> P.group (fromString command <> ".")
|
<> P.group (fromString command <> ".")
|
||||||
<> "Type `help` or `?` to get help."
|
<> "Type"
|
||||||
|
<> IPs.makeExample' IPs.help
|
||||||
|
<> "or `?` to get help."
|
||||||
where
|
where
|
||||||
noCompletionsMessage argDesc =
|
noCompletionsMessage argDesc =
|
||||||
P.callout "⚠️" $
|
P.callout "⚠️" $
|
||||||
|
@ -190,7 +190,7 @@ import Unison.CommandLine.BranchRelativePath (BranchRelativePath (..), parseBran
|
|||||||
import Unison.CommandLine.BranchRelativePath qualified as BranchRelativePath
|
import Unison.CommandLine.BranchRelativePath qualified as BranchRelativePath
|
||||||
import Unison.CommandLine.Completion
|
import Unison.CommandLine.Completion
|
||||||
import Unison.CommandLine.FZFResolvers qualified as Resolvers
|
import Unison.CommandLine.FZFResolvers qualified as Resolvers
|
||||||
import Unison.CommandLine.Helpers (aside, backtick, tip, warn)
|
import Unison.CommandLine.Helpers (aside, backtick, tip)
|
||||||
import Unison.CommandLine.InputPattern (ArgumentType (..), InputPattern (InputPattern), IsOptional (..), unionSuggestions)
|
import Unison.CommandLine.InputPattern (ArgumentType (..), InputPattern (InputPattern), IsOptional (..), unionSuggestions)
|
||||||
import Unison.CommandLine.InputPattern qualified as I
|
import Unison.CommandLine.InputPattern qualified as I
|
||||||
import Unison.Core.Project (ProjectBranchName (..))
|
import Unison.Core.Project (ProjectBranchName (..))
|
||||||
@ -300,14 +300,13 @@ searchResultToHQ oprefix = \case
|
|||||||
addPrefix :: Name -> Name
|
addPrefix :: Name -> Name
|
||||||
addPrefix = maybe id Path.prefixNameIfRel oprefix
|
addPrefix = maybe id Path.prefixNameIfRel oprefix
|
||||||
|
|
||||||
unsupportedStructuredArgument :: Text -> Text -> I.Argument -> Either (P.Pretty CT.ColorText) String
|
unsupportedStructuredArgument :: InputPattern -> Text -> I.Argument -> Either (P.Pretty CT.ColorText) String
|
||||||
unsupportedStructuredArgument command expected =
|
unsupportedStructuredArgument command expected =
|
||||||
either pure . const . Left . P.text $
|
either pure . const . Left . P.wrap $
|
||||||
"`"
|
makeExample' command
|
||||||
<> command
|
<> "can’t accept a numbered argument for"
|
||||||
<> "` can’t accept a numbered argument for "
|
<> P.text expected
|
||||||
<> expected
|
<> "and it’s not yet possible to provide un-expanded numbers as arguments."
|
||||||
<> " and it’s not yet possible to provide un-expanded numbers as arguments."
|
|
||||||
|
|
||||||
expectedButActually' :: Text -> String -> P.Pretty CT.ColorText
|
expectedButActually' :: Text -> String -> P.Pretty CT.ColorText
|
||||||
expectedButActually' expected actualValue =
|
expectedButActually' expected actualValue =
|
||||||
@ -793,7 +792,7 @@ load =
|
|||||||
)
|
)
|
||||||
\case
|
\case
|
||||||
[] -> pure $ Input.LoadI Nothing
|
[] -> pure $ Input.LoadI Nothing
|
||||||
[file] -> Input.LoadI . Just <$> unsupportedStructuredArgument "load" "a file name" file
|
[file] -> Input.LoadI . Just <$> unsupportedStructuredArgument load "a file name" file
|
||||||
args -> wrongArgsLength "no more than one argument" args
|
args -> wrongArgsLength "no more than one argument" args
|
||||||
|
|
||||||
clear :: InputPattern
|
clear :: InputPattern
|
||||||
@ -1016,7 +1015,7 @@ displayTo =
|
|||||||
(wrongArgsLength "at least two arguments" [file])
|
(wrongArgsLength "at least two arguments" [file])
|
||||||
( \defs ->
|
( \defs ->
|
||||||
Input.DisplayI . Input.FileLocation
|
Input.DisplayI . Input.FileLocation
|
||||||
<$> unsupportedStructuredArgument "display.to" "a file name" file
|
<$> unsupportedStructuredArgument displayTo "a file name" file
|
||||||
<*> traverse handleHashQualifiedNameArg defs
|
<*> traverse handleHashQualifiedNameArg defs
|
||||||
)
|
)
|
||||||
$ NE.nonEmpty defs
|
$ NE.nonEmpty defs
|
||||||
@ -1823,7 +1822,7 @@ debugTabCompletion =
|
|||||||
P.wrap $ "Completions which are finished are prefixed with a * represent finished completions."
|
P.wrap $ "Completions which are finished are prefixed with a * represent finished completions."
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(fmap Input.DebugTabCompletionI . traverse (unsupportedStructuredArgument "debug.tab-complete" "text"))
|
(fmap Input.DebugTabCompletionI . traverse (unsupportedStructuredArgument debugTabCompletion "text"))
|
||||||
|
|
||||||
debugLspNameCompletion :: InputPattern
|
debugLspNameCompletion :: InputPattern
|
||||||
debugLspNameCompletion =
|
debugLspNameCompletion =
|
||||||
@ -1837,8 +1836,8 @@ debugLspNameCompletion =
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
\case
|
\case
|
||||||
[prefix] -> Input.DebugLSPNameCompletionI . Text.pack <$> unsupportedStructuredArgument "text" prefix
|
[prefix] -> Input.DebugLSPNameCompletionI . Text.pack <$> unsupportedStructuredArgument debugLspNameCompletion "text" prefix
|
||||||
_ -> Left (I.help debugLspNameCompletion)
|
args -> wrongArgsLength "exactly one argument" args
|
||||||
|
|
||||||
debugFuzzyOptions :: InputPattern
|
debugFuzzyOptions :: InputPattern
|
||||||
debugFuzzyOptions =
|
debugFuzzyOptions =
|
||||||
@ -1858,8 +1857,8 @@ debugFuzzyOptions =
|
|||||||
\case
|
\case
|
||||||
(cmd : args) ->
|
(cmd : args) ->
|
||||||
Input.DebugFuzzyOptionsI
|
Input.DebugFuzzyOptionsI
|
||||||
<$> unsupportedStructuredArgument "debug.fuzzy-options" "a command" cmd
|
<$> unsupportedStructuredArgument debugFuzzyOptions "a command" cmd
|
||||||
<*> traverse (unsupportedStructuredArgument "debug.fuzzy-options" "text") args
|
<*> traverse (unsupportedStructuredArgument debugFuzzyOptions "text") args
|
||||||
args -> wrongArgsLength "at least one argument" args
|
args -> wrongArgsLength "at least one argument" args
|
||||||
|
|
||||||
debugFormat :: InputPattern
|
debugFormat :: InputPattern
|
||||||
@ -2345,7 +2344,7 @@ helpTopics =
|
|||||||
( \case
|
( \case
|
||||||
[] -> Right $ Input.CreateMessage topics
|
[] -> Right $ Input.CreateMessage topics
|
||||||
[topic] -> do
|
[topic] -> do
|
||||||
topic <- unsupportedStructuredArgument "help-topics" "a help topic" topic
|
topic <- unsupportedStructuredArgument helpTopics "a help topic" topic
|
||||||
case Map.lookup topic helpTopicsMap of
|
case Map.lookup topic helpTopicsMap of
|
||||||
Nothing -> Left $ "I don't know of that topic. Try `help-topics`."
|
Nothing -> Left $ "I don't know of that topic. Try `help-topics`."
|
||||||
Just t -> Right $ Input.CreateMessage t
|
Just t -> Right $ Input.CreateMessage t
|
||||||
@ -2534,10 +2533,10 @@ help =
|
|||||||
showPatternHelp
|
showPatternHelp
|
||||||
visibleInputs
|
visibleInputs
|
||||||
[cmd] -> do
|
[cmd] -> do
|
||||||
cmd <- unsupportedStructuredArgument "help" "a command" cmd
|
cmd <- unsupportedStructuredArgument help "a command" cmd
|
||||||
case (Map.lookup cmd commandsByName, isHelp cmd) of
|
case (Map.lookup cmd commandsByName, isHelp cmd) of
|
||||||
(Nothing, Just msg) -> Right $ Input.CreateMessage msg
|
(Nothing, Just msg) -> Right $ Input.CreateMessage msg
|
||||||
(Nothing, Nothing) -> Left $ "I don't know of that command. Try `help`."
|
(Nothing, Nothing) -> Left $ "I don't know of that command. Try" <> makeExampleEOS help []
|
||||||
(Just pat, Nothing) -> Right . Input.CreateMessage $ showPatternHelp pat
|
(Just pat, Nothing) -> Right . Input.CreateMessage $ showPatternHelp pat
|
||||||
-- If we have a command and a help topic with the same name (like "projects"), then append a tip to the
|
-- If we have a command and a help topic with the same name (like "projects"), then append a tip to the
|
||||||
-- command's help that suggests running `help-topic command`
|
-- command's help that suggests running `help-topic command`
|
||||||
@ -2816,7 +2815,7 @@ docsToHtml =
|
|||||||
[namespacePath, destinationFilePath] ->
|
[namespacePath, destinationFilePath] ->
|
||||||
Input.DocsToHtmlI
|
Input.DocsToHtmlI
|
||||||
<$> handleBranchRelativePathArg namespacePath
|
<$> handleBranchRelativePathArg namespacePath
|
||||||
<*> unsupportedStructuredArgument "docs.to-html" "a file name" destinationFilePath
|
<*> unsupportedStructuredArgument docsToHtml "a file name" destinationFilePath
|
||||||
args -> wrongArgsLength "exactly two arguments" args
|
args -> wrongArgsLength "exactly two arguments" args
|
||||||
|
|
||||||
docToMarkdown :: InputPattern
|
docToMarkdown :: InputPattern
|
||||||
@ -2856,7 +2855,7 @@ execute =
|
|||||||
main : args ->
|
main : args ->
|
||||||
Input.ExecuteI
|
Input.ExecuteI
|
||||||
<$> handleHashQualifiedNameArg main
|
<$> handleHashQualifiedNameArg main
|
||||||
<*> traverse (unsupportedStructuredArgument "run" "a command-line argument") args
|
<*> traverse (unsupportedStructuredArgument execute "a command-line argument") args
|
||||||
[] -> wrongArgsLength "at least one argument" []
|
[] -> wrongArgsLength "at least one argument" []
|
||||||
|
|
||||||
saveExecuteResult :: InputPattern
|
saveExecuteResult :: InputPattern
|
||||||
@ -2927,7 +2926,7 @@ makeStandalone =
|
|||||||
$ \case
|
$ \case
|
||||||
[main, file] ->
|
[main, file] ->
|
||||||
Input.MakeStandaloneI
|
Input.MakeStandaloneI
|
||||||
<$> unsupportedStructuredArgument "compile" "a file name" file
|
<$> unsupportedStructuredArgument makeStandalone "a file name" file
|
||||||
<*> handleHashQualifiedNameArg main
|
<*> handleHashQualifiedNameArg main
|
||||||
args -> wrongArgsLength "exactly two arguments" args
|
args -> wrongArgsLength "exactly two arguments" args
|
||||||
|
|
||||||
@ -2948,7 +2947,7 @@ runScheme =
|
|||||||
main : args ->
|
main : args ->
|
||||||
Input.ExecuteSchemeI
|
Input.ExecuteSchemeI
|
||||||
<$> handleHashQualifiedNameArg main
|
<$> handleHashQualifiedNameArg main
|
||||||
<*> traverse (unsupportedStructuredArgument "run.native" "a command-line argument") args
|
<*> traverse (unsupportedStructuredArgument runScheme "a command-line argument") args
|
||||||
[] -> wrongArgsLength "at least one argument" []
|
[] -> wrongArgsLength "at least one argument" []
|
||||||
|
|
||||||
compileScheme :: InputPattern
|
compileScheme :: InputPattern
|
||||||
@ -2969,7 +2968,7 @@ compileScheme =
|
|||||||
$ \case
|
$ \case
|
||||||
[main, file] ->
|
[main, file] ->
|
||||||
Input.CompileSchemeI . Text.pack
|
Input.CompileSchemeI . Text.pack
|
||||||
<$> unsupportedStructuredArgument "compile.native" "a file name" file
|
<$> unsupportedStructuredArgument compileScheme "a file name" file
|
||||||
<*> handleHashQualifiedNameArg main
|
<*> handleHashQualifiedNameArg main
|
||||||
args -> wrongArgsLength "exactly two arguments" args
|
args -> wrongArgsLength "exactly two arguments" args
|
||||||
|
|
||||||
@ -2997,7 +2996,7 @@ createAuthor =
|
|||||||
<$> handleRelativeNameSegmentArg symbolStr
|
<$> handleRelativeNameSegmentArg symbolStr
|
||||||
<*> fmap
|
<*> fmap
|
||||||
(parseAuthorName . unwords)
|
(parseAuthorName . unwords)
|
||||||
(traverse (unsupportedStructuredArgument "create.author" "text") authorStr)
|
(traverse (unsupportedStructuredArgument createAuthor "text") authorStr)
|
||||||
args -> wrongArgsLength "at least two arguments" args
|
args -> wrongArgsLength "at least two arguments" args
|
||||||
where
|
where
|
||||||
-- let's have a real parser in not too long
|
-- let's have a real parser in not too long
|
||||||
@ -3265,7 +3264,7 @@ releaseDraft =
|
|||||||
bimap (const "Couldn’t parse version number") Input.ReleaseDraftI
|
bimap (const "Couldn’t parse version number") Input.ReleaseDraftI
|
||||||
. tryInto @Semver
|
. tryInto @Semver
|
||||||
. Text.pack
|
. Text.pack
|
||||||
=<< unsupportedStructuredArgument "release.draft" "a version number" semverString
|
=<< unsupportedStructuredArgument releaseDraft "a version number" semverString
|
||||||
args -> wrongArgsLength "exactly one argument" args
|
args -> wrongArgsLength "exactly one argument" args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user