dropped defaultCmd
With recusrion, it doesn't really make sense.
This commit is contained in:
parent
1260adbd77
commit
5f73fd5b66
3 changed files with 8 additions and 19 deletions
19
Commands.hs
19
Commands.hs
|
@ -29,18 +29,16 @@ parseCmd argv = do
|
||||||
(flags, params) <- getopt
|
(flags, params) <- getopt
|
||||||
case (length params) of
|
case (length params) of
|
||||||
0 -> error header
|
0 -> error header
|
||||||
_ -> do
|
_ -> case (lookupCmd (params !! 0)) of
|
||||||
let (cmd, locs) = takeCmd params $ lookupCmd (params !! 0)
|
[] -> error header
|
||||||
|
[(_,cmd)] -> do
|
||||||
|
let locs = drop 1 params
|
||||||
files <- mapM recurseFiles locs
|
files <- mapM recurseFiles locs
|
||||||
return (flags, map cmd $ foldl (++) [] files)
|
return (flags, map cmd $ foldl (++) [] files)
|
||||||
where
|
where
|
||||||
getopt = case getOpt Permute options argv of
|
getopt = case getOpt Permute options argv of
|
||||||
(flags, nonopts, []) -> return (flags, nonopts)
|
(flags, nonopts, []) -> return (flags, nonopts)
|
||||||
(_, _, errs) -> ioError (userError (concat errs ++ usageInfo header options))
|
(_, _, errs) -> ioError (userError (concat errs ++ usageInfo header options))
|
||||||
takeCmd files cmds =
|
|
||||||
if (0 == length cmds)
|
|
||||||
then (defaultCmd, files)
|
|
||||||
else ((snd $ cmds !! 0), drop 1 files)
|
|
||||||
lookupCmd cmd = filter (\(c, a) -> c == cmd) cmds
|
lookupCmd cmd = filter (\(c, a) -> c == cmd) cmds
|
||||||
cmds = [ ("add", addCmd)
|
cmds = [ ("add", addCmd)
|
||||||
, ("get", getCmd)
|
, ("get", getCmd)
|
||||||
|
@ -54,15 +52,6 @@ parseCmd argv = do
|
||||||
(join "|" $ map fst cmds) ++ "] file ..."
|
(join "|" $ map fst cmds) ++ "] file ..."
|
||||||
options = [ Option ['f'] ["force"] (NoArg Force) "allow actions that may loose annexed data" ]
|
options = [ Option ['f'] ["force"] (NoArg Force) "allow actions that may loose annexed data" ]
|
||||||
|
|
||||||
{- 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. -}
|
||||||
addCmd :: FilePath -> Annex ()
|
addCmd :: FilePath -> Annex ()
|
||||||
|
|
2
Core.hs
2
Core.hs
|
@ -58,3 +58,5 @@ inAnnex :: Key -> Annex Bool
|
||||||
inAnnex key = do
|
inAnnex key = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
liftIO $ doesFileExist $ annexLocation g key
|
liftIO $ doesFileExist $ annexLocation g key
|
||||||
|
|
||||||
|
{- -}
|
||||||
|
|
|
@ -39,8 +39,6 @@ Enough broad picture, here's how it actually looks:
|
||||||
* `git annex unannex $file` undoes a `git annex add`. But use `git annex drop`
|
* `git annex unannex $file` undoes a `git annex add`. But use `git annex drop`
|
||||||
if you're just done with a file; only use `unannex` if you
|
if you're just done with a file; only use `unannex` if you
|
||||||
accidentially added a file.
|
accidentially added a file.
|
||||||
* `git annex $file` is a shorthand. If the file
|
|
||||||
is already known, it does `git annex get`, otherwise it does `git annex add`.
|
|
||||||
|
|
||||||
Oh yeah, "$file" in the above can be any number of files, or directories.
|
Oh yeah, "$file" in the above can be any number of files, or directories.
|
||||||
git-annex automatically recurses into directories, but skips files that are
|
git-annex automatically recurses into directories, but skips files that are
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue