summaryrefslogtreecommitdiff
path: root/git-repair.hs
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2013-11-18 13:51:55 -0400
committerJoey Hess <joey@kitenet.net>2013-11-18 13:51:55 -0400
commit05355d4aab533d0c55666412b6c250e644bc7088 (patch)
tree1a6ebddf6cd90cc944df3915809e68f78ce934fc /git-repair.hs
parent91345e7d917c38e1bdcf9b2b01a5b7830a73eef7 (diff)
downloadgit-repair-05355d4aab533d0c55666412b6c250e644bc7088.tar.gz
use optparse-applicative
Diffstat (limited to 'git-repair.hs')
-rw-r--r--git-repair.hs34
1 files changed, 18 insertions, 16 deletions
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
)