Skip to content

Commit 8a3bdc9

Browse files
committed
arg alignment
1 parent 8de56f0 commit 8a3bdc9

File tree

3 files changed

+50
-35
lines changed

3 files changed

+50
-35
lines changed

jscomp/bsb_helper/bsb_helper_arg.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ let (+>) = Ext_buffer.add_string
3434
let usage_b (buf : Ext_buffer.t) progname speclist =
3535
buf +> progname;
3636
buf +> " options:\n";
37+
let max_col = ref 0 in
38+
Ext_list.iter speclist (fun (key,_,_) ->
39+
if String.length key > !max_col then
40+
max_col := String.length key
41+
);
3742
Ext_list.iter speclist (fun (key,_,doc) ->
3843
buf +> " ";
3944
buf +> key ;
40-
buf +> " ";
45+
buf +> (String.make (!max_col - String.length key + 1 ) ' ');
4146
buf +> doc;
4247
buf +> "\n"
43-
)
48+
)
4449
;;
4550

4651

jscomp/main/bsb_helper_main.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let compilation_kind = ref Bsb_helper_depfile_gen.Js
2525

2626
let hash : Bsb_helper_arg.string_action =
2727
Set {contents = ""}
28-
28+
2929
let dev_group = ref false
3030
let namespace = ref None
3131

@@ -36,12 +36,12 @@ let () =
3636
~start:1
3737
[
3838
"-g", Bool dev_group ,
39-
" Set the dev group (default to be 0)"
39+
"Set the dev group (default to be 0)"
4040
;
4141
"-bs-ns", String (Call (fun s -> namespace := Some s)),
42-
" Set namespace";
42+
"Set namespace";
4343
"-hash", String hash,
44-
" Set hash(internal)";
44+
"Set hash(internal)";
4545
] (fun ~rev_args ->
4646
match rev_args with
4747
| [x]

lib/4.06.1/bsb_helper.ml

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,10 +1611,13 @@ module Bsb_helper_arg : sig
16111611

16121612

16131613

1614+
type string_action =
1615+
| Call of (string -> unit)
1616+
| Set of {mutable contents : string}
1617+
16141618
type spec =
1615-
| Set of bool ref
1616-
| String of (string -> unit)
1617-
| Set_string of string ref
1619+
| Bool of bool ref
1620+
| String of string_action
16181621

16191622
type key = string
16201623
type doc = string
@@ -1638,10 +1641,14 @@ type key = string
16381641
type doc = string
16391642
type anon_fun = rev_args:string list -> unit
16401643

1644+
type string_action =
1645+
| Call of (string -> unit)
1646+
| Set of {mutable contents : string}
1647+
16411648
type spec =
1642-
| Set of bool ref
1643-
| String of (string -> unit)
1644-
| Set_string of string ref
1649+
| Bool of bool ref
1650+
| String of string_action
1651+
16451652

16461653
exception Bad of string
16471654

@@ -1650,10 +1657,6 @@ type error =
16501657
| Unknown of string
16511658
| Missing of string
16521659

1653-
1654-
1655-
1656-
16571660
type t = (string * spec * string) list
16581661

16591662
let rec assoc3 (x : string) (l : t) =
@@ -1669,13 +1672,18 @@ let (+>) = Ext_buffer.add_string
16691672
let usage_b (buf : Ext_buffer.t) progname speclist =
16701673
buf +> progname;
16711674
buf +> " options:\n";
1675+
let max_col = ref 0 in
1676+
Ext_list.iter speclist (fun (key,_,_) ->
1677+
if String.length key > !max_col then
1678+
max_col := String.length key
1679+
);
16721680
Ext_list.iter speclist (fun (key,_,doc) ->
16731681
buf +> " ";
16741682
buf +> key ;
1675-
buf +> " ";
1683+
buf +> (String.make (!max_col - String.length key + 1 ) ' ');
16761684
buf +> doc;
16771685
buf +> "\n"
1678-
)
1686+
)
16791687
;;
16801688

16811689

@@ -1713,17 +1721,17 @@ let parse_exn ~progname ~argv ~start (speclist : t) anonfun =
17131721
match assoc3 s speclist with
17141722
| Some action -> begin
17151723
begin match action with
1716-
| Set r -> r := true;
1724+
| Bool r -> r := true;
17171725
| String f ->
1718-
if !current < l then begin
1719-
f argv.(!current);
1720-
incr current;
1721-
end else stop_raise ~progname ~error:(Missing s) speclist
1722-
| Set_string r ->
1723-
if !current < l then begin
1724-
r := argv.(!current);
1725-
incr current;
1726-
end else stop_raise ~progname ~error:(Missing s) speclist
1726+
if !current >= l then stop_raise ~progname ~error:(Missing s) speclist
1727+
else begin
1728+
let arg = argv.(!current) in
1729+
incr current;
1730+
match f with
1731+
| Call f ->
1732+
f arg
1733+
| Set u -> u.contents <- arg
1734+
end
17271735
end;
17281736
end;
17291737
| None -> stop_raise ~progname ~error:(Unknown s) speclist
@@ -4079,7 +4087,9 @@ end = struct
40794087
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
40804088
let compilation_kind = ref Bsb_helper_depfile_gen.Js
40814089

4082-
let hash : string ref = ref ""
4090+
let hash : Bsb_helper_arg.string_action =
4091+
Set {contents = ""}
4092+
40834093
let dev_group = ref false
40844094
let namespace = ref None
40854095

@@ -4089,13 +4099,13 @@ let () =
40894099
~argv:Sys.argv
40904100
~start:1
40914101
[
4092-
"-g", Set dev_group ,
4093-
" Set the dev group (default to be 0)"
4102+
"-g", Bool dev_group ,
4103+
"Set the dev group (default to be 0)"
40944104
;
4095-
"-bs-ns", String (fun s -> namespace := Some s),
4096-
" Set namespace";
4097-
"-hash", Set_string hash,
4098-
" Set hash(internal)";
4105+
"-bs-ns", String (Call (fun s -> namespace := Some s)),
4106+
"Set namespace";
4107+
"-hash", String hash,
4108+
"Set hash(internal)";
40994109
] (fun ~rev_args ->
41004110
match rev_args with
41014111
| [x]

0 commit comments

Comments
 (0)