aboutsummaryrefslogtreecommitdiff
path: root/CmdLine/Option.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-10 00:55:53 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-10 01:39:06 -0400
commit56c0bf6c690ffddc4ac561393f4cd21d087b7ddb (patch)
tree745ab36efe39f693d776a16a73758e04409f74a1 /CmdLine/Option.hs
parentea0f914261e4747de75339952c2d47374c5a7803 (diff)
convert global options (still not used)
Diffstat (limited to 'CmdLine/Option.hs')
-rw-r--r--CmdLine/Option.hs68
1 files changed, 39 insertions, 29 deletions
diff --git a/CmdLine/Option.hs b/CmdLine/Option.hs
index 0cda34ba1..9cb1d41d4 100644
--- a/CmdLine/Option.hs
+++ b/CmdLine/Option.hs
@@ -6,7 +6,7 @@
-}
module CmdLine.Option (
- commonOptions,
+ commonGlobalOptions,
flagOption,
fieldOption,
optionName,
@@ -15,35 +15,46 @@ module CmdLine.Option (
OptDescr(..),
) where
+import Options.Applicative
import System.Console.GetOpt
import Common.Annex
+import CmdLine.Usage
import qualified Annex
import Types.Messages
-import Types.DesktopNotify
-import CmdLine.Usage
+import Types.DeferredParse
--- Options accepted by both git-annex and git-annex-shell sub-commands.
-commonOptions :: [Option]
-commonOptions =
- [ Option [] ["force"] (NoArg (setforce True))
- "allow actions that may lose annexed data"
- , Option ['F'] ["fast"] (NoArg (setfast True))
- "avoid slow operations"
- , Option ['q'] ["quiet"] (NoArg (Annex.setOutput QuietOutput))
- "avoid verbose output"
- , Option ['v'] ["verbose"] (NoArg (Annex.setOutput NormalOutput))
- "allow verbose output (default)"
- , Option ['d'] ["debug"] (NoArg setdebug)
- "show debug messages"
- , Option [] ["no-debug"] (NoArg unsetdebug)
- "don't show debug messages"
- , Option ['b'] ["backend"] (ReqArg setforcebackend paramName)
- "specify key-value backend to use"
- , Option [] ["notify-finish"] (NoArg (setdesktopnotify mkNotifyFinish))
- "show desktop notification after transfer finishes"
- , Option [] ["notify-start"] (NoArg (setdesktopnotify mkNotifyStart))
- "show desktop notification after transfer completes"
+-- Global options accepted by both git-annex and git-annex-shell sub-commands.
+commonGlobalOptions :: Parser GlobalSetter
+commonGlobalOptions = globalSetters
+ [ globalFlag (setforce True)
+ ( long "force"
+ <> help "allow actions that may lose annexed data"
+ )
+ , globalFlag (setfast True)
+ ( long "fast" <> short 'F'
+ <> help "avoid slow operations"
+ )
+ , globalFlag (Annex.setOutput QuietOutput)
+ ( long "quiet" <> short 'q'
+ <> help "avoid verbose output"
+ )
+ , globalFlag (Annex.setOutput NormalOutput)
+ ( long "verbose" <> short 'v'
+ <> help "allow verbose output (default)"
+ )
+ , globalFlag setdebug
+ ( long "debug" <> short 'd'
+ <> help "show debug messages"
+ )
+ , globalFlag unsetdebug
+ ( long "no-debug"
+ <> help "don't show debug messages"
+ )
+ , globalSetter setforcebackend $ strOption
+ ( long "backend" <> short 'b' <> metavar paramName
+ <> help "specify key-value backend to use"
+ )
]
where
setforce v = Annex.changeState $ \s -> s { Annex.force = v }
@@ -51,17 +62,16 @@ commonOptions =
setforcebackend v = Annex.changeState $ \s -> s { Annex.forcebackend = Just v }
setdebug = Annex.changeGitConfig $ \c -> c { annexDebug = True }
unsetdebug = Annex.changeGitConfig $ \c -> c { annexDebug = False }
- setdesktopnotify v = Annex.changeState $ \s -> s { Annex.desktopnotify = Annex.desktopnotify s <> v }
{- An option that sets a flag. -}
flagOption :: String -> String -> String -> Option
-flagOption short opt description =
- Option short [opt] (NoArg (Annex.setFlag opt)) description
+flagOption shortv opt description =
+ Option shortv [opt] (NoArg (Annex.setFlag opt)) description
{- An option that sets a field. -}
fieldOption :: String -> String -> String -> String -> Option
-fieldOption short opt paramdesc description =
- Option short [opt] (ReqArg (Annex.setField opt) paramdesc) description
+fieldOption shortv opt paramdesc description =
+ Option shortv [opt] (ReqArg (Annex.setField opt) paramdesc) description
{- The flag or field name used for an option. -}
optionName :: Option -> String