Add option to list available L-systems
This commit is contained in:
parent
ebe12ac42b
commit
ac5a746762
2 changed files with 11 additions and 3 deletions
|
@ -51,12 +51,13 @@ command-line arguments, see the output of ~--help~:
|
||||||
#+BEGIN_SRC
|
#+BEGIN_SRC
|
||||||
lsystems -- Generate L-systems
|
lsystems -- Generate L-systems
|
||||||
|
|
||||||
Usage: lsystems-exe [LSYSTEM] [-n|--iterations N]
|
Usage: lsystems-exe [LSYSTEM] [-n|--iterations N] [-l|--list-lsystems]
|
||||||
Generate and draw an L-system
|
Generate and draw an L-system
|
||||||
|
|
||||||
Available options:
|
Available options:
|
||||||
LSYSTEM L-system to generate (default: penroseP3)
|
LSYSTEM L-system to generate (default: penroseP3)
|
||||||
-n,--iterations N Number of iterations (default: 5)
|
-n,--iterations N Number of iterations (default: 5)
|
||||||
|
-l,--list-lsystems List all available L-systems
|
||||||
-h,--help Show this help text
|
-h,--help Show this help text
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
|
11
app/Main.hs
11
app/Main.hs
|
@ -16,7 +16,7 @@ data Options = Options
|
||||||
selectLSystem :: [LSystem a] -> String -> Either String (LSystem a)
|
selectLSystem :: [LSystem a] -> String -> Either String (LSystem a)
|
||||||
selectLSystem ls s = case find (\x -> name x == s) ls of
|
selectLSystem ls s = case find (\x -> name x == s) ls of
|
||||||
Just x -> Right x
|
Just x -> Right x
|
||||||
Nothing -> Left $ "Cannot find L-system \"" ++ s ++ "\""
|
Nothing -> Left $ "Cannot find L-system \"" ++ s ++ "\". Use -l to find all available L-systems."
|
||||||
|
|
||||||
lsystem :: Parser (LSystem Char)
|
lsystem :: Parser (LSystem Char)
|
||||||
lsystem = argument (eitherReader (selectLSystem lsystems))
|
lsystem = argument (eitherReader (selectLSystem lsystems))
|
||||||
|
@ -36,11 +36,18 @@ iterations = option auto
|
||||||
<> value 5
|
<> value 5
|
||||||
<> metavar "N")
|
<> metavar "N")
|
||||||
|
|
||||||
|
listLSystems :: Parser (a -> a)
|
||||||
|
listLSystems = infoOption (printList lsystems)
|
||||||
|
(long "list-lsystems"
|
||||||
|
<> short 'l'
|
||||||
|
<> help "List all available L-systems")
|
||||||
|
where printList xs = "Available L-systems:\n" ++ unlines (map name xs)
|
||||||
|
|
||||||
options :: Parser Options
|
options :: Parser Options
|
||||||
options = Options <$> lsystem <*> iterations
|
options = Options <$> lsystem <*> iterations
|
||||||
|
|
||||||
opts :: ParserInfo Options
|
opts :: ParserInfo Options
|
||||||
opts = info (options <**> helper)
|
opts = info (options <**> listLSystems <**> helper)
|
||||||
( fullDesc
|
( fullDesc
|
||||||
<> progDesc "Generate and draw an L-system"
|
<> progDesc "Generate and draw an L-system"
|
||||||
<> header "lsystems -- Generate L-systems")
|
<> header "lsystems -- Generate L-systems")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue