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