Commit d3ac9436 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

random-dfa: Optionally output to file instead of stdout

parent ed078088
......@@ -43,6 +43,7 @@ instance Show OutputFormat where
data Options = Options
{ _optStates :: Int
, _optLetters :: Int
, _optFile :: Maybe FilePath
, _optOutputFormat :: OutputFormat
}
makeLensesWith abbreviatedFields ''Options
......@@ -59,6 +60,12 @@ options =
OptParse.auto
(OptParse.metavar "M" <> OptParse.help "Size of the alphabet")
)
<*> optional
(OptParse.strArgument
(OptParse.metavar "OUTPUT_FILE" <> OptParse.help
"Name of the file where the output should be written."
)
)
<*> (OptParse.option
readFormat
( OptParse.long "output-format"
......@@ -88,11 +95,15 @@ main = do
)
)
let builder = case opts^.outputFormat of
MA -> coalgB
let builder = case opts ^. outputFormat of
MA -> coalgB
Dot -> dotB
dfa <- randomDFA (opts ^. states) (opts ^. letters)
TL.putStr (Build.toLazyText (builder dfa))
let text = Build.toLazyText (builder dfa)
case opts ^. file of
Nothing -> TL.putStr text
Just filename -> TL.writeFile filename text
return ()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment