Parse command-line options
This commit is contained in:
parent
975c5e4116
commit
362025c8df
3 changed files with 35 additions and 1 deletions
|
|
@ -1,4 +1,10 @@
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
|
import Options.Applicative
|
||||||
|
|
||||||
|
import Mima.MimaRun.Options
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = putStrLn "In the beginning, there was nothing."
|
main = do
|
||||||
|
opts <- execParser parserInfo
|
||||||
|
putStrLn $ "The options are: " ++ show opts
|
||||||
|
|
|
||||||
27
mima-run/Mima/MimaRun/Options.hs
Normal file
27
mima-run/Mima/MimaRun/Options.hs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
module Mima.MimaRun.Options
|
||||||
|
( Options(..)
|
||||||
|
, parserInfo
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Options.Applicative
|
||||||
|
|
||||||
|
data Options = Options
|
||||||
|
{ inputFile :: FilePath
|
||||||
|
, steps :: Maybe Integer
|
||||||
|
} deriving (Show)
|
||||||
|
|
||||||
|
parser :: Parser Options
|
||||||
|
parser = Options
|
||||||
|
<$> strOption
|
||||||
|
( help "The .mima file to use"
|
||||||
|
<> metavar "INPUTFILE"
|
||||||
|
)
|
||||||
|
<*> (optional . option auto)
|
||||||
|
( short 'n'
|
||||||
|
<> long "steps"
|
||||||
|
<> help "Maximum number of steps to execute"
|
||||||
|
<> metavar "STEPS"
|
||||||
|
)
|
||||||
|
|
||||||
|
parserInfo :: ParserInfo Options
|
||||||
|
parserInfo = info (parser <**> helper) (failureCode 1)
|
||||||
|
|
@ -19,6 +19,7 @@ dependencies:
|
||||||
- binary
|
- binary
|
||||||
- bytestring
|
- bytestring
|
||||||
- containers
|
- containers
|
||||||
|
- optparse-applicative
|
||||||
- text
|
- text
|
||||||
- transformers
|
- transformers
|
||||||
- unordered-containers
|
- unordered-containers
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue