refactor
This commit is contained in:
parent
d0fe0c5e10
commit
4cc65d97fc
1 changed files with 17 additions and 13 deletions
30
CmdLine.hs
30
CmdLine.hs
|
@ -71,7 +71,6 @@ dispatch fuzzyok allargs allcmds globaloptions fields getgitrepo progname progde
|
||||||
res -> handleresult res
|
res -> handleresult res
|
||||||
where
|
where
|
||||||
autocorrect = Git.AutoCorrect.prepare (fromJust inputcmdname) cmdname cmds
|
autocorrect = Git.AutoCorrect.prepare (fromJust inputcmdname) cmdname cmds
|
||||||
(fuzzy, cmds, inputcmdname, args) = findCmd fuzzyok allargs allcmds
|
|
||||||
name
|
name
|
||||||
| fuzzy = case cmds of
|
| fuzzy = case cmds of
|
||||||
(c:_) -> Just (cmdname c)
|
(c:_) -> Just (cmdname c)
|
||||||
|
@ -81,6 +80,9 @@ dispatch fuzzyok allargs allcmds globaloptions fields getgitrepo progname progde
|
||||||
Nothing -> allargs
|
Nothing -> allargs
|
||||||
Just n -> n:args
|
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. -}
|
{- 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 :: String -> String -> [GlobalOption] -> CmdParams -> [Command] -> (Command -> O.Parser v) -> O.ParserResult (Command, v, GlobalSetter)
|
||||||
parseCmd progname progdesc globaloptions allargs allcmds getparser =
|
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])
|
intro = mconcat $ concatMap (\l -> [H.text l, H.line])
|
||||||
(synopsis progname progdesc : commandList allcmds)
|
(synopsis progname progdesc : commandList allcmds)
|
||||||
|
|
||||||
{- Parses command line params far enough to find the Command to run, and
|
{- Finds the Command that matches the subcommand name.
|
||||||
- returns the remaining params.
|
|
||||||
- Does fuzzy matching if necessary, which may result in multiple Commands. -}
|
- Does fuzzy matching if necessary, which may result in multiple Commands. -}
|
||||||
findCmd :: Bool -> CmdParams -> [Command] -> (Bool, [Command], Maybe String, CmdParams)
|
findCmd :: Bool -> [Command] -> Maybe String -> (Bool, [Command])
|
||||||
findCmd fuzzyok argv cmds
|
findCmd fuzzyok cmds (Just n)
|
||||||
| not (null exactcmds) = ret (False, exactcmds)
|
| not (null exactcmds) = (False, exactcmds)
|
||||||
| fuzzyok && not (null inexactcmds) = ret (True, inexactcmds)
|
| fuzzyok && not (null inexactcmds) = (True, inexactcmds)
|
||||||
| otherwise = ret (False, [])
|
| 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
|
where
|
||||||
ret (fuzzy, matches) = (fuzzy, matches, name, args)
|
|
||||||
(name, args) = findname argv []
|
(name, args) = findname argv []
|
||||||
findname [] c = (Nothing, reverse c)
|
findname [] c = (Nothing, reverse c)
|
||||||
findname (a:as) c
|
findname (a:as) c
|
||||||
| "-" `isPrefixOf` a = findname as (a:c)
|
| "-" `isPrefixOf` a = findname as (a:c)
|
||||||
| otherwise = (Just a, reverse c ++ as)
|
| 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 :: Command -> GlobalSetter -> Annex ()
|
||||||
prepRunCommand cmd globalconfig = do
|
prepRunCommand cmd globalconfig = do
|
||||||
|
|
Loading…
Reference in a new issue