module Todos.Main
(module Todos.Default,
module Todos.Config,
module Todos.Dot,
todos
) where
import Prelude hiding (putStrLn,readFile,getContents,print)
import IO
import Data.Tree
import System.Exit
import System.Cmd (system)
import System.Environment
import Config.Dyre
import Todos.Types
import Todos.Unicode
import Todos.Dates
import Todos.Dot
import Todos.Tree
import Todos.ReadConfig
import Todos.Loader
import Todos.CommandParser
import Todos.Config
import Todos.Default
realTodos ∷ (RuntimeConfig c) ⇒ TodosConfig c → IO ()
realTodos tcfg = do
currDate ← getCurrentDateTime
config ← readConfig
args ← getArgs
let pres = (parseCommandLine tcfg) currDate (nullConfig tcfg) (config ⧺ args)
case pres of
Parsed q files' → do
let bc = toBaseConfig q
files ← glob files'
todos ← loadTodo bc currDate files
let queried = (filterTodos tcfg) currDate q todos
case commandToRun bc of
JustShow → printTodos tcfg (mkPrintConfig currDate q tcfg) queried
ShowAsDot →
putStrLn $ showAsDot (itemColor tcfg) (itemShape tcfg) queried
SystemCommand cmd → do
forT selected (\item → system $ printfItem cmd item)
return ()
where selected | outOnlyFirst bc = [Node (rootLabel $ head queried) []]
| otherwise = queried
ParseError str → error str
CmdLineHelp → do putStrLn usage
exitWith ExitSuccess
todos ∷ (RuntimeConfig c) ⇒ TodosConfig c → IO ()
todos = wrapMain $ defaultParams {
projectName = "todos",
realMain = realTodos,
statusOut = const (return ())
}