Skip to content

Commit

Permalink
Added version information, closes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
maurotrb committed Sep 13, 2013
1 parent 5d559ac commit 69fb4b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ main :: IO ()
main = OA.customExecParser (OA.prefs OA.showHelpOnError) optionsPI >>= haskdeep

haskdeep :: Options -> IO ()
haskdeep Version = putStrLn haskdeepVersion
haskdeep (Options OptComputation OptMD5 conf) = execComputation conf md5hash
haskdeep (Options OptComputation OptSHA1 conf) = execComputation conf sha1hash
haskdeep (Options OptComputation OptSHA256 conf) = execComputation conf sha256hash
Expand Down
51 changes: 31 additions & 20 deletions src/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Options
,OptExecution(..)
,OptCompMode(..)
,optionsPI
,haskdeepVersion
)
where

Expand All @@ -29,7 +30,11 @@ import Options.Applicative

import HaskDeep

data Options = Options OptExecution OptCompMode HaskDeepConfiguration
haskdeepVersion :: String
haskdeepVersion = "haskdeep 0.1.0.0 - file hashing and audit"

data Options = Version
| Options OptExecution OptCompMode HaskDeepConfiguration

data OptExecution = OptComputation
| OptAudit
Expand All @@ -40,10 +45,10 @@ data OptCompMode = OptMD5
| OptSkein512

optionsPI :: ParserInfo Options
optionsPI = info (optionsP <**> helper)
optionsPI = info (helper <*> optionsP)
( fullDesc
<> progDesc "Computes hashes and audit a set of files"
<> header "haskdeep - file hashing and audit" )
<> header haskdeepVersion)

configurationP :: Parser HaskDeepConfiguration
configurationP = HaskDeepConfiguration
Expand All @@ -67,25 +72,31 @@ configurationP = HaskDeepConfiguration
<> metavar "RULE"
<> help "Regex to ignore files or directories"
<> reader ignReader
<> value (ignoreRule defaultHaskDeepConfiguration))
<> value (ignoreRule defaultHaskDeepConfiguration)
<> hidden )

optionsP :: Parser Options
optionsP = Options
<$> subparser
( command "compute"
(info (pure OptComputation)
(progDesc "Computes file hashes and saves them to known hashes file"))
<> command "audit"
(info (pure OptAudit)
(progDesc "Audit files comparing them to known hashes")))
<*> nullOption
( long "computation"
<> short 'c'
<> metavar "MODE"
<> help "md5 | sha1 | sha256 | skein512 - default md5"
<> reader compReader
<> value OptMD5)
<*> configurationP
optionsP = flag' Version
( long "version"
<> short 'v'
<> help "Show version information"
<> hidden )
<|> ( Options
<$> subparser
( command "compute"
(info (pure OptComputation)
(progDesc "Computes file hashes and saves them to known hashes file"))
<> command "audit"
(info (pure OptAudit)
(progDesc "Audit files comparing them to known hashes")))
<*> nullOption
( long "computation"
<> short 'c'
<> metavar "MODE"
<> help "md5 | sha1 | sha256 | skein512 - default md5"
<> reader compReader
<> value OptMD5)
<*> configurationP )

fpReader :: String -> Either ParseError FilePath
fpReader fp = Right $ FSC.decodeString fp
Expand Down

0 comments on commit 69fb4b2

Please sign in to comment.