Normalize CLI options and help display

This commit is contained in:
James Eversole 2025-01-01 08:34:17 -06:00
parent 7d38d99dcd
commit bf58c9afbd
2 changed files with 25 additions and 15 deletions

View File

@ -83,7 +83,7 @@ tricu eval [OPTIONS]
tricu decode [OPTIONS]
Decode a Tree Calculus value into a string representation
-f --input=ITEM Optional file path to attempt decoding.
-f --file=FILE Optional input file path to attempt decoding.
Defaults to stdin.
```

View File

@ -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