From 9374d3f19b9fcba66d05827ba038d5c8a747732b Mon Sep 17 00:00:00 2001 From: Louis-Guillaume Gagnon Date: Thu, 5 Sep 2013 07:50:12 -0400 Subject: [PATCH] View: implement usageView --- src/View.hs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/View.hs b/src/View.hs index 31ef736..e3f43f0 100644 --- a/src/View.hs +++ b/src/View.hs @@ -21,7 +21,37 @@ module View ( view ) where -import Tools.Operation +import Data.Char (isDigit) + +import Tools.Constants +import Tools.Operation (isHelp) view :: [String] -> IO () -view argv = putStrLn $ usage View + +view [] = error errTooFew + +view (x:[]) | isHelp x = putStrLn usageView + | and (map isDigit x) = doView x "" + | otherwise = error $ "view: invalid id: " ++ x + +view (x:xs) = do + if and (map isDigit x) + then case tryGetViewer xs of + Left msg -> error $ "view: " ++ msg + Right v -> doView x v + else error $ "view: invalid id: " ++ x + + +doView :: String -> String -> IO () +doView id viewer = putStrLn "not yet implemented" + +tryGetViewer :: [String] -> Either String String +tryGetViewer xs = Right "" + +errTooFew :: String +errTooFew = "view: too few arguments ('" ++ progName ++ " view help' for help)" + +usageView :: String +usageView = "usage: " ++ progName ++ " view [options]\n\ + \options:\n\ + \ -v " -- 2.11.4.GIT