@@ -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+
16141618type 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
16191622type key = string
16201623type doc = string
@@ -1638,10 +1641,14 @@ type key = string
16381641type doc = string
16391642type anon_fun = rev_args :string list -> unit
16401643
1644+ type string_action =
1645+ | Call of (string -> unit )
1646+ | Set of {mutable contents : string }
1647+
16411648type 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
16461653exception Bad of string
16471654
@@ -1650,10 +1657,6 @@ type error =
16501657 | Unknown of string
16511658 | Missing of string
16521659
1653-
1654-
1655-
1656-
16571660type t = (string * spec * string ) list
16581661
16591662let rec assoc3 (x : string ) (l : t ) =
@@ -1669,13 +1672,18 @@ let (+>) = Ext_buffer.add_string
16691672let 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. *)
40804088let 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+
40834093let dev_group = ref false
40844094let 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