Commit 5f6672e9 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢
Browse files

main: Switch to sub-command style CLI

This introduces the new sub-command `refine` that does what running the
binary without sub-command previously did.

This opens up the possibility for further sub-commands and improves
discoverability.
parent 4158995a
...@@ -11,11 +11,13 @@ In the absence of a project name: This is my master's thesis ...@@ -11,11 +11,13 @@ In the absence of a project name: This is my master's thesis
There isn't much to see, yet. To see pretty printed parse results, There isn't much to see, yet. To see pretty printed parse results,
use: use:
stack exec ma < FILENAME stack exec ma refine < FILENAME
Where `FILENAME` is a file describing the input. Examples are in Where `FILENAME` is a file describing the input. Examples are in
`examples/`. `examples/`.
Command line syntax is described in `stack exec -- ma --help`.
## API documentation ## API documentation
The documentation for the internal API can be built and opened in the The documentation for the internal API can be built and opened in the
......
...@@ -28,15 +28,31 @@ import MA.FunctorDescription ...@@ -28,15 +28,31 @@ import MA.FunctorDescription
data Options = Options data Options = Options
{ optVerbose :: Bool { optCommand :: SubCommand }
, optCommand :: Maybe SubCommand
}
data SubCommand = HelpCommand (HelpCommand) data SubCommand
= HelpCommand HelpCommand
| RefineCommand RefineOptions
subcommand :: Parser SubCommand subcommand :: Parser SubCommand
subcommand = hsubparser $ subcommand =
command "help" (info (HelpCommand <$> helpCommand) (progDesc "get help")) hsubparser
(command "help" (info (HelpCommand <$> helpCommand) (progDesc "get help"))) <|>
hsubparser
(command
"refine"
(info
(RefineCommand <$> refineOptions)
(progDesc
"Refine the initial partition of a given coalgebra and output the result as a list of blocks of states.")))
data RefineOptions = RefineOptions
{ refineStats :: Bool
}
refineOptions :: Parser RefineOptions
refineOptions = RefineOptions
<$> switch ( long "stats" <> help "Print runtime statistics (such as timing information) to stderr")
data HelpCommand = HelpListFunctors data HelpCommand = HelpListFunctors
...@@ -44,12 +60,7 @@ helpCommand :: Parser HelpCommand ...@@ -44,12 +60,7 @@ helpCommand :: Parser HelpCommand
helpCommand = subparser $ command "list_functors" (info (pure HelpListFunctors) (progDesc "list available functors")) helpCommand = subparser $ command "list_functors" (info (pure HelpListFunctors) (progDesc "list available functors"))
options :: Parser Options options :: Parser Options
options = Options options = Options <$> subcommand
<$> switch ( long "verbose"
<> short 'v'
<> help "Print runtime stats"
)
<*> optional subcommand
main :: IO () main :: IO ()
main = do main = do
...@@ -58,16 +69,16 @@ main = do ...@@ -58,16 +69,16 @@ main = do
info (options <**> helper) fullDesc info (options <**> helper) fullDesc
case optCommand params of case optCommand params of
Just (HelpCommand h) -> printHelp h (HelpCommand h) -> printHelp h
Nothing -> do (RefineCommand r) -> do
(f, (symbolTable, encoding)) <- withTime (optVerbose params) "parse" $ do (f, (symbolTable, encoding)) <- withTime (refineStats r) "parse" $ do
readCoalgebraFromStdin >>= \case readCoalgebraFromStdin >>= \case
Left err -> hPutStrLn stderr err >> exitFailure Left err -> hPutStrLn stderr err >> exitFailure
Right res -> evaluate $ res Right res -> evaluate $ res
partition <- withTime (optVerbose params) "refine" partition <- withTime (refineStats r) "refine"
(stToIO (refine f encoding)) (stToIO (refine f encoding))
withTime (optVerbose params) "print" withTime (refineStats r) "print"
(printPartition encoding symbolTable partition) (printPartition encoding symbolTable partition)
printHelp :: HelpCommand -> IO () printHelp :: HelpCommand -> IO ()
......
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