@@ -15,26 +15,27 @@ module internal ParseArgs = begin
1515 | " --" :: rest -> rest
1616 | _ :: tail -> get_ script_ args tail
1717
18- let parseTopLevel arg optionsSoFar =
19- match arg with
18+ let parseTopLevel ( arg : string ) optionsSoFar =
19+ match arg.ToLowerInvariant () with
2020
2121 // TODO support sequential/parallel runs e.g. "clean release-build;debug-build"
2222
2323 | " -t" | " /t" ->
2424 ( optionsSoFar, Number ( " thread count" , fun o v -> { o with XakeOptionsType.Threads = v}))
25- | " -R " | " /R " ->
25+ | " -r " | " /r " ->
2626 ( optionsSoFar, String ( " root folder" , fun o v -> { o with XakeOptionsType.ProjectRoot = v}))
27- | " -FL " | " /FL " ->
27+ | " -fl " | " /fl " ->
2828 ( optionsSoFar, String ( " file log filename" , fun o v -> { o with XakeOptionsType.FileLog = v}))
29- | " -D " | " /D " ->
29+ | " -d " | " /d " ->
3030 ( optionsSoFar, KeyValue ( " variable" , fun o k v -> { o with Vars = o.Vars @ [( k, v)] }))
31- | " -LL " | " /LL " ->
31+ | " -ll " | " /ll " ->
3232 ( optionsSoFar, String ( " console verbosity" , fun o s -> { o with ConLogLevel = s |> parseVerbosity }))
33- | " -FLL " | " /FLL " ->
33+ | " -fll " | " /fll " ->
3434 ( optionsSoFar, String ( " filelog verbosity" , fun o s -> { o with FileLogLevel = s |> parseVerbosity }))
3535
3636 // handle unrecognized option
37- | x when x.StartsWith( " -" ) ->
37+ | x when x.StartsWith( " -" ) || x.StartsWith( " /" ) ->
38+ // TODO write errors to log?
3839 printfn " Option '%s ' is unrecognized" x
3940 ( optionsSoFar, TopLevel)
4041 | x ->
@@ -64,19 +65,29 @@ module internal ParseArgs = begin
6465
6566 ( fn optionsSoFar k v, TopLevel)
6667
67- let foldFunction state element =
68- match state with
69- | ( optionsSoFar, TopLevel) ->
70- parseTopLevel element optionsSoFar
71-
72- | ( optionsSoFar, Number ( name, fn)) ->
73- readNumber name element optionsSoFar fn
74-
75- | ( optionsSoFar, String ( name, fn)) ->
76- readString name element optionsSoFar fn
77-
78- | ( optionsSoFar, KeyValue ( name, fn)) ->
79- readKeyValue name element optionsSoFar fn
68+ let foldFunction state element =
69+ try
70+ match state with
71+ | ( optionsSoFar, TopLevel) ->
72+ parseTopLevel element optionsSoFar
73+
74+ | ( optionsSoFar, Number ( name, fn)) ->
75+ readNumber name element optionsSoFar fn
76+
77+ | ( optionsSoFar, String ( name, fn)) ->
78+ readString name element optionsSoFar fn
79+
80+ | ( optionsSoFar, KeyValue ( name, fn)) ->
81+ readKeyValue name element optionsSoFar fn
82+ with e ->
83+ let argName =
84+ match state with
85+ | (_, Number ( name, _)) | (_, KeyValue ( name, _)) | (_, String ( name, _)) ->
86+ name
87+ | _ ->
88+ " switch"
89+ printfn " Failed to parse '%s ' due to %s " argName e.Message
90+ ( fst state, TopLevel)
8091
8192end
8293
@@ -85,28 +96,23 @@ module Main =
8596
8697 open ParseArgs
8798
88- /// <summary >
89- /// creates xake build script
90- /// </summary >
91- /// <param name =" options " ></param >
92- let xake options =
93-
94- new RulesBuilder( options)
95-
9699 /// <summary >
97100 /// Creates a script with script parameters passed as list of strings.
98101 /// </summary >
99102 /// <param name =" args " ></param >
100103 /// <param name =" initialOptions " ></param >
101- let xakeArgsStr args initialOptions =
102- let options = args |> List.fold foldFunction ( initialOptions, TopLevel) |> fst
104+ let xakeArgs args initialOptions =
105+ let options =
106+ if initialOptions.IgnoreCommandLine then initialOptions
107+ else args |> List.fold foldFunction ( initialOptions, TopLevel) |> fst
103108 new RulesBuilder ( options)
104109
105110 /// <summary >
106111 /// Create xake build script using command-line arguments to define script options
107112 /// </summary >
108- /// <param name =" args " ></param >
109- /// <param name =" options " ></param >
110- let xakeArgs =
113+ /// <param name =" options " >Initial options set. Could be overridden by a command line arguments.
114+ /// Define option IgnoreCommandLine=true to ignore command line arguments
115+ /// </param >
116+ let xake options =
111117 let args = get_ args() |> get_ script_ args in
112- xakeArgsStr args
118+ xakeArgs args options
0 commit comments