diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-07-08 16:58:54 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-07-08 16:58:54 -0400 |
commit | 249e0861520a2904f70bf4b79a4ebddc009c3683 (patch) | |
tree | d5a4bb91ac80ad3fe44ed6b168bfc60ccb60668e /Command.hs | |
parent | 931f0f7bc6eb1ea6d25dec52e14c584f0cbd4778 (diff) |
converted fsck's options to optparse-applicative
Global options and seeking and key options are still to be done.
Diffstat (limited to 'Command.hs')
-rw-r--r-- | Command.hs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/Command.hs b/Command.hs index ec8ffadd9..e72bd1660 100644 --- a/Command.hs +++ b/Command.hs @@ -1,6 +1,6 @@ {- git-annex command infrastructure - - - Copyright 2010-2014 Joey Hess <id@joeyh.name> + - Copyright 2010-2015 Joey Hess <id@joeyh.name> - - Licensed under the GNU GPL version 3 or higher. -} @@ -8,6 +8,8 @@ module Command ( command, withParams, + cmdParams, + finalOpt, noRepo, noCommit, noMessages, @@ -36,16 +38,24 @@ 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 :: String -> CommandSection -> String -> CmdParamsDesc -> (CmdParamsDesc -> CommandParser) -> Command command name section desc paramdesc mkparser = 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) +{- Simple option parser that takes all non-option params as-is. -} +withParams :: (CmdParams -> v) -> CmdParamsDesc -> O.Parser v +withParams mkseek paramdesc = mkseek <$> cmdParams paramdesc + +{- Parser that accepts all non-option params. -} +cmdParams :: CmdParamsDesc -> O.Parser CmdParams +cmdParams paramdesc = O.many (O.argument O.str (O.metavar paramdesc)) + +{- Makes an option parser that is normally required be optional; + - its switch can be given zero or more times, and the last one + - given will be used. -} +finalOpt :: O.Parser a -> O.Parser (Maybe a) +finalOpt = lastMaybe <$$> O.many {- Indicates that a command doesn't need to commit any changes to - the git-annex branch. -} |