From ceff04ff3e7fff4b0ea6e8ad4334cca80d291880 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 16 May 2011 12:25:54 -0400 Subject: [PATCH] better multiword parameter handling This way, individual words as entered on the command line are available to commands. --- Command.hs | 6 ++++-- Command/Describe.hs | 8 ++++---- Command/Init.hs | 8 +++++--- Command/InitRemote.hs | 9 +++++---- Command/Semitrust.hs | 7 ++++--- Command/Trust.hs | 7 ++++--- Command/Untrust.hs | 7 ++++--- 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Command.hs b/Command.hs index 4f835a3adc..abbe897b5b 100644 --- a/Command.hs +++ b/Command.hs @@ -47,6 +47,8 @@ type CommandCleanup = Annex Bool - functions. -} type CommandSeekStrings = CommandStartString -> CommandSeek type CommandStartString = String -> CommandStart +type CommandSeekWords = CommandStartWords -> CommandSeek +type CommandStartWords = [String] -> CommandStart type CommandSeekKeys = CommandStartKey -> CommandSeek type CommandStartKey = Key -> CommandStart type BackendFile = (FilePath, Maybe (Backend Annex)) @@ -143,8 +145,8 @@ withFilesNotInGit a params = do newfiles <- liftIO $ runPreserveOrder (Git.notInRepo repo) params newfiles' <- filterFiles newfiles backendPairs a newfiles' -withString :: CommandSeekStrings -withString a params = return [a $ unwords params] +withWords :: CommandSeekWords +withWords a params = return [a params] withStrings :: CommandSeekStrings withStrings a params = return $ map a params withFilesToBeCommitted :: CommandSeekStrings diff --git a/Command/Describe.hs b/Command/Describe.hs index dcabef7fbf..57f884e037 100644 --- a/Command/Describe.hs +++ b/Command/Describe.hs @@ -18,12 +18,12 @@ command = [repoCommand "describe" (paramPair paramRemote paramDesc) seek "change description of a repository"] seek :: [CommandSeek] -seek = [withString start] +seek = [withWords start] -start :: CommandStartString -start params = notBareRepo $ do +start :: CommandStartWords +start ws = notBareRepo $ do let (name, description) = - case (words params) of + case ws of (n:d) -> (n,unwords d) _ -> error "Specify a repository and a description." diff --git a/Command/Init.hs b/Command/Init.hs index 668b5c87d6..b7a0787991 100644 --- a/Command/Init.hs +++ b/Command/Init.hs @@ -27,15 +27,17 @@ command = [repoCommand "init" paramDesc seek "initialize git-annex with repository description"] seek :: [CommandSeek] -seek = [withString start] +seek = [withWords start] {- Stores description for the repository etc. -} -start :: CommandStartString -start description = do +start :: CommandStartWords +start ws = do when (null description) $ error "please specify a description of this repository\n" showStart "init" description next $ perform description + where + description = unwords ws perform :: String -> CommandPerform perform description = do diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs index 261ccdc8b7..ae22e3564e 100644 --- a/Command/InitRemote.hs +++ b/Command/InitRemote.hs @@ -28,21 +28,22 @@ command = [repoCommand "initremote" "sets up a special (non-git) remote"] seek :: [CommandSeek] -seek = [withString start] +seek = [withWords start] -start :: CommandStartString -start params = notBareRepo $ do +start :: CommandStartWords +start ws = notBareRepo $ do when (null ws) $ error "Specify a name for the remote" (u, c) <- findByName name let fullconfig = M.union config c t <- findType fullconfig + liftIO $ putStrLn $ show fullconfig + showStart "initremote" name next $ perform t u $ M.union config c where - ws = words params name = head ws config = Remote.keyValToConfig $ tail ws diff --git a/Command/Semitrust.hs b/Command/Semitrust.hs index fc1bcbbcdc..11742137f1 100644 --- a/Command/Semitrust.hs +++ b/Command/Semitrust.hs @@ -18,10 +18,11 @@ command = [repoCommand "semitrust" (paramRepeating paramRemote) seek "return repository to default trust level"] seek :: [CommandSeek] -seek = [withString start] +seek = [withWords start] -start :: CommandStartString -start name = notBareRepo $ do +start :: CommandStartWords +start ws = notBareRepo $ do + let name = unwords ws showStart "semitrust" name u <- Remote.nameToUUID name next $ perform u diff --git a/Command/Trust.hs b/Command/Trust.hs index ef03828c23..d5444affe6 100644 --- a/Command/Trust.hs +++ b/Command/Trust.hs @@ -18,10 +18,11 @@ command = [repoCommand "trust" (paramRepeating paramRemote) seek "trust a repository"] seek :: [CommandSeek] -seek = [withString start] +seek = [withWords start] -start :: CommandStartString -start name = notBareRepo $ do +start :: CommandStartWords +start ws = notBareRepo $ do + let name = unwords ws showStart "trust" name u <- Remote.nameToUUID name next $ perform u diff --git a/Command/Untrust.hs b/Command/Untrust.hs index ebe9c31b3b..174c395066 100644 --- a/Command/Untrust.hs +++ b/Command/Untrust.hs @@ -18,10 +18,11 @@ command = [repoCommand "untrust" (paramRepeating paramRemote) seek "do not trust a repository"] seek :: [CommandSeek] -seek = [withString start] +seek = [withWords start] -start :: CommandStartString -start name = notBareRepo $ do +start :: CommandStartWords +start ws = notBareRepo $ do + let name = unwords ws showStart "untrust" name u <- Remote.nameToUUID name next $ perform u