From ac5a7467628291e490a6eef302164945e75e7551 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Wed, 17 Jan 2018 17:35:20 +0000 Subject: [PATCH] Add option to list available L-systems --- README.org | 3 ++- app/Main.hs | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index fdc9e75..e4f0acc 100644 --- a/README.org +++ b/README.org @@ -51,12 +51,13 @@ command-line arguments, see the output of ~--help~: #+BEGIN_SRC 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 Available options: LSYSTEM L-system to generate (default: penroseP3) -n,--iterations N Number of iterations (default: 5) + -l,--list-lsystems List all available L-systems -h,--help Show this help text #+END_SRC diff --git a/app/Main.hs b/app/Main.hs index 9c45afe..240f60a 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -16,7 +16,7 @@ data Options = Options selectLSystem :: [LSystem a] -> String -> Either String (LSystem a) selectLSystem ls s = case find (\x -> name x == s) ls of 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 = argument (eitherReader (selectLSystem lsystems)) @@ -36,11 +36,18 @@ iterations = option auto <> value 5 <> 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 = Options <$> lsystem <*> iterations opts :: ParserInfo Options -opts = info (options <**> helper) +opts = info (options <**> listLSystems <**> helper) ( fullDesc <> progDesc "Generate and draw an L-system" <> header "lsystems -- Generate L-systems")