summaryrefslogtreecommitdiff
path: root/src/GF/Command/Commands.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2007-11-06 11:01:45 +0000
committeraarne <aarne@cs.chalmers.se>2007-11-06 11:01:45 +0000
commit693621ffbe9146f24ba75e073b6ce2e716c56a5e (patch)
tree43f880829a17c7834fcdb179f5c468fa6c53fc05 /src/GF/Command/Commands.hs
parentdb399191d926209d36c8496ba65d53dcaeb7855b (diff)
made command table independent of options
Diffstat (limited to 'src/GF/Command/Commands.hs')
-rw-r--r--src/GF/Command/Commands.hs37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/GF/Command/Commands.hs b/src/GF/Command/Commands.hs
index 1d9da6558..79e28865f 100644
--- a/src/GF/Command/Commands.hs
+++ b/src/GF/Command/Commands.hs
@@ -5,6 +5,7 @@ module GF.Command.Commands (
isOpt,
options,
flags,
+ CommandInfo,
CommandOutput
) where
@@ -22,7 +23,7 @@ import qualified Data.Map as Map
type CommandOutput = ([Tree],String) ---- errors, etc
data CommandInfo = CommandInfo {
- exec :: [Tree] -> IO CommandOutput,
+ exec :: [Option] -> [Tree] -> IO CommandOutput,
synopsis :: String,
explanation :: String,
longname :: String,
@@ -32,7 +33,7 @@ data CommandInfo = CommandInfo {
emptyCommandInfo :: CommandInfo
emptyCommandInfo = CommandInfo {
- exec = \ts -> return (ts,[]), ----
+ exec = \_ ts -> return (ts,[]), ----
synopsis = "synopsis",
explanation = "explanation",
longname = "longname",
@@ -46,7 +47,7 @@ lookCommand = Map.lookup
commandHelpAll :: MultiGrammar -> [Option] -> String
commandHelpAll mgr opts = unlines
[commandHelp (isOpt "full" opts) (co,info)
- | (co,info) <- Map.assocs (allCommands mgr opts)]
+ | (co,info) <- Map.assocs (allCommands mgr)]
commandHelp :: Bool -> (String,CommandInfo) -> String
commandHelp full (co,info) = unlines $ [
@@ -78,45 +79,45 @@ isOpt :: String -> [Option] -> Bool
isOpt o opts = elem o [x | OOpt (Ident x) <- opts]
-allCommands :: MultiGrammar -> [Option] -> Map.Map String CommandInfo
-allCommands mgr opts = Map.fromAscList [
+allCommands :: MultiGrammar -> Map.Map String CommandInfo
+allCommands mgr = Map.fromAscList [
("gr", emptyCommandInfo {
longname = "generate_random",
synopsis = "generates a list of random trees, by default one tree",
- flags = ["number"],
- exec = \_ -> do
- ts <- generateRandom mgr optCat
- return $ fromTrees $ take optNum ts
+ flags = ["cat","number"],
+ exec = \opts _ -> do
+ ts <- generateRandom mgr (optCat opts)
+ return $ fromTrees $ take (optNum opts) ts
}),
("h", emptyCommandInfo {
longname = "help",
synopsis = "get description of a command, or a the full list of commands",
options = ["full"],
- exec = \ts -> return ([], case ts of
+ exec = \opts ts -> return ([], case ts of
[t] -> let co = (showTree t) in
- case lookCommand co (allCommands mgr opts) of
+ case lookCommand co (allCommands mgr) of ---- new map ??!!
Just info -> commandHelp True (co,info)
_ -> "command not found"
_ -> commandHelpAll mgr opts)
}),
("l", emptyCommandInfo {
- exec = return . fromStrings . map lin,
+ exec = \opts -> return . fromStrings . map (lin opts),
flags = ["lang"]
}),
("p", emptyCommandInfo {
- exec = return . fromTrees . concatMap par . toStrings,
+ exec = \opts -> return . fromTrees . concatMap (par opts). toStrings,
flags = ["cat","lang"]
})
]
where
- lin t = unlines [linearize mgr lang t | lang <- optLangs]
- par s = concat [parse mgr lang optCat s | lang <- optLangs]
+ lin opts t = unlines [linearize mgr lang t | lang <- optLangs opts]
+ par opts s = concat [parse mgr lang (optCat opts) s | lang <- optLangs opts]
- optLangs = case valIdOpts "lang" "" opts of
+ optLangs opts = case valIdOpts "lang" "" opts of
"" -> languages mgr
lang -> [lang]
- optCat = valIdOpts "cat" (lookAbsFlag gr (cid "startcat")) opts
- optNum = valIntOpts "number" 1 opts
+ optCat opts = valIdOpts "cat" (lookAbsFlag gr (cid "startcat")) opts
+ optNum opts = valIntOpts "number" 1 opts
gr = gfcc mgr