git-annex/Command/Upgrade.hs

51 lines
1.3 KiB
Haskell
Raw Normal View History

2011-03-16 19:48:26 +00:00
{- git-annex command
-
- Copyright 2011-2020 Joey Hess <id@joeyh.name>
2011-03-16 19:48:26 +00:00
-
- Licensed under the GNU AGPL version 3 or higher.
2011-03-16 19:48:26 +00:00
-}
module Command.Upgrade where
import Command
2011-03-19 22:58:10 +00:00
import Upgrade
2016-03-31 21:20:43 +00:00
import Annex.Version
import Annex.Init
2011-03-16 19:48:26 +00:00
cmd :: Command
cmd = dontCheck
-- because an old version may not seem to exist
-- and also, this avoids automatic silent upgrades before
-- this command can start up.
repoExists $
-- avoid upgrading repo out from under daemon
noDaemonRunning $
command "upgrade" SectionMaintenance "upgrade repository"
paramNothing (seek <$$> optParser)
2011-03-16 19:48:26 +00:00
data UpgradeOptions = UpgradeOptions
{ autoOnly :: Bool
}
2011-03-16 19:48:26 +00:00
optParser :: CmdParamsDesc -> Parser UpgradeOptions
optParser _ = UpgradeOptions
<$> switch
( long "autoonly"
<> help "only do automatic upgrades"
)
seek :: UpgradeOptions -> CommandSeek
seek o = commandAction (start o)
start :: UpgradeOptions -> CommandStart
start (UpgradeOptions { autoOnly = True }) =
starting "upgrade" (ActionItemOther Nothing) (SeekInput []) $ do
getVersion >>= maybe noop checkUpgrade
next $ return True
start _ =
starting "upgrade" (ActionItemOther Nothing) (SeekInput []) $ do
whenM (isNothing <$> getVersion) $ do
initialize Nothing Nothing
r <- upgrade False latestVersion
next $ return r