9 data Flag
= Path
String
19 isFlag
:: String -> Bool
20 isFlag f
= f `
elem`
["-f","-p","-t","-j","-i","-d","-a","-k"]
22 add
:: [String] -> IO ()
23 add
[] = error $ "add: no arguments specified ('" ++ progName
++ " add help' for help)"
24 add argv
= if isHelp
$ head argv
25 then do putStrLn usageAdd
27 case parseFlags argv
of
28 Left msg
-> error $ "add: " ++ msg
29 Right flags
-> putStr $ flagsToString flags
31 flagsToString
:: [Flag
] -> String
32 flagsToString xs
= foldl' step
[] xs
33 where step ys x
= show x
++ "\n" ++ ys
35 parseFlags
:: [String] -> Either String [Flag
]
36 parseFlags argv
= parseFlags
' [] argv
37 where parseFlags
' _
(x
:[]) = Left
"too few arguments"
38 parseFlags
' fs
[] = Right fs
43 Right f
-> parseFlags
' (f
:fs
) (dropWhile (not . isFlag
) (tail xs
))
45 getFlag
:: [String] -> Either String Flag
54 "-k" -> Keywords
$ getValues
$ tail x
55 "-a" -> Authors
$ getValues
$ tail x
57 then Left
"too few argument"
60 getValues
:: [String] -> String
61 getValues argv
= intercalate
"|" $ takeWhile (not . isFlag
) argv
64 usageAdd
= "usage: " ++ progName
++ " add <filters>\n\
68 \ -a <author1 [author2] ...>\n\
69 \ -k <keyword1 [keyword2] ...>\n\
73 \ -p <page-from>-<page-to>"