restore some options utilities, fix hledger-balance-csv script

This commit is contained in:
Simon Michael 2014-03-28 16:33:48 -07:00
parent b69e6c6946
commit ce888a62d5
2 changed files with 29 additions and 18 deletions

View File

@ -27,4 +27,4 @@ printBalanceCsv opts = withJournalDo opts $
let (items,_) = balanceReport ropts (queryFromOpts d ropts) j let (items,_) = balanceReport ropts (queryFromOpts d ropts) j
putStrLn $ printCSV $ putStrLn $ printCSV $
["account","balance"] : ["account","balance"] :
[[a, showMixedAmountWithoutPrice b] | (a, _, _, b) <- items] [[a, showMixedAmountWithoutPrice b] | ((a, _, _), b) <- items]

View File

@ -25,7 +25,7 @@ module Hledger.Cli.Options (
-- * CLI options -- * CLI options
CliOpts(..), CliOpts(..),
defcliopts, defcliopts,
-- getCliOpts, getCliOpts,
decodeRawOpts, decodeRawOpts,
rawOptsToCliOpts, rawOptsToCliOpts,
checkCliOpts, checkCliOpts,
@ -56,7 +56,7 @@ where
import qualified Control.Exception as C import qualified Control.Exception as C
-- import Control.Monad (filterM) -- import Control.Monad (filterM)
-- import Control.Monad (when) import Control.Monad (when)
import Data.List import Data.List
import Data.List.Split import Data.List.Split
import Data.Maybe import Data.Maybe
@ -66,7 +66,7 @@ import System.Console.CmdArgs.Explicit
import System.Console.CmdArgs.Text import System.Console.CmdArgs.Text
import System.Directory import System.Directory
import System.Environment import System.Environment
-- import System.Exit import System.Exit (exitSuccess)
import Test.HUnit import Test.HUnit
import Text.ParserCombinators.Parsec as P import Text.ParserCombinators.Parsec as P
@ -278,20 +278,31 @@ checkCliOpts opts@CliOpts{reportopts_=ropts} = do
Right _ -> return () Right _ -> return ()
return opts return opts
-- not used: -- Currently only used by some extras/ scripts:
-- -- | Parse hledger CLI options from the command line using the given -- | Parse hledger CLI options from the command line using the given
-- -- cmdargs mode, and either return them or, if a help flag is present, -- cmdargs mode, and either return them or, if a help flag is present,
-- -- print the mode help and exit the program. -- print the mode help and exit the program.
-- getCliOpts :: Mode RawOpts -> IO CliOpts getCliOpts :: Mode RawOpts -> IO CliOpts
-- getCliOpts mode = do getCliOpts mode = do
-- args <- getArgs args <- getArgs
-- let rawopts = decodeRawOpts $ processValue mode args let rawopts = decodeRawOpts $ processValue mode args
-- opts <- rawOptsToCliOpts rawopts >>= checkCliOpts opts <- rawOptsToCliOpts rawopts >>= checkCliOpts
-- debugArgs args opts debugArgs args opts
-- -- if any (`elem` args) ["--help","-h","-?"] -- if any (`elem` args) ["--help","-h","-?"]
-- when ("help" `inRawOpts` rawopts_ opts) $ when ("help" `inRawOpts` rawopts_ opts) $
-- putStr (showModeHelp mode) >> exitSuccess putStr (showModeHelp mode) >> exitSuccess
-- return opts return opts
where
-- | Print debug info about arguments and options if --debug is present.
debugArgs :: [String] -> CliOpts -> IO ()
debugArgs args opts =
when ("--debug" `elem` args) $ do
progname <- getProgName
putStrLn $ "running: " ++ progname
putStrLn $ "raw args: " ++ show args
putStrLn $ "processed opts:\n" ++ show opts
d <- getCurrentDay
putStrLn $ "search query: " ++ (show $ queryFromOpts d $ reportopts_ opts)
-- CliOpts accessors -- CliOpts accessors