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/>.
25 import Data
.Char (isDigit)
26 import System
.IO (hFlush,stdout)
28 import Tools
.Constants
29 import Tools
.Filter
(rowToString
)
30 import Tools
.Operation
(isHelp
)
31 import Tools
.SQL
(getEntry
, removeEntry
)
33 remove
:: [String] -> IO ()
34 remove
[] = error $ "remove: too few arguments ('" ++ progName
++
35 " remove help') for help"
36 remove argv |
length argv
> 1 = error $ "remove: too many arguments ('" ++
37 progName
++ " remove help') for help"
38 | isHelp
(argv
!!0) = putStrLn usageRemove
39 |
or (map (not . isDigit) id) = error $ "remove: invalid id: " ++ id
40 |
otherwise = askRemove
id
43 askRemove
:: String -> IO ()
45 entry
<- getEntry
$ read id
47 Left msg
-> error $ "remove: " ++ msg
48 Right row
-> do putStrLn $ rowToString row
49 putStr "Remove this entry? [y/n] "
53 "y" -> removeEntry
$ read id
57 usageRemove
= "usage: " ++ progName
++ " remove <id>"