summaryrefslogtreecommitdiff
path: root/Command.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-08 15:39:05 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-08 15:39:05 -0400
commitb2252febf1355e62a00fb735831d3b2a1aed2566 (patch)
tree621fb71f80252d300436261bb1d67ee537d1f7e9 /Command.hs
parente7e61fb6cbe5455ded9bb550a64121223c099fc2 (diff)
support cmdnorepo actions, also using getopt-applicative there
Diffstat (limited to 'Command.hs')
-rw-r--r--Command.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/Command.hs b/Command.hs
index c1d788c79..ec8ffadd9 100644
--- a/Command.hs
+++ b/Command.hs
@@ -7,6 +7,7 @@
module Command (
command,
+ withParams,
noRepo,
noCommit,
noMessages,
@@ -32,11 +33,19 @@ import CmdLine.Action as ReExported
import CmdLine.Option as ReExported
import CmdLine.GitAnnex.Options as ReExported
+import qualified Options.Applicative as O
+
{- Generates a normal Command -}
command :: String -> CommandSection -> String -> String -> (String -> CommandParser) -> Command
command name section desc paramdesc mkparser =
- Command [] Nothing commonChecks False False name paramdesc
- section desc (mkparser paramdesc)
+ Command [] commonChecks False False name paramdesc
+ section desc (mkparser paramdesc) Nothing
+
+{- Option parser that takes all non-option params as-is. -}
+withParams :: (CmdParams -> v) -> String -> O.Parser v
+withParams mkseek paramdesc = mkseek <$> O.many cmdparams
+ where
+ cmdparams = O.argument O.str (O.metavar paramdesc)
{- Indicates that a command doesn't need to commit any changes to
- the git-annex branch. -}
@@ -50,8 +59,8 @@ noMessages c = c { cmdnomessages = True }
{- Adds a fallback action to a command, that will be run if it's used
- outside a git repository. -}
-noRepo :: (CmdParams -> IO ()) -> Command -> Command
-noRepo a c = c { cmdnorepo = Just a }
+noRepo :: (String -> O.Parser (IO ())) -> Command -> Command
+noRepo a c = c { cmdnorepo = Just (a (cmdparamdesc c)) }
{- Adds options to a command. -}
withOptions :: [Option] -> Command -> Command