aboutsummaryrefslogtreecommitdiff
path: root/Command.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-10 12:47:35 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-10 12:47:35 -0400
commit9886c302ef538e538ec7d48b94374b9d2400004f (patch)
tree4c6b55c2ab31a977f1fbd89f131aac9ae3722119 /Command.hs
parentbc9b0307cf427ab8ca6532c2ae4e0086e7ad4a4a (diff)
implement withGlobalOptions, and convert Find
Diffstat (limited to 'Command.hs')
-rw-r--r--Command.hs15
1 files changed, 15 insertions, 0 deletions
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