Skip to content

Commit

Permalink
Add optparse-applicative
Browse files Browse the repository at this point in the history
  • Loading branch information
stoeffel committed Oct 25, 2021
1 parent 5685c34 commit 7dfbaec
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
46 changes: 44 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,65 @@ import qualified Control.Monad
import qualified Data.Foldable
import qualified Haskell.Verify.Examples as HVE
import NriPrelude
import Options.Applicative ((<**>))
import qualified Options.Applicative as OA
import qualified System.Directory
import qualified System.Environment
import System.FilePath.Find ((&&?), (==?))
import qualified System.FilePath.Find as Find
import Prelude ((<>))
import qualified Prelude

data Options = Options
{ files :: List Prelude.FilePath,
showTodos :: ShowTodos
}
deriving (Show)

data ShowTodos = ShowTodos | HideTodos
deriving (Show)

optionsParser :: OA.Parser Options
optionsParser =
map2
Options
( OA.many
<| OA.strOption
( OA.metavar "FILES"
<> OA.help "Specific files to verify"
)
)
( OA.flag
HideTodos
ShowTodos
( OA.long "todos"
<> OA.short 't'
<> OA.help "Show examples that don't have a verified result yet."
)
)

optionsInfo :: OA.ParserInfo Options
optionsInfo =
OA.info
(optionsParser <**> OA.helper)
( OA.fullDesc
<> OA.progDesc "Verify that your examples are correct."
<> OA.header "haskell-verify-examples"
)

main :: Prelude.IO ()
main = do
logHandler <- Platform.silentHandler
handler <- HVE.handler logHandler
cwd <- System.Directory.getCurrentDirectory
params <- System.Environment.getArgs
files <- case params of
options <- OA.execParser optionsInfo
let _ = Debug.log "opts" options
files' <- case files options of
[file] -> Prelude.pure [file]
[] -> Find.find (noRCS &&? noDist) (Find.extension ==? ".hs") cwd
results <-
files
files'
|> List.map
( \modulePath -> do
parsed <- HVE.parse handler modulePath
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ executables:
- haskell-verify-examples
- hint >= 0.9.0.4 && < 0.10
- nri-prelude >= 0.1.0.0 && < 0.7
- optparse-applicative >= 0.16.1.0 && < 0.17
- text >= 1.2.3.1 && < 1.3
main: Main.hs
source-dirs: app
Expand Down

0 comments on commit 7dfbaec

Please sign in to comment.