Skip to content

Commit 41a2142

Browse files
committed
Bug fixed
1 parent 287df62 commit 41a2142

File tree

1 file changed

+39
-60
lines changed

1 file changed

+39
-60
lines changed

YukimiScript.CommandLineTool/Program.fs

Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -42,72 +42,51 @@ type Option =
4242
exception private OptionErrorException
4343

4444

45-
let private optionParser =
46-
let arg =
47-
parser {
48-
do! Basics.whitespace1
49-
return! Constants.stringParser
50-
}
51-
|> name "command line arg"
45+
let defaultOption scriptDir =
46+
{ ScriptDir = scriptDir
47+
VoiceDocumentOutputDir = None
48+
DiagramOutputFile = None
49+
LibraryDirs = []
50+
TargetLua = None
51+
Charset = None }
52+
5253

53-
let rec options cur =
54-
arg
55-
|> bind (function
56-
| "--target-lua" ->
57-
if cur.TargetLua.IsSome then
58-
raise OptionErrorException
59-
arg
60-
|> bind (fun lua ->
61-
{ cur with TargetLua = Some lua }
62-
|> options)
63-
| "--lib" ->
64-
arg
65-
|> bind (fun lib ->
66-
{ cur with LibraryDirs = lib :: cur.LibraryDirs }
67-
|> options)
68-
| "--dgml" ->
69-
if cur.DiagramOutputFile.IsSome then
70-
raise OptionErrorException
71-
else
72-
arg
73-
|> bind (fun dgml ->
74-
{ cur with DiagramOutputFile = Some dgml }
75-
|> options)
76-
| "--charset" ->
77-
if cur.Charset.IsSome then
78-
raise OptionErrorException
79-
arg
80-
|> bind (fun charset ->
81-
{ cur with Charset = Some charset }
82-
|> options)
83-
| _ -> raise OptionErrorException)
84-
|> zeroOrOne
85-
|> map (Option.defaultValue cur)
54+
let rec parseOption prev =
55+
function
56+
| [] -> Ok prev
57+
| "--lib" :: lib :: other ->
58+
parseOption
59+
{ prev with LibraryDirs = lib :: prev.LibraryDirs}
60+
other
61+
62+
| "--dgml" :: dgml :: other ->
63+
if prev.DiagramOutputFile.IsSome then
64+
failwith "--dgml is already given."
65+
parseOption { prev with DiagramOutputFile = Some dgml } other
66+
67+
| "--target-lua" :: lua :: other ->
68+
if prev.TargetLua.IsSome then
69+
failwith "--target-lua is already given."
70+
parseOption { prev with TargetLua = Some lua } other
71+
72+
| "--charset" :: charset :: other ->
73+
if prev.Charset.IsSome then
74+
failwith "--charset is already given."
75+
parseOption { prev with Charset = Some charset } other
76+
77+
| _ -> Error ()
8678

87-
parser {
88-
let! scriptDir = arg
89-
return! options
90-
{ ScriptDir = scriptDir
91-
VoiceDocumentOutputDir = None
92-
DiagramOutputFile = None
93-
LibraryDirs = []
94-
TargetLua = None
95-
Charset = None }
96-
}
97-
9879

9980
[<EntryPoint>]
10081
let main argv =
10182
argv
102-
|> Array.map (fun x ->
103-
match x.Trim() with
104-
| x when x.StartsWith "\"" && x.EndsWith "\"" -> x
105-
| x when x.StartsWith "\"" -> x + "\""
106-
| x when x.EndsWith "\"" -> "\"" + x
107-
| x -> "\"" + x + "\"")
108-
|> Array.fold (fun a b -> a + " " + b) ""
109-
|> fun x -> " " + x.Trim ()
110-
|> fun argv -> run argv optionParser
83+
|> Array.toList
84+
|> function
85+
| scriptDir :: other ->
86+
parseOption
87+
(defaultOption scriptDir)
88+
other
89+
| _ -> Error ()
11190
|> function
11291
| Error _ ->
11392
help ()

0 commit comments

Comments
 (0)