2011-10-30 03:48:46 +00:00
|
|
|
{- git-annex command-line options
|
2010-12-30 20:52:24 +00:00
|
|
|
-
|
2011-10-30 03:48:46 +00:00
|
|
|
- Copyright 2010-2011 Joey Hess <joey@kitenet.net>
|
2010-12-30 20:52:24 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Options where
|
|
|
|
|
|
|
|
import System.Console.GetOpt
|
2011-05-21 15:52:13 +00:00
|
|
|
import System.Log.Logger
|
2010-12-30 20:52:24 +00:00
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-12-30 20:52:24 +00:00
|
|
|
import qualified Annex
|
2011-09-18 22:21:42 +00:00
|
|
|
import Limit
|
2010-12-30 20:52:24 +00:00
|
|
|
|
|
|
|
{- Each dashed command-line option results in generation of an action
|
|
|
|
- in the Annex monad that performs the necessary setting.
|
|
|
|
-}
|
|
|
|
type Option = OptDescr (Annex ())
|
|
|
|
|
|
|
|
commonOptions :: [Option]
|
2010-12-31 17:39:30 +00:00
|
|
|
commonOptions =
|
2011-04-03 16:18:38 +00:00
|
|
|
[ Option [] ["force"] (NoArg (setforce True))
|
2010-12-30 20:52:24 +00:00
|
|
|
"allow actions that may lose annexed data"
|
2011-03-22 21:41:06 +00:00
|
|
|
, Option ['F'] ["fast"] (NoArg (setfast True))
|
|
|
|
"avoid slow operations"
|
2011-09-15 17:30:04 +00:00
|
|
|
, Option ['a'] ["auto"] (NoArg (setauto True))
|
|
|
|
"automatic mode"
|
2011-09-01 17:35:07 +00:00
|
|
|
, Option ['q'] ["quiet"] (NoArg (setoutput Annex.QuietOutput))
|
2010-12-30 20:52:24 +00:00
|
|
|
"avoid verbose output"
|
2011-09-01 17:35:07 +00:00
|
|
|
, Option ['v'] ["verbose"] (NoArg (setoutput Annex.NormalOutput))
|
2011-05-21 15:52:13 +00:00
|
|
|
"allow verbose output (default)"
|
2011-09-01 19:16:31 +00:00
|
|
|
, Option ['j'] ["json"] (NoArg (setoutput Annex.JSONOutput))
|
|
|
|
"enable JSON output"
|
2011-05-21 15:52:13 +00:00
|
|
|
, Option ['d'] ["debug"] (NoArg (setdebug))
|
|
|
|
"show debug messages"
|
2011-05-18 23:34:46 +00:00
|
|
|
, Option ['b'] ["backend"] (ReqArg setforcebackend paramName)
|
|
|
|
"specify key-value backend to use"
|
2010-12-31 17:39:30 +00:00
|
|
|
]
|
2011-01-26 04:17:38 +00:00
|
|
|
where
|
|
|
|
setforce v = Annex.changeState $ \s -> s { Annex.force = v }
|
2011-03-22 21:41:06 +00:00
|
|
|
setfast v = Annex.changeState $ \s -> s { Annex.fast = v }
|
2011-09-15 17:30:04 +00:00
|
|
|
setauto v = Annex.changeState $ \s -> s { Annex.auto = v }
|
2011-09-01 17:35:07 +00:00
|
|
|
setoutput v = Annex.changeState $ \s -> s { Annex.output = v }
|
2011-05-18 23:34:46 +00:00
|
|
|
setforcebackend v = Annex.changeState $ \s -> s { Annex.forcebackend = Just v }
|
2011-05-22 23:07:20 +00:00
|
|
|
setdebug = liftIO $ updateGlobalLogger rootLoggerName $
|
|
|
|
setLevel DEBUG
|
2011-09-18 22:21:42 +00:00
|
|
|
|
|
|
|
matcherOptions :: [Option]
|
|
|
|
matcherOptions =
|
|
|
|
[ longopt "not" "negate next option"
|
|
|
|
, longopt "and" "both previous and next option must match"
|
|
|
|
, longopt "or" "either previous or next option must match"
|
|
|
|
, shortopt "(" "open group of options"
|
|
|
|
, shortopt ")" "close group of options"
|
|
|
|
]
|
|
|
|
where
|
2011-09-21 03:24:48 +00:00
|
|
|
longopt o = Option [] [o] $ NoArg $ addToken o
|
|
|
|
shortopt o = Option o [] $ NoArg $ addToken o
|
2011-10-30 03:48:46 +00:00
|
|
|
|
|
|
|
{- Descriptions of params used in usage messages. -}
|
|
|
|
paramPaths :: String
|
|
|
|
paramPaths = paramOptional $ paramRepeating paramPath -- most often used
|
|
|
|
paramPath :: String
|
|
|
|
paramPath = "PATH"
|
|
|
|
paramKey :: String
|
|
|
|
paramKey = "KEY"
|
|
|
|
paramDesc :: String
|
|
|
|
paramDesc = "DESC"
|
|
|
|
paramUrl :: String
|
|
|
|
paramUrl = "URL"
|
|
|
|
paramNumber :: String
|
|
|
|
paramNumber = "NUMBER"
|
|
|
|
paramRemote :: String
|
|
|
|
paramRemote = "REMOTE"
|
|
|
|
paramGlob :: String
|
|
|
|
paramGlob = "GLOB"
|
|
|
|
paramName :: String
|
|
|
|
paramName = "NAME"
|
|
|
|
paramUUID :: String
|
|
|
|
paramUUID = "UUID"
|
|
|
|
paramType :: String
|
|
|
|
paramType = "TYPE"
|
2011-12-22 22:31:44 +00:00
|
|
|
paramFormat :: String
|
|
|
|
paramFormat = "FORMAT"
|
2011-10-30 03:48:46 +00:00
|
|
|
paramKeyValue :: String
|
|
|
|
paramKeyValue = "K=V"
|
|
|
|
paramNothing :: String
|
|
|
|
paramNothing = ""
|
|
|
|
paramRepeating :: String -> String
|
|
|
|
paramRepeating s = s ++ " ..."
|
|
|
|
paramOptional :: String -> String
|
|
|
|
paramOptional s = "[" ++ s ++ "]"
|
|
|
|
paramPair :: String -> String -> String
|
|
|
|
paramPair a b = a ++ " " ++ b
|