aboutsummaryrefslogtreecommitdiff
path: root/Command/Unused.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-10 16:05:56 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-10 16:05:56 -0400
commitaa96e9c8667b5e80b5ccae1958a073518d463dfa (patch)
treedc4452a8b96b9c47902a17e65541e71c506ec848 /Command/Unused.hs
parent00e37e72e06d3692ea2b5c77dfa6b0147a3b6d6d (diff)
convert Unused, and remove some dead code for old style option parsing
Diffstat (limited to 'Command/Unused.hs')
-rw-r--r--Command/Unused.hs38
1 files changed, 23 insertions, 15 deletions
diff --git a/Command/Unused.hs b/Command/Unused.hs
index c2ca148b7..a383d567b 100644
--- a/Command/Unused.hs
+++ b/Command/Unused.hs
@@ -1,6 +1,6 @@
{- git-annex command
-
- - Copyright 2010-2012 Joey Hess <id@joeyh.name>
+ - Copyright 2010-2015 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -31,6 +31,7 @@ import Annex.CatFile
import Types.Key
import Types.RefSpec
import Git.FilePath
+import Git.Types
import Logs.View (is_branchView)
import Annex.BloomFilter
@@ -38,26 +39,33 @@ cmd :: Command
cmd = -- withGlobalOptions [unusedFromOption, refSpecOption] $
command "unused" SectionMaintenance
"look for unused file content"
- paramNothing (withParams seek)
+ paramNothing (seek <$$> optParser)
-unusedFromOption :: Option
-unusedFromOption = fieldOption ['f'] "from" paramRemote "remote to check for unused content"
+data UnusedOptions = UnusedOptions
+ { fromRemote :: Maybe RemoteName
+ , refSpecOption :: Maybe RefSpec
+ }
-refSpecOption :: Option
-refSpecOption = fieldOption [] "used-refspec" paramRefSpec "refs to consider used (default: all refs)"
+optParser :: CmdParamsDesc -> Parser UnusedOptions
+optParser _ = UnusedOptions
+ <$> optional (strOption
+ ( long "from" <> short 'f' <> metavar paramRemote
+ <> help "remote to check for unused content"
+ ))
+ <*> optional (option (eitherReader parseRefSpec)
+ ( long "unused-refspec" <> metavar paramRefSpec
+ <> help "refs to consider used (default: all branches)"
+ ))
-seek :: CmdParams -> CommandSeek
-seek = withNothing start
+seek :: UnusedOptions -> CommandSeek
+seek = commandAction . start
-{- Finds unused content in the annex. -}
-start :: CommandStart
-start = do
+start :: UnusedOptions -> CommandStart
+start o = do
cfgrefspec <- fromMaybe allRefSpec . annexUsedRefSpec
<$> Annex.getGitConfig
- !refspec <- maybe cfgrefspec (either error id . parseRefSpec)
- <$> Annex.getField (optionName refSpecOption)
- from <- Annex.getField (optionName unusedFromOption)
- let (name, perform) = case from of
+ let refspec = fromMaybe cfgrefspec (refSpecOption o)
+ let (name, perform) = case fromRemote o of
Nothing -> (".", checkUnused refspec)
Just "." -> (".", checkUnused refspec)
Just "here" -> (".", checkUnused refspec)