This commit is contained in:
Joey Hess 2021-02-02 14:27:42 -04:00
parent d0fe0c5e10
commit 4cc65d97fc
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -71,7 +71,6 @@ dispatch fuzzyok allargs allcmds globaloptions fields getgitrepo progname progde
res -> handleresult res
where
autocorrect = Git.AutoCorrect.prepare (fromJust inputcmdname) cmdname cmds
(fuzzy, cmds, inputcmdname, args) = findCmd fuzzyok allargs allcmds
name
| fuzzy = case cmds of
(c:_) -> Just (cmdname c)
@ -81,6 +80,9 @@ dispatch fuzzyok allargs allcmds globaloptions fields getgitrepo progname progde
Nothing -> allargs
Just n -> n:args
(inputcmdname, args) = findCmdName allargs
(fuzzy, cmds) = findCmd fuzzyok allcmds inputcmdname
{- Parses command line, selecting one of the commands from the list. -}
parseCmd :: String -> String -> [GlobalOption] -> CmdParams -> [Command] -> (Command -> O.Parser v) -> O.ParserResult (Command, v, GlobalSetter)
parseCmd progname progdesc globaloptions allargs allcmds getparser =
@ -99,25 +101,27 @@ parseCmd progname progdesc globaloptions allargs allcmds getparser =
intro = mconcat $ concatMap (\l -> [H.text l, H.line])
(synopsis progname progdesc : commandList allcmds)
{- Parses command line params far enough to find the Command to run, and
- returns the remaining params.
{- Finds the Command that matches the subcommand name.
- Does fuzzy matching if necessary, which may result in multiple Commands. -}
findCmd :: Bool -> CmdParams -> [Command] -> (Bool, [Command], Maybe String, CmdParams)
findCmd fuzzyok argv cmds
| not (null exactcmds) = ret (False, exactcmds)
| fuzzyok && not (null inexactcmds) = ret (True, inexactcmds)
| otherwise = ret (False, [])
findCmd :: Bool -> [Command] -> Maybe String -> (Bool, [Command])
findCmd fuzzyok cmds (Just n)
| not (null exactcmds) = (False, exactcmds)
| fuzzyok && not (null inexactcmds) = (True, inexactcmds)
| otherwise = (False, [])
where
exactcmds = filter (\c -> cmdname c == n) cmds
inexactcmds = Git.AutoCorrect.fuzzymatches n cmdname cmds
findCmd _ _ Nothing = (False, [])
{- Parses command line params far enough to find the subcommand name. -}
findCmdName :: CmdParams -> (Maybe String, CmdParams)
findCmdName argv = (name, args)
where
ret (fuzzy, matches) = (fuzzy, matches, name, args)
(name, args) = findname argv []
findname [] c = (Nothing, reverse c)
findname (a:as) c
| "-" `isPrefixOf` a = findname as (a:c)
| otherwise = (Just a, reverse c ++ as)
exactcmds = filter (\c -> name == Just (cmdname c)) cmds
inexactcmds = case name of
Nothing -> []
Just n -> Git.AutoCorrect.fuzzymatches n cmdname cmds
prepRunCommand :: Command -> GlobalSetter -> Annex ()
prepRunCommand cmd globalconfig = do