2013-03-27 17:51:24 +00:00
|
|
|
{- common command-line options
|
2010-12-30 20:52:24 +00:00
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010-2011 Joey Hess <id@joeyh.name>
|
2010-12-30 20:52:24 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2014-01-26 20:25:55 +00:00
|
|
|
module CmdLine.Option (
|
|
|
|
commonOptions,
|
|
|
|
flagOption,
|
|
|
|
fieldOption,
|
|
|
|
optionName,
|
2015-02-08 19:04:58 +00:00
|
|
|
optionParam,
|
2012-01-06 02:48:59 +00:00
|
|
|
ArgDescr(..),
|
|
|
|
OptDescr(..),
|
|
|
|
) where
|
2010-12-30 20:52:24 +00:00
|
|
|
|
|
|
|
import System.Console.GetOpt
|
|
|
|
|
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
|
2014-03-22 14:42:38 +00:00
|
|
|
import Types.DesktopNotify
|
2014-01-26 20:25:55 +00:00
|
|
|
import CmdLine.Usage
|
2010-12-30 20:52:24 +00:00
|
|
|
|
2015-02-06 21:08:14 +00:00
|
|
|
-- Options accepted by both git-annex and git-annex-shell sub-commands.
|
2014-01-26 20:25:55 +00:00
|
|
|
commonOptions :: [Option]
|
|
|
|
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"
|
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-02-16 04:41:30 +00:00
|
|
|
, Option ['d'] ["debug"] (NoArg setdebug)
|
2011-05-21 15:52:13 +00:00
|
|
|
"show debug messages"
|
2013-06-18 00:41:17 +00:00
|
|
|
, Option [] ["no-debug"] (NoArg unsetdebug)
|
|
|
|
"don't show debug messages"
|
2011-05-18 23:34:46 +00:00
|
|
|
, Option ['b'] ["backend"] (ReqArg setforcebackend paramName)
|
|
|
|
"specify key-value backend to use"
|
2014-03-22 14:42:38 +00:00
|
|
|
, Option [] ["notify-finish"] (NoArg (setdesktopnotify mkNotifyFinish))
|
|
|
|
"show desktop notification after transfer finishes"
|
|
|
|
, Option [] ["notify-start"] (NoArg (setdesktopnotify mkNotifyStart))
|
|
|
|
"show desktop notification after transfer completes"
|
2010-12-31 17:39:30 +00:00
|
|
|
]
|
2012-10-29 01:27:15 +00:00
|
|
|
where
|
|
|
|
setforce v = Annex.changeState $ \s -> s { Annex.force = v }
|
|
|
|
setfast v = Annex.changeState $ \s -> s { Annex.fast = v }
|
|
|
|
setforcebackend v = Annex.changeState $ \s -> s { Annex.forcebackend = Just v }
|
2013-06-18 00:41:17 +00:00
|
|
|
setdebug = Annex.changeGitConfig $ \c -> c { annexDebug = True }
|
|
|
|
unsetdebug = Annex.changeGitConfig $ \c -> c { annexDebug = False }
|
2014-03-22 14:42:38 +00:00
|
|
|
setdesktopnotify v = Annex.changeState $ \s -> s { Annex.desktopnotify = Annex.desktopnotify s <> v }
|
2012-01-06 14:14:37 +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. -}
|
2014-01-26 20:25:55 +00:00
|
|
|
flagOption :: String -> String -> String -> Option
|
|
|
|
flagOption short opt description =
|
2012-01-06 14:14:37 +00:00
|
|
|
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. -}
|
2014-01-26 20:25:55 +00:00
|
|
|
fieldOption :: String -> String -> String -> String -> Option
|
|
|
|
fieldOption short opt paramdesc description =
|
2012-01-06 14:14:37 +00:00
|
|
|
Option short [opt] (ReqArg (Annex.setField opt) paramdesc) description
|
|
|
|
|
|
|
|
{- The flag or field name used for an option. -}
|
2014-01-26 20:25:55 +00:00
|
|
|
optionName :: Option -> String
|
|
|
|
optionName (Option _ o _ _) = Prelude.head o
|
2015-02-08 19:04:58 +00:00
|
|
|
|
|
|
|
optionParam :: Option -> String
|
|
|
|
optionParam o = "--" ++ optionName o
|