default command

This commit is contained in:
Joey Hess 2010-10-14 12:36:40 -04:00
parent 0f12bd16d8
commit 282d985368
2 changed files with 18 additions and 8 deletions

View file

@ -14,7 +14,7 @@ import System.Console.GetOpt
import Types import Types
import Commands import Commands
data Mode = Add | Push | Pull | Want | Get | Drop | Unannex data Mode = Default | Add | Push | Pull | Want | Get | Drop | Unannex
deriving Show deriving Show
options :: [OptDescr Mode] options :: [OptDescr Mode]
@ -30,8 +30,7 @@ options =
argvToMode argv = do argvToMode argv = do
case getOpt Permute options argv of case getOpt Permute options argv of
-- default mode is Add ([],files,[]) -> return (Default, files)
([],files,[]) -> return (Add, files)
-- one mode is normal case -- one mode is normal case
(m:[],files,[]) -> return (m, files) (m:[],files,[]) -> return (m, files)
-- multiple modes is an error -- multiple modes is an error
@ -43,7 +42,8 @@ argvToMode argv = do
dispatch :: Mode -> FilePath -> Annex () dispatch :: Mode -> FilePath -> Annex ()
dispatch mode item = do dispatch mode item = do
case (mode) of case (mode) of
Add -> annexCmd item Default -> defaultCmd item
Add -> addCmd item
Push -> pushCmd item Push -> pushCmd item
Pull -> pullCmd item Pull -> pullCmd item
Want -> wantCmd item Want -> wantCmd item

View file

@ -1,7 +1,8 @@
{- git-annex subcommands -} {- git-annex subcommands -}
module Commands ( module Commands (
annexCmd, defaultCmd,
addCmd,
unannexCmd, unannexCmd,
getCmd, getCmd,
wantCmd, wantCmd,
@ -25,10 +26,19 @@ import UUID
import LocationLog import LocationLog
import Types import Types
{- Default mode is to annex a file if it is not already, and otherwise
- get its content. -}
defaultCmd :: FilePath -> Annex ()
defaultCmd file = do
r <- liftIO $ Backend.lookupFile file
case (r) of
Just v -> getCmd file
Nothing -> addCmd file
{- Annexes a file, storing it in a backend, and then moving it into {- Annexes a file, storing it in a backend, and then moving it into
- the annex directory and setting up the symlink pointing to its content. -} - the annex directory and setting up the symlink pointing to its content. -}
annexCmd :: FilePath -> Annex () addCmd :: FilePath -> Annex ()
annexCmd file = inBackend file err $ do addCmd file = inBackend file err $ do
liftIO $ checkLegal file liftIO $ checkLegal file
stored <- Backend.storeFile file stored <- Backend.storeFile file
g <- Annex.gitRepo g <- Annex.gitRepo
@ -63,7 +73,7 @@ annexCmd file = inBackend file err $ do
subdirs = (length $ split "/" file) - 1 subdirs = (length $ split "/" file) - 1
{- Inverse of annexCmd. -} {- Inverse of addCmd. -}
unannexCmd :: FilePath -> Annex () unannexCmd :: FilePath -> Annex ()
unannexCmd file = notinBackend file err $ \(key, backend) -> do unannexCmd file = notinBackend file err $ \(key, backend) -> do
Backend.dropFile backend key Backend.dropFile backend key