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.
|
|
|
|
-}
|
|
|
|
|
2012-01-06 14:14:37 +00:00
|
|
|
module Option (
|
|
|
|
common,
|
|
|
|
matcher,
|
|
|
|
flag,
|
|
|
|
field,
|
|
|
|
name,
|
2012-01-06 02:48:59 +00:00
|
|
|
ArgDescr(..),
|
|
|
|
OptDescr(..),
|
|
|
|
) where
|
2010-12-30 20:52:24 +00:00
|
|
|
|
|
|
|
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
|
2012-04-27 17:23:52 +00:00
|
|
|
import Types.Messages
|
2011-09-18 22:21:42 +00:00
|
|
|
import Limit
|
2012-01-06 02:48:59 +00:00
|
|
|
import Usage
|
2010-12-30 20:52:24 +00:00
|
|
|
|
2012-01-06 14:14:37 +00:00
|
|
|
common :: [Option]
|
|
|
|
common =
|
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"
|
2012-04-30 17:59:05 +00:00
|
|
|
, Option ['q'] ["quiet"] (NoArg (Annex.setOutput QuietOutput))
|
2010-12-30 20:52:24 +00:00
|
|
|
"avoid verbose output"
|
2012-04-30 17:59:05 +00:00
|
|
|
, Option ['v'] ["verbose"] (NoArg (Annex.setOutput NormalOutput))
|
2011-05-21 15:52:13 +00:00
|
|
|
"allow verbose output (default)"
|
2012-04-30 17:59:05 +00:00
|
|
|
, Option ['j'] ["json"] (NoArg (Annex.setOutput JSONOutput))
|
2011-09-01 19:16:31 +00:00
|
|
|
"enable JSON output"
|
2012-02-16 04:41:30 +00:00
|
|
|
, Option ['d'] ["debug"] (NoArg setdebug)
|
2011-05-21 15:52:13 +00:00
|
|
|
"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-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
|
2012-01-06 14:14:37 +00:00
|
|
|
|
|
|
|
matcher :: [Option]
|
|
|
|
matcher =
|
2011-09-18 22:21:42 +00:00
|
|
|
[ 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
|
|
|
|
more command-specific options
Made --from and --to command-specific options.
Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.
(Also added generic storage for command-specific flags, although there are
not yet any.)
Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.
Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
2012-01-06 07:06:25 +00:00
|
|
|
{- An option that sets a flag. -}
|
2012-01-06 14:14:37 +00:00
|
|
|
flag :: String -> String -> String -> Option
|
|
|
|
flag short opt description =
|
|
|
|
Option short [opt] (NoArg (Annex.setFlag opt)) description
|
2012-01-06 02:48:59 +00:00
|
|
|
|
more command-specific options
Made --from and --to command-specific options.
Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.
(Also added generic storage for command-specific flags, although there are
not yet any.)
Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.
Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
2012-01-06 07:06:25 +00:00
|
|
|
{- An option that sets a field. -}
|
2012-01-06 14:14:37 +00:00
|
|
|
field :: String -> String -> String -> String -> Option
|
|
|
|
field short opt paramdesc description =
|
|
|
|
Option short [opt] (ReqArg (Annex.setField opt) paramdesc) description
|
|
|
|
|
|
|
|
{- The flag or field name used for an option. -}
|
|
|
|
name :: Option -> String
|
|
|
|
name (Option _ o _ _) = Prelude.head o
|