2014-01-20 20:47:56 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-01-20 20:47:56 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.NumCopies where
|
|
|
|
|
|
|
|
import Command
|
2016-01-20 20:36:33 +00:00
|
|
|
import qualified Annex
|
2015-04-30 18:02:56 +00:00
|
|
|
import Annex.NumCopies
|
2014-01-20 20:47:56 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2017-02-16 17:24:16 +00:00
|
|
|
cmd = noMessages $ command "numcopies" SectionSetup
|
2015-07-08 19:08:02 +00:00
|
|
|
"configure desired number of copies"
|
|
|
|
paramNumber (withParams seek)
|
2014-01-20 20:47:56 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2018-10-01 18:12:06 +00:00
|
|
|
seek = withWords (commandAction . start)
|
2014-01-20 20:47:56 +00:00
|
|
|
|
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start [] = startGet
|
2014-10-09 19:35:19 +00:00
|
|
|
start [s] = case readish s of
|
2016-11-16 01:29:54 +00:00
|
|
|
Nothing -> giveup $ "Bad number: " ++ s
|
2014-10-09 19:35:19 +00:00
|
|
|
Just n
|
|
|
|
| n > 0 -> startSet n
|
|
|
|
| n == 0 -> ifM (Annex.getState Annex.force)
|
|
|
|
( startSet n
|
2016-11-16 01:29:54 +00:00
|
|
|
, giveup "Setting numcopies to 0 is very unsafe. You will lose data! If you really want to do that, specify --force."
|
2014-10-09 19:35:19 +00:00
|
|
|
)
|
2016-11-16 01:29:54 +00:00
|
|
|
| otherwise -> giveup "Number cannot be negative!"
|
|
|
|
start _ = giveup "Specify a single number."
|
2014-01-20 20:47:56 +00:00
|
|
|
|
|
|
|
startGet :: CommandStart
|
|
|
|
startGet = next $ next $ do
|
|
|
|
v <- getGlobalNumCopies
|
|
|
|
case v of
|
2015-10-06 19:26:42 +00:00
|
|
|
Just n -> liftIO $ putStrLn $ show $ fromNumCopies n
|
2014-01-20 20:47:56 +00:00
|
|
|
Nothing -> do
|
2014-10-09 19:35:19 +00:00
|
|
|
liftIO $ putStrLn "global numcopies is not set"
|
2014-01-21 21:08:49 +00:00
|
|
|
old <- deprecatedNumCopies
|
2014-01-20 20:47:56 +00:00
|
|
|
case old of
|
|
|
|
Nothing -> liftIO $ putStrLn "(default is 1)"
|
2014-01-21 21:08:49 +00:00
|
|
|
Just n -> liftIO $ putStrLn $ "(deprecated git config annex.numcopies is set to " ++ show (fromNumCopies n) ++ " locally)"
|
2014-01-20 20:47:56 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
startSet :: Int -> CommandStart
|
|
|
|
startSet n = do
|
2017-02-16 17:24:16 +00:00
|
|
|
allowMessages
|
2017-11-28 18:40:26 +00:00
|
|
|
showStart' "numcopies" (Just $ show n)
|
2014-01-20 20:47:56 +00:00
|
|
|
next $ next $ do
|
2014-01-21 20:08:19 +00:00
|
|
|
setGlobalNumCopies $ NumCopies n
|
2014-01-20 20:47:56 +00:00
|
|
|
return True
|