Normalize CLI options and help display
This commit is contained in:
		
							
								
								
									
										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 | ||||
|  | ||||
|   -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  | ||||
|  | ||||
							
								
								
									
										30
									
								
								src/Main.hs
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								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 | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 James Eversole
					James Eversole