From 998d9a085e9323c561d62b03ff791a20079f8d12 Mon Sep 17 00:00:00 2001 From: Sergey Alirzaev Date: Mon, 21 Dec 2009 06:24:01 +0300 Subject: [PATCH] some beautiful error messages --- laziness.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/laziness.hs b/laziness.hs index 0a6200c..683531c 100644 --- a/laziness.hs +++ b/laziness.hs @@ -2,10 +2,6 @@ - laziness: a tool to memoize your Earth-seizure plans - by Sergey 'L29Ah' Alirzaev, - - - Synopsis: - - laziness dig -- make laziness print todo graph starting at - - 'id' up to 'depth' jumps into - - - File format: - \t\t\t\t - [\t[\t...]]\n\t... @@ -16,6 +12,8 @@ import Data.List.Split import Data.Maybe import Data.DateTime +import Control.Monad + import System data Todo = Todo { @@ -59,13 +57,19 @@ _dig :: M.Map String Todo -> String -> Int -> Int -> [(Int, Todo)] _dig _ _ _ 0 = [] _dig db id curdepth maxdepth = (curdepth, node) : (concatMap (\x -> _dig db x (curdepth + 1) (maxdepth - 1)) $ deps node) - where node = fromJust $ M.lookup id db + where node = fromMaybe (error $ "No node named \"" ++ id ++ "\" in the database!") $ M.lookup id db +-- TODO: use getOpt main = do - (action:args) <- getArgs + args <- getArgs + when (length args == 0) $ error usage + let (action:cmdargs) = args f <- readFile ".todo" let db = M.fromList $ catMaybes $ map parseLine $ lines f putStr $ case action of - "dig" -> dig db (args!!0) (read $ args!!1) - otherwise -> "Usage! ;-)\n" + "dig" -> dig db (cmdargs!!0) (read $ cmdargs!!1) + otherwise -> error usage + +usage = "Usage:\n" ++ + "laziness dig -- make laziness print todo graph starting at 'id' up to 'depth' jumps into\n" -- 2.11.4.GIT