From cfdcf25d13eaa2a6a8b2601a50fda4370645c639 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 20 Feb 2014 15:12:35 -0400 Subject: refactor --- Command/Dead.hs | 27 +++------------------------ Command/Semitrust.hs | 19 +++---------------- Command/Trust.hs | 31 ++++++++++++++++++------------- Command/Untrust.hs | 19 +++---------------- 4 files changed, 27 insertions(+), 69 deletions(-) (limited to 'Command') diff --git a/Command/Dead.hs b/Command/Dead.hs index 13aa74bff..f9e5c2e27 100644 --- a/Command/Dead.hs +++ b/Command/Dead.hs @@ -7,34 +7,13 @@ module Command.Dead where -import Common.Annex import Command -import qualified Remote -import Logs.Trust -import Logs.Group - -import qualified Data.Set as S +import Types.TrustLevel +import Command.Trust (trustCommand) def :: [Command] def = [command "dead" (paramRepeating paramRemote) seek SectionSetup "hide a lost repository"] seek :: CommandSeek -seek = withWords start - -start :: [String] -> CommandStart -start ws = do - let name = unwords ws - showStart "dead" name - u <- Remote.nameToUUID name - next $ perform u - -perform :: UUID -> CommandPerform -perform uuid = do - markDead uuid - next $ return True - -markDead :: UUID -> Annex () -markDead uuid = do - trustSet uuid DeadTrusted - groupSet uuid S.empty +seek = trustCommand "dead" DeadTrusted diff --git a/Command/Semitrust.hs b/Command/Semitrust.hs index 26ce6961b..edba27346 100644 --- a/Command/Semitrust.hs +++ b/Command/Semitrust.hs @@ -7,26 +7,13 @@ module Command.Semitrust where -import Common.Annex import Command -import qualified Remote -import Logs.Trust +import Types.TrustLevel +import Command.Trust (trustCommand) def :: [Command] def = [command "semitrust" (paramRepeating paramRemote) seek SectionSetup "return repository to default trust level"] seek :: CommandSeek -seek = withWords start - -start :: [String] -> CommandStart -start ws = do - let name = unwords ws - showStart "semitrust" name - u <- Remote.nameToUUID name - next $ perform u - -perform :: UUID -> CommandPerform -perform uuid = do - trustSet uuid SemiTrusted - next $ return True +seek = trustCommand "semitrust" SemiTrusted diff --git a/Command/Trust.hs b/Command/Trust.hs index 3898af347..6f7d6de5f 100644 --- a/Command/Trust.hs +++ b/Command/Trust.hs @@ -1,6 +1,6 @@ {- git-annex command - - - Copyright 2010 Joey Hess + - Copyright 2010, 2014 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -11,22 +11,27 @@ import Common.Annex import Command import qualified Remote import Logs.Trust +import Logs.Group + +import qualified Data.Set as S def :: [Command] def = [command "trust" (paramRepeating paramRemote) seek SectionSetup "trust a repository"] seek :: CommandSeek -seek = withWords start - -start :: [String] -> CommandStart -start ws = do - let name = unwords ws - showStart "trust" name - u <- Remote.nameToUUID name - next $ perform u +seek = trustCommand "trust" Trusted -perform :: UUID -> CommandPerform -perform uuid = do - trustSet uuid Trusted - next $ return True +trustCommand :: String -> TrustLevel -> CommandSeek +trustCommand cmd level = withWords start + where + start ws = do + let name = unwords ws + showStart cmd name + u <- Remote.nameToUUID name + next $ perform u + perform uuid = do + trustSet uuid level + when (level == DeadTrusted) $ + groupSet uuid S.empty + next $ return True diff --git a/Command/Untrust.hs b/Command/Untrust.hs index cde1eee93..4c1035dcd 100644 --- a/Command/Untrust.hs +++ b/Command/Untrust.hs @@ -7,26 +7,13 @@ module Command.Untrust where -import Common.Annex import Command -import qualified Remote -import Logs.Trust +import Types.TrustLevel +import Command.Trust (trustCommand) def :: [Command] def = [command "untrust" (paramRepeating paramRemote) seek SectionSetup "do not trust a repository"] seek :: CommandSeek -seek = withWords start - -start :: [String] -> CommandStart -start ws = do - let name = unwords ws - showStart "untrust" name - u <- Remote.nameToUUID name - next $ perform u - -perform :: UUID -> CommandPerform -perform uuid = do - trustSet uuid UnTrusted - next $ return True +seek = trustCommand "untrust" UnTrusted -- cgit v1.2.3