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 02:48:59 +00:00
|
|
|
module Options (
|
|
|
|
commonOptions,
|
|
|
|
matcherOptions,
|
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
|
|
|
flagOption,
|
|
|
|
fieldOption,
|
2012-01-06 02:48:59 +00:00
|
|
|
ArgDescr(..),
|
|
|
|
Option,
|
|
|
|
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
|
2011-09-18 22:21:42 +00:00
|
|
|
import Limit
|
2012-01-06 02:48:59 +00:00
|
|
|
import Types.Option
|
|
|
|
import Usage
|
2010-12-30 20:52:24 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
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. -}
|
|
|
|
flagOption :: String -> String -> String -> Option
|
|
|
|
flagOption short flag description =
|
|
|
|
Option short [flag] (NoArg (Annex.setFlag flag)) 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. -}
|
|
|
|
fieldOption :: String -> String -> String -> String -> Option
|
|
|
|
fieldOption short field paramdesc description =
|
|
|
|
Option short [field] (ReqArg (Annex.setField field) paramdesc) description
|