Parse command-line parameters
This commit is contained in:
parent
04036bb047
commit
8f9b082eb4
2 changed files with 57 additions and 4 deletions
41
app/MimaRun.hs
Normal file
41
app/MimaRun.hs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
module MimaRun where
|
||||
|
||||
import Options.Applicative
|
||||
|
||||
data Settings = Settings
|
||||
{ file :: String
|
||||
, steps :: Maybe Integer
|
||||
, memoryDump :: Maybe FilePath
|
||||
, quiet :: Bool
|
||||
, sparseOutput :: Bool
|
||||
} deriving (Show)
|
||||
|
||||
settings :: Parser Settings
|
||||
settings = Settings
|
||||
<$> strArgument
|
||||
(metavar "INFILE"
|
||||
<> help "The memory dump to load and execute")
|
||||
<*> (optional . option auto)
|
||||
(long "steps"
|
||||
<> short 'n'
|
||||
<> metavar "N"
|
||||
<> help "How many instructions to execute (if not specified, runs until HALT or execution exception)")
|
||||
<*> (optional . strOption)
|
||||
(long "dump"
|
||||
<> short 'd'
|
||||
<> metavar "OUTFILE"
|
||||
<> help "If specified, the MiMa's memory is dumped to this file after execution is finished")
|
||||
<*> flag False True
|
||||
(long "quiet"
|
||||
<> short 'q'
|
||||
<> help "Whether to print the memory after execution is finished")
|
||||
<*> flag False True
|
||||
(long "sparse"
|
||||
<> short 's'
|
||||
<> help "Whether to print memory locations that contain 0")
|
||||
|
||||
opts :: ParserInfo Settings
|
||||
opts = info (helper <*> settings) $ fullDesc <> failureCode 1
|
||||
|
||||
main :: IO ()
|
||||
main = execParser opts >>= print
|
||||
Loading…
Add table
Add a link
Reference in a new issue