diff options
author | Joey Hess <joey@kitenet.net> | 2013-11-18 13:51:55 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-11-18 13:51:55 -0400 |
commit | 05355d4aab533d0c55666412b6c250e644bc7088 (patch) | |
tree | 1a6ebddf6cd90cc944df3915809e68f78ce934fc | |
parent | 91345e7d917c38e1bdcf9b2b01a5b7830a73eef7 (diff) | |
download | git-repair-05355d4aab533d0c55666412b6c250e644bc7088.tar.gz |
use optparse-applicative
-rw-r--r-- | debian/control | 3 | ||||
-rw-r--r-- | git-repair.cabal | 2 | ||||
-rw-r--r-- | git-repair.hs | 34 |
3 files changed, 21 insertions, 18 deletions
diff --git a/debian/control b/debian/control index f4999d7..bf14911 100644 --- a/debian/control +++ b/debian/control @@ -12,7 +12,8 @@ Build-Depends: libghc-extensible-exceptions-dev, libghc-unix-compat-dev, libghc-utf8-string-dev, - libghc-async-dev + libghc-async-dev, + libghc-optparse-applicative-dev Maintainer: Joey Hess <joeyh@debian.org> Standards-Version: 3.9.4 Vcs-Git: git://git-repair.branchable.com/ diff --git a/git-repair.cabal b/git-repair.cabal index e649be0..15acb79 100644 --- a/git-repair.cabal +++ b/git-repair.cabal @@ -23,7 +23,7 @@ Executable git-repair Build-Depends: MissingH, hslogger, directory, filepath, containers, mtl, network, extensible-exceptions, unix-compat, bytestring, base >= 4.5, base < 5, IfElse, text, process, - utf8-string, async + utf8-string, async, optparse-applicative if (! os(windows)) Build-Depends: unix diff --git a/git-repair.hs b/git-repair.hs index f726893..9ece7e5 100644 --- a/git-repair.hs +++ b/git-repair.hs @@ -5,34 +5,36 @@ - Licensed under the GNU GPL version 3 or higher. -} -import System.Environment import Data.Tuple.Utils +import Options.Applicative import Common import qualified Git.CurrentRepo import qualified Git.Repair import qualified Git.Config -header :: String -header = "Usage: git-repair" +data Settings = Settings + { forced :: Bool + } -usage :: a -usage = error $ "bad parameters\n\n" ++ header - -parseArgs :: IO Bool -parseArgs = do - args <- getArgs - return $ or $ map parse args +parseSettings :: Parser Settings +parseSettings = Settings + <$> switch forceopt where - parse "--force" = True - parse _ = usage + forceopt = long "force" + <> help "Force recovery, even if data is lost" main :: IO () -main = do - forced <- parseArgs - +main = execParser opts >>= repair + where + opts = info (helper <*> parseSettings) desc + desc = fullDesc + <> header "git-repair - repair a damanged git repository" + +repair :: Settings -> IO () +repair settings = do g <- Git.Config.read =<< Git.CurrentRepo.get - ifM (fst3 <$> Git.Repair.runRepair forced g) + ifM (fst3 <$> Git.Repair.runRepair (forced settings) g) ( exitSuccess , exitFailure ) |