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'
|
||||
Nothing -> f'
|
||||
|
||||
-- | Get the expanded, absolute output file path from options,
|
||||
-- or the default (-, meaning stdout).
|
||||
outputFileFromOpts :: CliOpts -> IO FilePath
|
||||
-- | Get the expanded, absolute output file path specified by an
|
||||
-- -o/--output-file options, or nothing, meaning stdout.
|
||||
outputFileFromOpts :: CliOpts -> IO (Maybe FilePath)
|
||||
outputFileFromOpts opts = do
|
||||
d <- getCurrentDirectory
|
||||
case output_file_ opts of
|
||||
Just p -> expandPath d p
|
||||
Nothing -> return "-"
|
||||
Nothing -> return Nothing
|
||||
Just f -> Just <$> expandPath d f
|
||||
|
||||
defaultOutputFormat :: String
|
||||
defaultOutputFormat = "txt"
|
||||
|
||||
outputFormats :: [String]
|
||||
outputFormats =
|
||||
[defaultOutputFormat] ++
|
||||
["csv"
|
||||
|
||||
@ -161,7 +161,7 @@ journalAddForecast CliOpts{inputopts_=iopts, reportspec_=rspec} j =
|
||||
writeOutput :: CliOpts -> String -> IO ()
|
||||
writeOutput opts s = do
|
||||
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.
|
||||
-- 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 opts s = do
|
||||
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.
|
||||
-- readJournal :: CliOpts -> String -> IO Journal
|
||||
|
||||
Loading…
Reference in New Issue
Block a user