@@ -4,8 +4,9 @@ Copyright (c) 2007-2015 Simon Michael <simon@joyful.com>
44Released under GPL version 3 or later.
55-}
66{-# LANGUAGE CPP #-}
7- {-# LANGUAGE OverloadedStrings #-}
87{-# LANGUAGE MultiParamTypeClasses #-}
8+ {-# LANGUAGE MultiWayIf #-}
9+ {-# LANGUAGE OverloadedStrings #-}
910
1011module Hledger.UI.Main where
1112
@@ -30,6 +31,7 @@ import System.Exit
3031import System.Directory
3132import System.FilePath
3233import System.FSNotify
34+ import Text.Printf (printf )
3335import Brick
3436
3537#if MIN_VERSION_brick(0,16,0)
@@ -66,15 +68,14 @@ main = do
6668 { inputopts_ = (inputopts_ copts) { auto_ = True }
6769 , reportopts_ = (reportopts_ copts) { forecast_ = True }
6870 }
69-
70- -- when (debug_ $ cliopts_ opts) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show opts)
71- run $ opts { cliopts_ = copts' }
72- where
73- run opts
74- | " help" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeUsage uimode) >> exitSuccess
75- | " version" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn prognameandversion >> exitSuccess
76- | " binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname)
77- | otherwise = withJournalDo (cliopts_ opts) (runBrickUi opts)
71+ when (debug_ copts' > 0 ) $ printf " %s\n " prognameandversion >> printf " opts: %s\n " (show opts)
72+ if
73+ | " help" `inRawOpts` rawopts_ copts' -> putStr (showModeUsage uimode) >> exitSuccess
74+ | " version" `inRawOpts` rawopts_ copts' -> putStrLn prognameandversion >> exitSuccess
75+ | " binary-filename" `inRawOpts` rawopts_ copts' -> putStrLn (binaryfilename progname)
76+ | otherwise -> do
77+ mapM_ ensureJournalFileExists =<< journalFilePathFromOpts copts'
78+ withJournalDo copts' (runBrickUi $ opts { cliopts_ = copts' })
7879
7980runBrickUi :: UIOpts -> Journal -> IO ()
8081runBrickUi uopts@ UIOpts {cliopts_= copts@ CliOpts {inputopts_= _iopts,reportopts_= ropts}} j = do
0 commit comments