Skip to content

Commit dc39a6d

Browse files
committed
tweak
1 parent 8db06a1 commit dc39a6d

File tree

4 files changed

+42
-60
lines changed

4 files changed

+42
-60
lines changed

jscomp/bsb_helper/bsb_helper_arg.ml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
type key = string
33
type doc = string
4-
type usage_msg = string
54
type anon_fun = rev_args:string list -> unit
65

76
type spec =
@@ -32,27 +31,26 @@ let rec assoc3 (x : string) (l : t) =
3231

3332
let (+>) = Ext_buffer.add_string
3433

35-
let usage_b (buf : Ext_buffer.t) speclist errmsg =
36-
let print_spec buf (key, _spec, doc) =
37-
if doc <> "" then begin
38-
Ext_buffer.add_string buf " ";
39-
Ext_buffer.add_string_char buf key ' ';
40-
Ext_buffer.add_string_char buf doc '\n'
41-
end
42-
in
43-
44-
Ext_buffer.add_string_char buf errmsg '\n';
45-
Ext_list.iter speclist (print_spec buf)
34+
let usage_b (buf : Ext_buffer.t) progname speclist =
35+
buf +> progname;
36+
buf +> " options:\n";
37+
Ext_list.iter speclist (fun (key,_,doc) ->
38+
buf +> " ";
39+
buf +> key ;
40+
buf +> " ";
41+
buf +> doc;
42+
buf +> "\n"
43+
)
4644
;;
4745

4846

4947

50-
let stop_raise ~progname ~(error : error) speclist errmsg =
48+
let stop_raise ~progname ~(error : error) speclist =
5149
let b = Ext_buffer.create 200 in
5250
begin match error with
5351
| Unknown ("-help" | "--help" | "-h") ->
54-
usage_b b speclist errmsg;
55-
output_string stdout (Ext_buffer.contents b);
52+
usage_b b progname speclist ;
53+
Ext_buffer.output_buffer stdout b;
5654
exit 0
5755
| Unknown s ->
5856
b +> progname ;
@@ -65,11 +63,11 @@ let stop_raise ~progname ~(error : error) speclist errmsg =
6563
b +> s;
6664
b +> "' needs an argument.\n"
6765
end;
68-
usage_b b speclist errmsg;
66+
usage_b b progname speclist ;
6967
raise (Bad (Ext_buffer.contents b))
7068

7169

72-
let parse_exn ~progname ~argv ~start (speclist : t) anonfun errmsg =
70+
let parse_exn ~progname ~argv ~start (speclist : t) anonfun =
7371
let l = Array.length argv in
7472
let current = ref start in
7573
let rev_list = ref [] in
@@ -85,15 +83,15 @@ let parse_exn ~progname ~argv ~start (speclist : t) anonfun errmsg =
8583
if !current < l then begin
8684
f argv.(!current);
8785
incr current;
88-
end else stop_raise ~progname ~error:(Missing s) speclist errmsg
86+
end else stop_raise ~progname ~error:(Missing s) speclist
8987
| Set_string r ->
9088
if !current < l then begin
9189
r := argv.(!current);
9290
incr current;
93-
end else stop_raise ~progname ~error:(Missing s) speclist errmsg
91+
end else stop_raise ~progname ~error:(Missing s) speclist
9492
end;
9593
end;
96-
| None -> stop_raise ~progname ~error:(Unknown s) speclist errmsg
94+
| None -> stop_raise ~progname ~error:(Unknown s) speclist
9795
end else begin
9896
rev_list := s :: !rev_list;
9997
end;

jscomp/bsb_helper/bsb_helper_arg.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ type spec =
88

99
type key = string
1010
type doc = string
11-
type usage_msg = string
11+
1212
type anon_fun = rev_args:string list -> unit
1313

1414
val parse_exn :
1515
progname:string ->
1616
argv:string array ->
1717
start:int ->
1818
(key * spec * doc) list ->
19-
anon_fun -> usage_msg -> unit
19+
anon_fun -> unit
2020

2121

2222

jscomp/main/bsb_helper_main.ml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,8 @@
2424
let compilation_kind = ref Bsb_helper_depfile_gen.Js
2525

2626
let hash : string ref = ref ""
27-
28-
29-
(* let output_prefix = ref None *)
3027
let dev_group = ref false
3128
let namespace = ref None
32-
33-
34-
35-
let usage = "Usage: bsb_helper.exe [options] \nOptions are:"
3629

3730
let () =
3831
Bsb_helper_arg.parse_exn
@@ -62,6 +55,6 @@ let () =
6255
!namespace x y
6356
| _ ->
6457
()
65-
) usage;
58+
) ;
6659
(* arrange with mlast comes first *)
6760

lib/4.06.1/bsb_helper.ml

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,15 +1618,15 @@ type spec =
16181618

16191619
type key = string
16201620
type doc = string
1621-
type usage_msg = string
1621+
16221622
type anon_fun = rev_args:string list -> unit
16231623

16241624
val parse_exn :
16251625
progname:string ->
16261626
argv:string array ->
16271627
start:int ->
16281628
(key * spec * doc) list ->
1629-
anon_fun -> usage_msg -> unit
1629+
anon_fun -> unit
16301630

16311631

16321632

@@ -1636,7 +1636,6 @@ end = struct
16361636

16371637
type key = string
16381638
type doc = string
1639-
type usage_msg = string
16401639
type anon_fun = rev_args:string list -> unit
16411640

16421641
type spec =
@@ -1667,27 +1666,26 @@ let rec assoc3 (x : string) (l : t) =
16671666

16681667
let (+>) = Ext_buffer.add_string
16691668

1670-
let usage_b (buf : Ext_buffer.t) speclist errmsg =
1671-
let print_spec buf (key, _spec, doc) =
1672-
if doc <> "" then begin
1673-
Ext_buffer.add_string buf " ";
1674-
Ext_buffer.add_string_char buf key ' ';
1675-
Ext_buffer.add_string_char buf doc '\n'
1676-
end
1677-
in
1678-
1679-
Ext_buffer.add_string_char buf errmsg '\n';
1680-
Ext_list.iter speclist (print_spec buf)
1669+
let usage_b (buf : Ext_buffer.t) progname speclist =
1670+
buf +> progname;
1671+
buf +> " options:\n";
1672+
Ext_list.iter speclist (fun (key,_,doc) ->
1673+
buf +> " ";
1674+
buf +> key ;
1675+
buf +> " ";
1676+
buf +> doc;
1677+
buf +> "\n"
1678+
)
16811679
;;
16821680

16831681

16841682

1685-
let stop_raise ~progname ~(error : error) speclist errmsg =
1683+
let stop_raise ~progname ~(error : error) speclist =
16861684
let b = Ext_buffer.create 200 in
16871685
begin match error with
16881686
| Unknown ("-help" | "--help" | "-h") ->
1689-
usage_b b speclist errmsg;
1690-
output_string stdout (Ext_buffer.contents b);
1687+
usage_b b progname speclist ;
1688+
Ext_buffer.output_buffer stdout b;
16911689
exit 0
16921690
| Unknown s ->
16931691
b +> progname ;
@@ -1700,11 +1698,11 @@ let stop_raise ~progname ~(error : error) speclist errmsg =
17001698
b +> s;
17011699
b +> "' needs an argument.\n"
17021700
end;
1703-
usage_b b speclist errmsg;
1701+
usage_b b progname speclist ;
17041702
raise (Bad (Ext_buffer.contents b))
17051703

17061704

1707-
let parse_exn ~progname ~argv ~start (speclist : t) anonfun errmsg =
1705+
let parse_exn ~progname ~argv ~start (speclist : t) anonfun =
17081706
let l = Array.length argv in
17091707
let current = ref start in
17101708
let rev_list = ref [] in
@@ -1720,15 +1718,15 @@ let parse_exn ~progname ~argv ~start (speclist : t) anonfun errmsg =
17201718
if !current < l then begin
17211719
f argv.(!current);
17221720
incr current;
1723-
end else stop_raise ~progname ~error:(Missing s) speclist errmsg
1721+
end else stop_raise ~progname ~error:(Missing s) speclist
17241722
| Set_string r ->
17251723
if !current < l then begin
17261724
r := argv.(!current);
17271725
incr current;
1728-
end else stop_raise ~progname ~error:(Missing s) speclist errmsg
1726+
end else stop_raise ~progname ~error:(Missing s) speclist
17291727
end;
17301728
end;
1731-
| None -> stop_raise ~progname ~error:(Unknown s) speclist errmsg
1729+
| None -> stop_raise ~progname ~error:(Unknown s) speclist
17321730
end else begin
17331731
rev_list := s :: !rev_list;
17341732
end;
@@ -4082,15 +4080,8 @@ end = struct
40824080
let compilation_kind = ref Bsb_helper_depfile_gen.Js
40834081

40844082
let hash : string ref = ref ""
4085-
4086-
4087-
(* let output_prefix = ref None *)
40884083
let dev_group = ref false
40894084
let namespace = ref None
4090-
4091-
4092-
4093-
let usage = "Usage: bsb_helper.exe [options] \nOptions are:"
40944085

40954086
let () =
40964087
Bsb_helper_arg.parse_exn
@@ -4120,7 +4111,7 @@ let () =
41204111
!namespace x y
41214112
| _ ->
41224113
()
4123-
) usage;
4114+
) ;
41244115
(* arrange with mlast comes first *)
41254116

41264117
end

0 commit comments

Comments
 (0)