diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-08-20 17:18:21 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-08-20 17:21:14 -0400 |
commit | 2c7e74b116e10112e9f4f5d9f22a93ae7e4bee9e (patch) | |
tree | 8a1665fa6cdb115fbaa57210a882aa4fdb6124aa | |
parent | 18067656af26fea271a0b75246cbf71af9c72114 (diff) |
make sync --no-content be accepted
It's the default, but this is a step toward changing that default later..
-rw-r--r-- | Command/Sync.hs | 6 | ||||
-rw-r--r-- | Utility/OptParse.hs | 45 |
2 files changed, 48 insertions, 3 deletions
diff --git a/Command/Sync.hs b/Command/Sync.hs index 46a03a4de..87a0fbcf6 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -47,6 +47,7 @@ import Annex.AutoMerge import Annex.Ssh import Annex.BloomFilter import Utility.Bloom +import Utility.OptParse import Control.Concurrent.MVar import qualified Data.Map as M @@ -67,9 +68,8 @@ data SyncOptions = SyncOptions optParser :: CmdParamsDesc -> Parser SyncOptions optParser desc = SyncOptions <$> cmdParams desc - <*> switch - ( long "content" - <> help "also transfer file contents" + <*> invertableSwitch "content" False + ( help "also transfer file contents" ) <*> optional (strOption ( long "message" <> short 'm' <> metavar "MSG" diff --git a/Utility/OptParse.hs b/Utility/OptParse.hs new file mode 100644 index 000000000..f58e8fadf --- /dev/null +++ b/Utility/OptParse.hs @@ -0,0 +1,45 @@ +{- optparse-applicative additions + - + - Copyright 2015 Joey Hess <id@joeyh.name> + - + - License: BSD-2-clause + -} + +module Utility.OptParse where + +import Options.Applicative +import Data.Monoid + +-- | A switch that can be enabled using --foo and disabled using --no-foo. +-- +-- The option modifier is applied to only the option that is *not* enabled +-- by default. For example: +-- +-- > invertableSwitch "recursive" True (help "do not recurse into directories") +-- +-- This example makes --recursive enabled by default, so +-- the help is shown only for --no-recursive. +invertableSwitch + :: String -- ^ long option + -> Bool -- ^ is switch enabled by default? + -> Mod FlagFields Bool -- ^ option modifier + -> Parser Bool +invertableSwitch longopt defv optmod = invertableSwitch' longopt defv + (if defv then mempty else optmod) + (if defv then optmod else mempty) + +-- | Allows providing option modifiers for both --foo and --no-foo. +invertableSwitch' + :: String -- ^ long option (eg "foo") + -> Bool -- ^ is switch enabled by default? + -> Mod FlagFields Bool -- ^ option modifier for --foo + -> Mod FlagFields Bool -- ^ option modifier for --no-foo + -> Parser Bool +invertableSwitch' longopt defv enmod dismod = collapse <$> many + ( flag' True (enmod <> long longopt) + <|> flag' False (dismod <> long nolongopt) + ) + where + nolongopt = "no-" ++ longopt + collapse [] = defv + collapse l = last l |