diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-07-08 15:39:05 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-07-08 15:39:05 -0400 |
commit | b2252febf1355e62a00fb735831d3b2a1aed2566 (patch) | |
tree | 621fb71f80252d300436261bb1d67ee537d1f7e9 /CmdLine.hs | |
parent | e7e61fb6cbe5455ded9bb550a64121223c099fc2 (diff) |
support cmdnorepo actions, also using getopt-applicative there
Diffstat (limited to 'CmdLine.hs')
-rw-r--r-- | CmdLine.hs | 45 |
1 files changed, 9 insertions, 36 deletions
diff --git a/CmdLine.hs b/CmdLine.hs index 2b9418d83..82c9b4289 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -45,7 +45,7 @@ dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do inRepo $ autocorrect . Just forM_ fields $ uncurry Annex.setField (cmd, seek) <- liftIO $ - O.handleParseResult (parseCmd (name:args) allcmds) + O.handleParseResult (parseCmd (name:args) allcmds cmdparser) when (cmdnomessages cmd) $ Annex.setOutput QuietOutput -- TODO: propigate global options to annex state (how?) @@ -54,11 +54,12 @@ dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do startup performCommandAction cmd seek $ shutdown $ cmdnocommit cmd - go (Left e) = do + go (Left norepo) = do when fuzzy $ autocorrect =<< Git.Config.global - -- a <- O.handleParseResult (parseCmd (name:args) allcmds) - error "TODO" + let norepoparser = fromMaybe (throw norepo) . cmdnorepo + (_cmd, a) <- O.handleParseResult (parseCmd (name:args) allcmds norepoparser) + a autocorrect = Git.AutoCorrect.prepare inputcmdname cmdname cmds err msg = msg ++ "\n\n" ++ usage header allcmds @@ -69,44 +70,16 @@ dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do _ -> inputcmdname | otherwise = inputcmdname -#if 0 - case getOptCmd args cmd commonoptions of - Right (flags, params) -> go flags params - =<< (E.try getgitrepo :: IO (Either E.SomeException Git.Repo)) - Left parseerr -> error parseerr - where - go flags params (Right g) = do - state <- Annex.new g - Annex.eval state $ do - checkEnvironment - when fuzzy $ - inRepo $ autocorrect . Just - forM_ fields $ uncurry Annex.setField - when (cmdnomessages cmd) $ - Annex.setOutput QuietOutput - sequence_ flags - whenM (annexDebug <$> Annex.getGitConfig) $ - liftIO enableDebugOutput - startup - performCommandAction cmd params $ - shutdown $ cmdnocommit cmd - go _flags params (Left e) = do - when fuzzy $ - autocorrect =<< Git.Config.global - maybe (throw e) (\a -> a params) (cmdnorepo cmd) - cmd = Prelude.head cmds -#endif -{- Parses command line and selects a command to run and gets the - - seek action for the command. -} -parseCmd :: CmdParams -> [Command] -> O.ParserResult (Command, CommandSeek) -parseCmd allargs allcmds = O.execParserPure (O.prefs O.idm) pinfo allargs +{- Parses command line, selecting one of the commands from the list. -} +parseCmd :: CmdParams -> [Command] -> (Command -> O.Parser v) -> O.ParserResult (Command, v) +parseCmd allargs allcmds getparser = O.execParserPure (O.prefs O.idm) pinfo allargs where pinfo = O.info (O.subparser $ mconcat $ map mkcommand allcmds) O.idm mkcommand c = O.command (cmdname c) (O.info (mkparser c) O.idm) mkparser c = (,) <$> pure c - <*> cmdparser c + <*> getparser c {- Parses command line params far enough to find the Command to run, and - returns the remaining params. |