commit 57f7389c4dccb18f18d95f3cdfd2861e2829cb68
parent 3ab9b58194486936a29c7b1b1ed94ca9f5a9d402
Author: James Eversole <james@eversole.co>
Date: Wed, 1 Jan 2025 08:34:17 -0600
Normalize CLI options and help display
Diffstat:
2 files changed, 25 insertions(+), 15 deletions(-)
diff --git 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
@@ -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