Normalize CLI options and help display
This commit is contained in:
parent
7d38d99dcd
commit
bf58c9afbd
10
README.md
10
README.md
@ -74,17 +74,17 @@ tricu eval [OPTIONS]
|
|||||||
Evaluate a file and return the result of the expression in the final line
|
Evaluate a file and return the result of the expression in the final line
|
||||||
|
|
||||||
-f --file=FILE Optional input file path for evaluation.
|
-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.
|
-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).
|
-t --form=FORM Optional output form: (fsl|tree|ast|ternary|ascii).
|
||||||
Defaults to fsl.
|
Defaults to fsl.
|
||||||
|
|
||||||
tricu decode [OPTIONS]
|
tricu decode [OPTIONS]
|
||||||
Decode a Tree Calculus value into a string representation
|
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.
|
Defaults to stdin.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Acknowledgements
|
## Acknowledgements
|
||||||
|
30
src/Main.hs
30
src/Main.hs
@ -14,8 +14,10 @@ import qualified Data.Map as Map
|
|||||||
|
|
||||||
data TricuArgs
|
data TricuArgs
|
||||||
= Repl
|
= Repl
|
||||||
| Evaluate { file :: Maybe FilePath, output :: Maybe FilePath, form :: EvaluatedForm }
|
| Evaluate { file :: Maybe FilePath
|
||||||
| Decode { input :: Maybe FilePath }
|
, output :: Maybe FilePath
|
||||||
|
, form :: EvaluatedForm }
|
||||||
|
| Decode { file :: Maybe FilePath }
|
||||||
deriving (Show, Data, Typeable)
|
deriving (Show, Data, Typeable)
|
||||||
|
|
||||||
replMode :: TricuArgs
|
replMode :: TricuArgs
|
||||||
@ -27,11 +29,16 @@ replMode = Repl
|
|||||||
evaluateMode :: TricuArgs
|
evaluateMode :: TricuArgs
|
||||||
evaluateMode = Evaluate
|
evaluateMode = Evaluate
|
||||||
{ file = def &= typ "FILE"
|
{ 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"
|
, 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"
|
, 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"
|
&= name "t"
|
||||||
}
|
}
|
||||||
&= help "Evaluate a file and return the result of the expression in the final line"
|
&= help "Evaluate a file and return the result of the expression in the final line"
|
||||||
@ -40,8 +47,11 @@ evaluateMode = Evaluate
|
|||||||
|
|
||||||
decodeMode :: TricuArgs
|
decodeMode :: TricuArgs
|
||||||
decodeMode = Decode
|
decodeMode = Decode
|
||||||
{ input = def &= typ "FILE"
|
{ file = def
|
||||||
&= help "Optional file path to attempt decoding.\nDefaults to stdin." &= name "f"
|
&= 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"
|
&= help "Decode a Tree Calculus value into a string representation"
|
||||||
&= explicit
|
&= explicit
|
||||||
@ -71,9 +81,9 @@ main = do
|
|||||||
writeFile outputPath fRes
|
writeFile outputPath fRes
|
||||||
putStrLn $ "Output to: " ++ outputPath
|
putStrLn $ "Output to: " ++ outputPath
|
||||||
Nothing -> putStr fRes
|
Nothing -> putStr fRes
|
||||||
Decode { input = maybeInputPath } -> do
|
Decode { file = maybeFilePath } -> do
|
||||||
value <- case maybeInputPath of
|
value <- case maybeFilePath of
|
||||||
Just inputPath -> readFile inputPath
|
Just filePath -> readFile filePath
|
||||||
Nothing -> getContents
|
Nothing -> getContents
|
||||||
putStrLn $ decodeResult $ result $ evalTricu library $ parseTricu value
|
putStrLn $ decodeResult $ result $ evalTricu library $ parseTricu value
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user