Skip to content

Commit 8f9243a

Browse files
authored
document init commands, tweak command line parsing lib (#5074)
1 parent 3f4dc4a commit 8f9243a

File tree

5 files changed

+112
-93
lines changed

5 files changed

+112
-93
lines changed

jscomp/bsb/bsb_arg.ml

+31-29
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,37 @@ let (+>) = Ext_buffer.add_string
5757

5858
let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
5959
buf +> usage;
60-
buf +> "\nOptions:\n";
61-
let max_col = ref 0 in
62-
Ext_array.iter speclist (fun (key,_,_) ->
63-
if String.length key > !max_col then
64-
max_col := String.length key
65-
);
66-
Ext_array.iter speclist (fun (key,_,doc) ->
67-
if not (Ext_string.starts_with doc "*internal*") then begin
68-
buf +> " ";
69-
buf +> key ;
70-
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
71-
let cur = ref 0 in
72-
let doc_length = String.length doc in
73-
while !cur < doc_length do
74-
if !cur <> 0 then begin
75-
buf +> "\n";
76-
buf +> String.make (!max_col + 4) ' ' ;
77-
end;
78-
match String.index_from_opt doc !cur '\n' with
79-
| None ->
80-
buf +> String.sub doc !cur (String.length doc - !cur );
81-
cur := doc_length
82-
| Some new_line_pos ->
83-
buf +> String.sub doc !cur (new_line_pos - !cur );
84-
cur := new_line_pos + 1
85-
done ;
86-
buf +> "\n"
87-
end
88-
)
60+
if Ext_array.is_empty speclist then () else begin
61+
buf +> "\nOptions:\n";
62+
let max_col = ref 0 in
63+
Ext_array.iter speclist (fun (key,_,_) ->
64+
if String.length key > !max_col then
65+
max_col := String.length key
66+
);
67+
Ext_array.iter speclist (fun (key,_,doc) ->
68+
if not (Ext_string.starts_with doc "*internal*") then begin
69+
buf +> " ";
70+
buf +> key ;
71+
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
72+
let cur = ref 0 in
73+
let doc_length = String.length doc in
74+
while !cur < doc_length do
75+
if !cur <> 0 then begin
76+
buf +> "\n";
77+
buf +> String.make (!max_col + 4) ' ' ;
78+
end;
79+
match String.index_from_opt doc !cur '\n' with
80+
| None ->
81+
buf +> String.sub doc !cur (String.length doc - !cur );
82+
cur := doc_length
83+
| Some new_line_pos ->
84+
buf +> String.sub doc !cur (new_line_pos - !cur );
85+
cur := new_line_pos + 1
86+
done ;
87+
buf +> "\n"
88+
end
89+
)
90+
end
8991
;;
9092

9193

jscomp/main/rescript_main.ml

+8-3
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,21 @@ let clean_subcommand ~start argv =
179179
if !make_world then
180180
Bsb_clean.clean_bs_deps Bsb_global_paths.cwd ;
181181
Bsb_clean.clean_self Bsb_global_paths.cwd
182-
182+
let init_usage = "Init the project\n\
183+
rescript init [project-name]\n\
184+
defaults to the current directory if not set\n\
185+
"
183186
let init_subcommand ~start argv =
184187
Bsb_arg.parse_exn
185-
~usage:"init the project" ~start ~argv [|
188+
~usage:init_usage ~start ~argv [|
186189
|] (fun
187190
~rev_args ->
188191
let location =
189192
match rev_args with
190-
| x :: _ ->
193+
| [x] ->
191194
x
195+
| last :: _another :: _ ->
196+
raise (Bsb_arg.Bad ("Don't know what to do with " ^ last))
192197
| [] ->
193198
"." in
194199
Bsb_theme_init.init_sample_project

lib/4.06.1/bsb.ml

+31-29
Original file line numberDiff line numberDiff line change
@@ -1780,35 +1780,37 @@ let (+>) = Ext_buffer.add_string
17801780

17811781
let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
17821782
buf +> usage;
1783-
buf +> "\nOptions:\n";
1784-
let max_col = ref 0 in
1785-
Ext_array.iter speclist (fun (key,_,_) ->
1786-
if String.length key > !max_col then
1787-
max_col := String.length key
1788-
);
1789-
Ext_array.iter speclist (fun (key,_,doc) ->
1790-
if not (Ext_string.starts_with doc "*internal*") then begin
1791-
buf +> " ";
1792-
buf +> key ;
1793-
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
1794-
let cur = ref 0 in
1795-
let doc_length = String.length doc in
1796-
while !cur < doc_length do
1797-
if !cur <> 0 then begin
1798-
buf +> "\n";
1799-
buf +> String.make (!max_col + 4) ' ' ;
1800-
end;
1801-
match String.index_from_opt doc !cur '\n' with
1802-
| None ->
1803-
buf +> String.sub doc !cur (String.length doc - !cur );
1804-
cur := doc_length
1805-
| Some new_line_pos ->
1806-
buf +> String.sub doc !cur (new_line_pos - !cur );
1807-
cur := new_line_pos + 1
1808-
done ;
1809-
buf +> "\n"
1810-
end
1811-
)
1783+
if Ext_array.is_empty speclist then () else begin
1784+
buf +> "\nOptions:\n";
1785+
let max_col = ref 0 in
1786+
Ext_array.iter speclist (fun (key,_,_) ->
1787+
if String.length key > !max_col then
1788+
max_col := String.length key
1789+
);
1790+
Ext_array.iter speclist (fun (key,_,doc) ->
1791+
if not (Ext_string.starts_with doc "*internal*") then begin
1792+
buf +> " ";
1793+
buf +> key ;
1794+
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
1795+
let cur = ref 0 in
1796+
let doc_length = String.length doc in
1797+
while !cur < doc_length do
1798+
if !cur <> 0 then begin
1799+
buf +> "\n";
1800+
buf +> String.make (!max_col + 4) ' ' ;
1801+
end;
1802+
match String.index_from_opt doc !cur '\n' with
1803+
| None ->
1804+
buf +> String.sub doc !cur (String.length doc - !cur );
1805+
cur := doc_length
1806+
| Some new_line_pos ->
1807+
buf +> String.sub doc !cur (new_line_pos - !cur );
1808+
cur := new_line_pos + 1
1809+
done ;
1810+
buf +> "\n"
1811+
end
1812+
)
1813+
end
18121814
;;
18131815

18141816

lib/4.06.1/rescript.ml

+39-32
Original file line numberDiff line numberDiff line change
@@ -1717,35 +1717,37 @@ let (+>) = Ext_buffer.add_string
17171717

17181718
let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
17191719
buf +> usage;
1720-
buf +> "\nOptions:\n";
1721-
let max_col = ref 0 in
1722-
Ext_array.iter speclist (fun (key,_,_) ->
1723-
if String.length key > !max_col then
1724-
max_col := String.length key
1725-
);
1726-
Ext_array.iter speclist (fun (key,_,doc) ->
1727-
if not (Ext_string.starts_with doc "*internal*") then begin
1728-
buf +> " ";
1729-
buf +> key ;
1730-
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
1731-
let cur = ref 0 in
1732-
let doc_length = String.length doc in
1733-
while !cur < doc_length do
1734-
if !cur <> 0 then begin
1735-
buf +> "\n";
1736-
buf +> String.make (!max_col + 4) ' ' ;
1737-
end;
1738-
match String.index_from_opt doc !cur '\n' with
1739-
| None ->
1740-
buf +> String.sub doc !cur (String.length doc - !cur );
1741-
cur := doc_length
1742-
| Some new_line_pos ->
1743-
buf +> String.sub doc !cur (new_line_pos - !cur );
1744-
cur := new_line_pos + 1
1745-
done ;
1746-
buf +> "\n"
1747-
end
1748-
)
1720+
if Ext_array.is_empty speclist then () else begin
1721+
buf +> "\nOptions:\n";
1722+
let max_col = ref 0 in
1723+
Ext_array.iter speclist (fun (key,_,_) ->
1724+
if String.length key > !max_col then
1725+
max_col := String.length key
1726+
);
1727+
Ext_array.iter speclist (fun (key,_,doc) ->
1728+
if not (Ext_string.starts_with doc "*internal*") then begin
1729+
buf +> " ";
1730+
buf +> key ;
1731+
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
1732+
let cur = ref 0 in
1733+
let doc_length = String.length doc in
1734+
while !cur < doc_length do
1735+
if !cur <> 0 then begin
1736+
buf +> "\n";
1737+
buf +> String.make (!max_col + 4) ' ' ;
1738+
end;
1739+
match String.index_from_opt doc !cur '\n' with
1740+
| None ->
1741+
buf +> String.sub doc !cur (String.length doc - !cur );
1742+
cur := doc_length
1743+
| Some new_line_pos ->
1744+
buf +> String.sub doc !cur (new_line_pos - !cur );
1745+
cur := new_line_pos + 1
1746+
done ;
1747+
buf +> "\n"
1748+
end
1749+
)
1750+
end
17491751
;;
17501752

17511753

@@ -16747,16 +16749,21 @@ let clean_subcommand ~start argv =
1674716749
if !make_world then
1674816750
Bsb_clean.clean_bs_deps Bsb_global_paths.cwd ;
1674916751
Bsb_clean.clean_self Bsb_global_paths.cwd
16750-
16752+
let init_usage = "Init the project\n\
16753+
rescript init [project-name]\n\
16754+
defaults to the current directory if not set\n\
16755+
"
1675116756
let init_subcommand ~start argv =
1675216757
Bsb_arg.parse_exn
16753-
~usage:"init the project" ~start ~argv [|
16758+
~usage:init_usage ~start ~argv [|
1675416759
|] (fun
1675516760
~rev_args ->
1675616761
let location =
1675716762
match rev_args with
16758-
| x :: _ ->
16763+
| [x] ->
1675916764
x
16765+
| last :: _another :: _ ->
16766+
raise (Bsb_arg.Bad ("Don't know what to do with " ^ last))
1676016767
| [] ->
1676116768
"." in
1676216769
Bsb_theme_init.init_sample_project

scripts/rescript_arg.js

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ function bad_arg(s) {
3737
function usage_b(b, usage, specs) {
3838
b.add(usage);
3939
b.add(`\nOptions:\n`);
40+
if(specs.length === 0){
41+
return
42+
}
4043
var max_col = 0;
4144
for (let [key] of specs) {
4245
if (key.length > max_col) {

0 commit comments

Comments
 (0)