From bf58c9afbd063413ec4496602e45076e3981fea9 Mon Sep 17 00:00:00 2001 From: James Eversole Date: Wed, 1 Jan 2025 08:34:17 -0600 Subject: [PATCH] Normalize CLI options and help display --- README.md | 10 +++++----- src/Main.hs | 30 ++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 0aa47d0..6ad3444 100644 --- a/README.md +++ b/README.md @@ -74,17 +74,17 @@ tricu eval [OPTIONS] Evaluate a file and return the result of the expression in the final line -f --file=FILE Optional input file path for evaluation. - Defaults to stdin. + Defaults to stdin. -o --output=OUTPUT Optional output file path for resulting output. - Defaults to stdout. + Defaults to stdout. -t --form=FORM Optional output form: (fsl|tree|ast|ternary|ascii). - Defaults to fsl. + Defaults to fsl. tricu decode [OPTIONS] Decode a Tree Calculus value into a string representation - -f --input=ITEM Optional file path to attempt decoding. - Defaults to stdin. + -f --file=FILE Optional input file path to attempt decoding. + Defaults to stdin. ``` ## Acknowledgements diff --git a/src/Main.hs b/src/Main.hs index 91c7bd9..336c873 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -14,8 +14,10 @@ import qualified Data.Map as Map data TricuArgs = Repl - | Evaluate { file :: Maybe FilePath, output :: Maybe FilePath, form :: EvaluatedForm } - | Decode { input :: Maybe FilePath } + | Evaluate { file :: Maybe FilePath + , output :: Maybe FilePath + , form :: EvaluatedForm } + | Decode { file :: Maybe FilePath } deriving (Show, Data, Typeable) replMode :: TricuArgs @@ -27,11 +29,16 @@ replMode = Repl evaluateMode :: TricuArgs evaluateMode = Evaluate { file = def &= typ "FILE" - &= help "Optional input file path for evaluation.\nDefaults to stdin." &= name "f" + &= help "Optional input file path for evaluation.\n \ + \ Defaults to stdin." + &= name "f" , output = def &= typ "OUTPUT" - &= help "Optional output file path for resulting output.\nDefaults to stdout." &= name "o" + &= help "Optional output file path for resulting output.\n \ + \ Defaults to stdout." + &= name "o" , form = FSL &= typ "FORM" - &= help "Optional output form: (fsl|tree|ast|ternary|ascii).\nDefaults to fsl." + &= help "Optional output form: (fsl|tree|ast|ternary|ascii).\n \ + \ Defaults to fsl." &= name "t" } &= help "Evaluate a file and return the result of the expression in the final line" @@ -40,8 +47,11 @@ evaluateMode = Evaluate decodeMode :: TricuArgs decodeMode = Decode - { input = def &= typ "FILE" - &= help "Optional file path to attempt decoding.\nDefaults to stdin." &= name "f" + { file = def + &= help "Optional input file path to attempt decoding.\n \ + \ Defaults to stdin." + &= name "f" + &= typ "FILE" } &= help "Decode a Tree Calculus value into a string representation" &= explicit @@ -71,9 +81,9 @@ main = do writeFile outputPath fRes putStrLn $ "Output to: " ++ outputPath Nothing -> putStr fRes - Decode { input = maybeInputPath } -> do - value <- case maybeInputPath of - Just inputPath -> readFile inputPath + Decode { file = maybeFilePath } -> do + value <- case maybeFilePath of + Just filePath -> readFile filePath Nothing -> getContents putStrLn $ decodeResult $ result $ evalTricu library $ parseTricu value