{-# LANGUAGE DeriveDataTypeable, MultiParamTypeClasses, ScopedTypeVariables #-} module CmdLine where import CmdLib import Storage.Hashed.Hash import Core( hdecode ) import qualified Data.ByteString.Char8 as BSC newtype Path = Path String deriving (Show, Typeable, Data, Read) newtype HashF = HashF String deriving (Show, Typeable, Data, Read) data Flag = Repo Path | Root HashF | From Path | To Path deriving (Typeable, Data, Show, Read) instance FlagType Flag where describe (Repo _) = "path to the backup repository" describe (Root _) = "root hash of the backup to select" readFlag _ = fallback <+< Path <+< HashF -- XXX These are a hack, since hashed-storage fails to provide the -- instances. Should be harmless otherwise. instance Typeable Hash instance Data Hash data Setup = Setup { repo :: FilePath , root :: Maybe Hash } deriving (Typeable, Data) instance Combine Setup Flag where combine (Repo (Path p)) f = f { repo = p } combine (Root (HashF p)) f = f { root = Just $ hdecode $ BSC.pack p } combine _ x = x initial = Setup { root = Nothing }