Commit 0af08346 authored by Jurrien Stutterheim's avatar Jurrien Stutterheim
Browse files

Fix Start function

parent 9c7b1f85
...@@ -35,35 +35,35 @@ Start :: *World -> *World ...@@ -35,35 +35,35 @@ Start :: *World -> *World
Start world Start world
# commandline = getCommandLine # commandline = getCommandLine
# cleanhome = case getEnvironmentVariable "CLEAN_HOME" of # cleanhome = case getEnvironmentVariable "CLEAN_HOME" of
EnvironmentVariableUndefined -> "." (EnvironmentVariable ch) -> ch
(EnvironmentVariable ch) -> ch _ -> "."
cl = intersperse " " (tl [arg \\ arg <-: commandline]) cl = intersperse " " (tl [arg \\ arg <-: commandline])
argsrec = startPBB (concat [fromString c \\ c <- cl]) argsrec = startPBB (concat [fromString c \\ c <- cl])
| isNothing argsrec.filename = showUsage world | isNothing argsrec.filename = showUsage world
# world = case getStringArg "action" of = case getStringArg "action" argsrec.args of
"create" -> createProject world argsrec.filename cleanhome (Just "create") -> createProject world argsrec.filename cleanhome
"show" -> showProject world argsrec.filename cleanhome (Just "show") -> showProject world argsrec.filename cleanhome
"addpath" -> addPath world argsrec.filename cleanhome //(Just "addpath") -> addPath world argsrec.filename cleanhome
"removepath" -> removePath world argsrec cleanhome //(Just "removepath") -> removePath world argsrec cleanhome
_ -> buildProject world argsrec _ -> buildProject world argsrec
showUsage :: !*World -> *World showUsage :: !*World -> *World
showUsage world = show showUsage world = show
[ "BatchBuild" [ "BatchBuild"
, "Usage: BatchBuild [--force] filename [--action=ARG] [--envsdir=ARG]" , "Usage: BatchBuild [--force] filename [--action=ARG] [--envsdir=ARG]"
, "--action : Execute a specific action. Possible actions:" , " --action : Execute a specific action. Possible actions:"
, " build : Build a project (default)." , " build : Build a project (default)."
, " create : Create a basic project file for a module." , " create : Create a basic project file for a module."
, " show : Summarize the contents of a project file." , " show : Summarize the contents of a project file."
, "--envsdir : Specify a directory where environment files can be found (defaults to 'IDEEnvs')" , " --envsdir : Specify a directory where environment files can be found (defaults to 'IDEEnvs')"
] world ] world
buildProject :: *World BBArgs -> *World buildProject :: *World BBArgs -> *World
buildProject world {force_rebuild=force_rebuild, filename=filename, args=args} buildProject world {force_rebuild=force_rebuild, filename=filename, args=args}
# (startup,world) = accFiles GetFullApplicationPath world # (startup,world) = accFiles GetFullApplicationPath world
# envsdir = case getStringArg "envsdir" args of # envsdir = case getStringArg "envsdir" args of
Nothing -> application_path EnvsFileName
(Just p) -> application_path p (Just p) -> application_path p
_ -> application_path EnvsFileName
# (envs,world) = openEnvironments startup envsdir world # (envs,world) = openEnvironments startup envsdir world
# ((proj,ok,err),world) = accFiles (ReadProjectFile (fromJust filename) startup) world # ((proj,ok,err),world) = accFiles (ReadProjectFile (fromJust filename) startup) world
| not ok || err <> "" = wAbort ("BatchBuild failed while opening project: "+++.err+++."\n") world | not ok || err <> "" = wAbort ("BatchBuild failed while opening project: "+++.err+++."\n") world
...@@ -146,8 +146,8 @@ concat xss = foldr (++) [] xss ...@@ -146,8 +146,8 @@ concat xss = foldr (++) [] xss
startPBB :: [.Char] -> BBArgs startPBB :: [.Char] -> BBArgs
startPBB args = case filter (\(xs, _) -> xs == []) (begin pBB args) of startPBB args = case filter (\(xs, _) -> xs == []) (begin pBB args) of
[] -> {force_rebuild = False, filename = Nothing, args = [] }
[(_, as):_] -> as [(_, as):_] -> as
_ -> {force_rebuild = False, filename = Nothing, args = [] }
pBB :: CParser Char BBArgs BBArgs pBB :: CParser Char BBArgs BBArgs
pBB = pForce <&> \f -> pFilename <&> \p -> <*> (sp pArgs) <@ \fs -> {force_rebuild = f, filename = p, args = fs} pBB = pForce <&> \f -> pFilename <&> \p -> <*> (sp pArgs) <@ \fs -> {force_rebuild = f, filename = p, args = fs}
...@@ -167,18 +167,19 @@ pArgs = pStringLongOpt "envsdir" <|> pBoolLongOpt "force" <|> pStringLongOpt "ac ...@@ -167,18 +167,19 @@ pArgs = pStringLongOpt "envsdir" <|> pBoolLongOpt "force" <|> pStringLongOpt "ac
hasFlag :: String [BBArg] -> Bool hasFlag :: String [BBArg] -> Bool
hasFlag _ [] = False hasFlag _ [] = False
hasFlag flag [(BBBool x):xs] = flag === x || hasFlag flag xs hasFlag flag [(BBBool x):xs] = flag === x || hasFlag flag xs
hasFlag flag [_:xs] = hasFlag flag xs
getStringArg :: String [BBArg] -> Maybe String getStringArg :: String [BBArg] -> Maybe String
getStringArg _ [] = Nothing getStringArg _ [] = Nothing
getStringArg arg [(BBString x v):xs] getStringArg arg [BBString x v:xs]
| arg === x = Just v | arg === x = Just v
| otherwise = getStringArg arg xs getStringArg arg [_:xs] = getStringArg arg xs
getIntArg :: String [BBArg] -> Maybe Int getIntArg :: String [BBArg] -> Maybe Int
getIntArg _ [] = Nothing getIntArg _ [] = Nothing
getIntArg arg [(BBInt x v):xs] getIntArg arg [BBInt x v:xs]
| arg === x = Just v | arg === x = Just v
| otherwise = getIntArg arg xs getIntArg arg [_:xs] = getIntArg arg xs
pNotSpace :: CParser Char [Char] a pNotSpace :: CParser Char [Char] a
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment