-
[hdata.git] / src / Main.hs
blob54284641500146945a70f063564e45c97b0f9433
1 {-
2 hdata.hs
4 Copyright 2013 Louis-Guillaume Gagnon <louis.guillaume.gagnon@gmail.com>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 module Main where
22 import System.Environment
24 import Add
25 import Modify
26 import Remove
27 import Search
28 import Tools.Constants
29 import Tools.Operation
30 import View
32 help :: [String] -> IO ()
33 help [] = putStrLn $ usageHelp
34 help (x:_) = case x of
35 "add" -> putStrLn usageAdd
36 "modify" -> putStrLn usageModify
37 "remove" -> putStrLn usageRemove
38 "search" -> putStrLn usageSearch
39 "view" -> putStrLn usageView
40 _ -> error $ "help: invalid argument: " ++ x
42 usageHelp = "usage: " ++ progName ++ " [operation] [id]\n\
43 \operations:\n\
44 \ add <filters> \n\
45 \ help [operation] \n\
46 \ modify [options] <filters> <id>\n\
47 \ remove [options] <id>\n\
48 \ search [options] [filters] [id]\n\
49 \ view [options] <id>\n\
50 \ version"
52 version :: IO ()
53 version = do
54 putStrLn $ progName ++ " v" ++ progVersion
55 putStrLn "© 2013 Louis-Guillaume Gagnon - GPLv3+"
58 main :: IO ()
59 main = do
60 argv <- getArgs
61 if null argv
62 then
63 do
64 error $ "No operation specified ('" ++ progName ++ " help' for help)"
65 else
67 let argv' = tail argv
68 case parseArg (head argv) of
69 Right Add -> add argv'
70 Right Help -> help argv'
71 Right Modify -> modify argv'
72 Right Remove -> remove argv'
73 Right Search -> search argv'
74 Right View -> view argv'
75 Right Version -> version
76 Left msg -> error msg