From e59ba5a70b6d008afae4f9cfaea7e2495a870937 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 9 Jul 2015 16:20:30 -0400 Subject: [PATCH] refactor --- CmdLine/GitAnnex/Options.hs | 23 +---------------------- Command.hs | 1 + Types/DeferredParse.hs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 Types/DeferredParse.hs diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index fb1b81acf9..c027c602cc 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -5,8 +5,6 @@ - Licensed under the GNU GPL version 3 or higher. -} -{-# LANGUAGE FlexibleInstances #-} - module CmdLine.GitAnnex.Options where import System.Console.GetOpt @@ -20,6 +18,7 @@ import Types.NumCopies import Types.Messages import Types.Key import Types.Command +import Types.DeferredParse import qualified Annex import qualified Remote import qualified Limit @@ -56,26 +55,6 @@ gitAnnexOptions = commonOptions ++ >>= pure . (\r -> r { gitGlobalOpts = gitGlobalOpts r ++ [Param "-c", Param v] }) >>= Annex.changeGitRepo --- Some values cannot be fully parsed without performing an action. --- The action may be expensive, so it's best to call finishParse on such a --- value before using getParsed repeatedly. -data DeferredParse a = DeferredParse (Annex a) | ReadyParse a - -class DeferredParseClass a where - finishParse :: a -> Annex a - -getParsed :: DeferredParse a -> Annex a -getParsed (DeferredParse a) = a -getParsed (ReadyParse a) = pure a - -instance DeferredParseClass (DeferredParse a) where - finishParse (DeferredParse a) = ReadyParse <$> a - finishParse (ReadyParse a) = pure (ReadyParse a) - -instance DeferredParseClass (Maybe (DeferredParse a)) where - finishParse Nothing = pure Nothing - finishParse (Just v) = Just <$> finishParse v - parseRemoteOption :: Parser RemoteName -> Parser (DeferredParse Remote) parseRemoteOption p = DeferredParse . (fromJust <$$> Remote.byNameWithUUID) . Just <$> p diff --git a/Command.hs b/Command.hs index df72ad2a71..019a657aa0 100644 --- a/Command.hs +++ b/Command.hs @@ -27,6 +27,7 @@ import qualified Backend import qualified Git import Types.Command as ReExported import Types.Option as ReExported +import Types.DeferredParse as ReExported import CmdLine.Seek as ReExported import Checks as ReExported import CmdLine.Usage as ReExported diff --git a/Types/DeferredParse.hs b/Types/DeferredParse.hs new file mode 100644 index 0000000000..2f463de353 --- /dev/null +++ b/Types/DeferredParse.hs @@ -0,0 +1,33 @@ +{- git-annex deferred parse values + - + - Copyright 2015 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +{-# LANGUAGE FlexibleInstances #-} + +module Types.DeferredParse where + +import Annex +import Common + +-- Some values cannot be fully parsed without performing an action. +-- The action may be expensive, so it's best to call finishParse on such a +-- value before using getParsed repeatedly. +data DeferredParse a = DeferredParse (Annex a) | ReadyParse a + +class DeferredParseClass a where + finishParse :: a -> Annex a + +getParsed :: DeferredParse a -> Annex a +getParsed (DeferredParse a) = a +getParsed (ReadyParse a) = pure a + +instance DeferredParseClass (DeferredParse a) where + finishParse (DeferredParse a) = ReadyParse <$> a + finishParse (ReadyParse a) = pure (ReadyParse a) + +instance DeferredParseClass (Maybe (DeferredParse a)) where + finishParse Nothing = pure Nothing + finishParse (Just v) = Just <$> finishParse v