finish previous commit

This commit is contained in:
Simon Michael 2014-10-21 17:49:41 -07:00
parent 9416d12d8a
commit 9d1ef010ac

View File

@ -31,6 +31,8 @@ module Hledger.Cli.Options (
decodeRawOpts, decodeRawOpts,
rawOptsToCliOpts, rawOptsToCliOpts,
checkCliOpts, checkCliOpts,
outputFormats,
defaultOutputFormat,
-- possibly these should move into argsToCliOpts -- possibly these should move into argsToCliOpts
-- * CLI option accessors -- * CLI option accessors
@ -367,6 +369,13 @@ outputFileFromOpts opts = do
Just p -> expandPath d p Just p -> expandPath d p
Nothing -> return "-" Nothing -> return "-"
defaultOutputFormat = "txt"
outputFormats =
[defaultOutputFormat] ++
["csv"
]
-- | Get the output format from the --output-format option, -- | Get the output format from the --output-format option,
-- otherwise from a recognised file extension in the --output-file option, -- otherwise from a recognised file extension in the --output-file option,
-- otherwise the default (txt). -- otherwise the default (txt).
@ -375,16 +384,18 @@ outputFormatFromOpts opts =
case output_format_ opts of case output_format_ opts of
Just f -> f Just f -> f
Nothing -> Nothing ->
let mext = (snd . splitExtension . snd . splitFileName) <$> output_file_ opts case filePathExtension <$> output_file_ opts of
in case mext of Just ext | ext `elem` outputFormats -> ext
Just ext | ext `elem` formats -> ext _ -> defaultOutputFormat
_ -> defaultformat
defaultformat = "txt" -- -- | Get the file name without its last extension, from a file path.
formats = -- filePathBaseFileName :: FilePath -> String
[defaultformat] ++ -- filePathBaseFileName = fst . splitExtension . snd . splitFileName
["csv"
] -- | Get the last file extension, without the dot, from a file path.
-- May return the null string.
filePathExtension :: FilePath -> String
filePathExtension = dropWhile (=='.') . snd . splitExtension . snd . splitFileName
-- | Get the (tilde-expanded) rules file path from options, if any. -- | Get the (tilde-expanded) rules file path from options, if any.
rulesFilePathFromOpts :: CliOpts -> IO (Maybe FilePath) rulesFilePathFromOpts :: CliOpts -> IO (Maybe FilePath)