lib: outputFileFromOpts now returns a maybe; cleanups
This commit is contained in:
		
							parent
							
								
									4b5ad69eb1
								
							
						
					
					
						commit
						1afb84c95d
					
				| @ -555,17 +555,19 @@ expandPathPreservingPrefix d prefixedf = do | |||||||
|     Just p  -> p ++ ":" ++ f' |     Just p  -> p ++ ":" ++ f' | ||||||
|     Nothing -> f' |     Nothing -> f' | ||||||
| 
 | 
 | ||||||
| -- | Get the expanded, absolute output file path from options, | -- | Get the expanded, absolute output file path specified by an | ||||||
| -- or the default (-, meaning stdout). | -- -o/--output-file options, or nothing, meaning stdout. | ||||||
| outputFileFromOpts :: CliOpts -> IO FilePath | outputFileFromOpts :: CliOpts -> IO (Maybe FilePath) | ||||||
| outputFileFromOpts opts = do | outputFileFromOpts opts = do | ||||||
|   d <- getCurrentDirectory |   d <- getCurrentDirectory | ||||||
|   case output_file_ opts of |   case output_file_ opts of | ||||||
|     Just p  -> expandPath d p |     Nothing -> return Nothing | ||||||
|     Nothing -> return "-" |     Just f  -> Just <$> expandPath d f | ||||||
| 
 | 
 | ||||||
|  | defaultOutputFormat :: String | ||||||
| defaultOutputFormat = "txt" | defaultOutputFormat = "txt" | ||||||
| 
 | 
 | ||||||
|  | outputFormats :: [String] | ||||||
| outputFormats = | outputFormats = | ||||||
|   [defaultOutputFormat] ++ |   [defaultOutputFormat] ++ | ||||||
|   ["csv" |   ["csv" | ||||||
|  | |||||||
| @ -161,7 +161,7 @@ journalAddForecast CliOpts{inputopts_=iopts, reportspec_=rspec} j = | |||||||
| writeOutput :: CliOpts -> String -> IO () | writeOutput :: CliOpts -> String -> IO () | ||||||
| writeOutput opts s = do | writeOutput opts s = do | ||||||
|   f <- outputFileFromOpts opts |   f <- outputFileFromOpts opts | ||||||
|   (if f == "-" then putStr else writeFile f) s |   (maybe putStr writeFile f) s | ||||||
| 
 | 
 | ||||||
| -- | Write some output to stdout or to a file selected by --output-file. | -- | Write some output to stdout or to a file selected by --output-file. | ||||||
| -- If the file exists it will be overwritten. This function operates on Lazy | -- If the file exists it will be overwritten. This function operates on Lazy | ||||||
| @ -169,7 +169,7 @@ writeOutput opts s = do | |||||||
| writeOutputLazyText :: CliOpts -> TL.Text -> IO () | writeOutputLazyText :: CliOpts -> TL.Text -> IO () | ||||||
| writeOutputLazyText opts s = do | writeOutputLazyText opts s = do | ||||||
|   f <- outputFileFromOpts opts |   f <- outputFileFromOpts opts | ||||||
|   (if f == "-" then TL.putStr else TL.writeFile f) s |   (maybe TL.putStr TL.writeFile f) s | ||||||
| 
 | 
 | ||||||
| -- -- | Get a journal from the given string and options, or throw an error. | -- -- | Get a journal from the given string and options, or throw an error. | ||||||
| -- readJournal :: CliOpts -> String -> IO Journal | -- readJournal :: CliOpts -> String -> IO Journal | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user