module TodoTree.Dispatch where

-- import Control.Monad (when)
import System.Console.Docopt.NoTH
import TodoTree.Repl (repl)

dispatchOrExit :: String -> [String] -> IO ()
dispatchOrExit usg args = do
  doc <- parseUsageOrExit usg
  opts <- parseArgsOrExit doc args
  dispatch doc opts

dispatch :: Docopt -> Arguments -> IO ()
dispatch usg args = do
  let getArg' arg = getArgOrExitWith usg args $ argument arg
    -- ifArg  arg act = when (isPresent args $ argument arg) act
  getArg' "file" >>= (\f -> repl [f])
