Some cleanup and optparse
This commit is contained in:
parent
ebdb931e32
commit
d5208cfa34
3 changed files with 33 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
*.cabal
|
||||
result*
|
||||
|
|
41
Main.hs
41
Main.hs
|
@ -3,20 +3,39 @@
|
|||
module Main where
|
||||
|
||||
import Data.Attoparsec.Text (parseOnly)
|
||||
import Data.Either (fromRight)
|
||||
import Options.Applicative
|
||||
import qualified Data.Text.IO as T
|
||||
|
||||
import INAST
|
||||
import INSolver
|
||||
|
||||
data FCInsurersOpt = FCInsurersOpt
|
||||
{ path :: FilePath
|
||||
, intInput :: Int
|
||||
}
|
||||
|
||||
fCInsurersOpt :: Parser FCInsurersOpt
|
||||
fCInsurersOpt = FCInsurersOpt
|
||||
<$> strOption
|
||||
( long "network"
|
||||
<> metavar "PATH"
|
||||
<> help "the path to a file that defines a network" )
|
||||
<*> option auto
|
||||
( long "input"
|
||||
<> metavar "INT"
|
||||
<> help "an integer input to the network" )
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
inputNetwork <- T.readFile "./input.network"
|
||||
T.putStrLn "Using the following input network:"
|
||||
T.putStrLn inputNetwork
|
||||
T.putStrLn "Parsed AST:"
|
||||
let Right insnet = parseOnly insuranceNetworkParser inputNetwork
|
||||
print insnet
|
||||
T.putStrLn "Problem solution, input=3:"
|
||||
print $ solve (3::Int) insnet
|
||||
T.putStrLn "Problem solution, input=6:"
|
||||
print $ solve (6::Int) insnet
|
||||
main = fcinsurers =<< execParser opts
|
||||
where
|
||||
opts = info (fCInsurersOpt <**> helper)
|
||||
( fullDesc
|
||||
<> progDesc "A small command line program that outputs a list of the \
|
||||
\ fewest contributing insurers (by their integer ids)"
|
||||
<> header "Fewest Contributing Insurers (in23)" )
|
||||
|
||||
fcinsurers :: FCInsurersOpt -> IO ()
|
||||
fcinsurers (FCInsurersOpt p i) = do
|
||||
inputNetwork <- T.readFile p
|
||||
print $ fromRight [] $ solve i <$> parseOnly insuranceNetworkParser inputNetwork
|
||||
|
|
|
@ -5,8 +5,9 @@ ghc-options: -Wall -threaded
|
|||
dependencies:
|
||||
- base == 4.*
|
||||
- attoparsec
|
||||
- text
|
||||
- mtl
|
||||
- optparse-applicative
|
||||
- text
|
||||
|
||||
executables:
|
||||
in23:
|
||||
|
|
Loading…
Reference in a new issue