From 9886c302ef538e538ec7d48b94374b9d2400004f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Jul 2015 12:47:35 -0400 Subject: implement withGlobalOptions, and convert Find --- Command.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Command.hs') diff --git a/Command.hs b/Command.hs index 019a657aa..102173f88 100644 --- a/Command.hs +++ b/Command.hs @@ -13,6 +13,7 @@ module Command ( noCommit, noMessages, withOptions, + withGlobalOptions, next, stop, stopUnless, @@ -33,6 +34,7 @@ import Checks as ReExported import CmdLine.Usage as ReExported import CmdLine.Action as ReExported import CmdLine.Option as ReExported +import CmdLine.GlobalSetter as ReExported import CmdLine.GitAnnex.Options as ReExported import Options.Applicative as ReExported hiding (command) @@ -78,6 +80,19 @@ noRepo a c = c { cmdnorepo = Just (a (cmdparamdesc c)) } withOptions :: [Option] -> Command -> Command withOptions o c = c { cmdoptions = cmdoptions c ++ o } +{- Adds global options to a command's option parser, and modifies its seek + - option to first run actions for them. + -} +withGlobalOptions :: [Parser GlobalSetter] -> Command -> Command +withGlobalOptions os c = c { cmdparser = apply <$> mixin (cmdparser c) } + where + mixin p = (,) + <$> p + <*> combineGlobalSetters os + apply (seek, globalsetters) = do + void $ getParsed globalsetters + seek + {- For start and perform stages to indicate what step to run next. -} next :: a -> Annex (Maybe a) next a = return $ Just a -- cgit v1.2.3