Skip to content

tweak init subcommand #5074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions jscomp/bsb/bsb_arg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,37 @@ let (+>) = Ext_buffer.add_string

let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
buf +> usage;
buf +> "\nOptions:\n";
let max_col = ref 0 in
Ext_array.iter speclist (fun (key,_,_) ->
if String.length key > !max_col then
max_col := String.length key
);
Ext_array.iter speclist (fun (key,_,doc) ->
if not (Ext_string.starts_with doc "*internal*") then begin
buf +> " ";
buf +> key ;
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
let cur = ref 0 in
let doc_length = String.length doc in
while !cur < doc_length do
if !cur <> 0 then begin
buf +> "\n";
buf +> String.make (!max_col + 4) ' ' ;
end;
match String.index_from_opt doc !cur '\n' with
| None ->
buf +> String.sub doc !cur (String.length doc - !cur );
cur := doc_length
| Some new_line_pos ->
buf +> String.sub doc !cur (new_line_pos - !cur );
cur := new_line_pos + 1
done ;
buf +> "\n"
end
)
if Ext_array.is_empty speclist then () else begin
buf +> "\nOptions:\n";
let max_col = ref 0 in
Ext_array.iter speclist (fun (key,_,_) ->
if String.length key > !max_col then
max_col := String.length key
);
Ext_array.iter speclist (fun (key,_,doc) ->
if not (Ext_string.starts_with doc "*internal*") then begin
buf +> " ";
buf +> key ;
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
let cur = ref 0 in
let doc_length = String.length doc in
while !cur < doc_length do
if !cur <> 0 then begin
buf +> "\n";
buf +> String.make (!max_col + 4) ' ' ;
end;
match String.index_from_opt doc !cur '\n' with
| None ->
buf +> String.sub doc !cur (String.length doc - !cur );
cur := doc_length
| Some new_line_pos ->
buf +> String.sub doc !cur (new_line_pos - !cur );
cur := new_line_pos + 1
done ;
buf +> "\n"
end
)
end
;;


Expand Down
11 changes: 8 additions & 3 deletions jscomp/main/rescript_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,21 @@ let clean_subcommand ~start argv =
if !make_world then
Bsb_clean.clean_bs_deps Bsb_global_paths.cwd ;
Bsb_clean.clean_self Bsb_global_paths.cwd

let init_usage = "Init the project\n\
rescript init [project-name]\n\
defaults to the current directory if not set\n\
"
let init_subcommand ~start argv =
Bsb_arg.parse_exn
~usage:"init the project" ~start ~argv [|
~usage:init_usage ~start ~argv [|
|] (fun
~rev_args ->
let location =
match rev_args with
| x :: _ ->
| [x] ->
x
| last :: _another :: _ ->
raise (Bsb_arg.Bad ("Don't know what to do with " ^ last))
| [] ->
"." in
Bsb_theme_init.init_sample_project
Expand Down
60 changes: 31 additions & 29 deletions lib/4.06.1/bsb.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1780,35 +1780,37 @@ let (+>) = Ext_buffer.add_string

let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
buf +> usage;
buf +> "\nOptions:\n";
let max_col = ref 0 in
Ext_array.iter speclist (fun (key,_,_) ->
if String.length key > !max_col then
max_col := String.length key
);
Ext_array.iter speclist (fun (key,_,doc) ->
if not (Ext_string.starts_with doc "*internal*") then begin
buf +> " ";
buf +> key ;
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
let cur = ref 0 in
let doc_length = String.length doc in
while !cur < doc_length do
if !cur <> 0 then begin
buf +> "\n";
buf +> String.make (!max_col + 4) ' ' ;
end;
match String.index_from_opt doc !cur '\n' with
| None ->
buf +> String.sub doc !cur (String.length doc - !cur );
cur := doc_length
| Some new_line_pos ->
buf +> String.sub doc !cur (new_line_pos - !cur );
cur := new_line_pos + 1
done ;
buf +> "\n"
end
)
if Ext_array.is_empty speclist then () else begin
buf +> "\nOptions:\n";
let max_col = ref 0 in
Ext_array.iter speclist (fun (key,_,_) ->
if String.length key > !max_col then
max_col := String.length key
);
Ext_array.iter speclist (fun (key,_,doc) ->
if not (Ext_string.starts_with doc "*internal*") then begin
buf +> " ";
buf +> key ;
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
let cur = ref 0 in
let doc_length = String.length doc in
while !cur < doc_length do
if !cur <> 0 then begin
buf +> "\n";
buf +> String.make (!max_col + 4) ' ' ;
end;
match String.index_from_opt doc !cur '\n' with
| None ->
buf +> String.sub doc !cur (String.length doc - !cur );
cur := doc_length
| Some new_line_pos ->
buf +> String.sub doc !cur (new_line_pos - !cur );
cur := new_line_pos + 1
done ;
buf +> "\n"
end
)
end
;;


Expand Down
71 changes: 39 additions & 32 deletions lib/4.06.1/rescript.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1717,35 +1717,37 @@ let (+>) = Ext_buffer.add_string

let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
buf +> usage;
buf +> "\nOptions:\n";
let max_col = ref 0 in
Ext_array.iter speclist (fun (key,_,_) ->
if String.length key > !max_col then
max_col := String.length key
);
Ext_array.iter speclist (fun (key,_,doc) ->
if not (Ext_string.starts_with doc "*internal*") then begin
buf +> " ";
buf +> key ;
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
let cur = ref 0 in
let doc_length = String.length doc in
while !cur < doc_length do
if !cur <> 0 then begin
buf +> "\n";
buf +> String.make (!max_col + 4) ' ' ;
end;
match String.index_from_opt doc !cur '\n' with
| None ->
buf +> String.sub doc !cur (String.length doc - !cur );
cur := doc_length
| Some new_line_pos ->
buf +> String.sub doc !cur (new_line_pos - !cur );
cur := new_line_pos + 1
done ;
buf +> "\n"
end
)
if Ext_array.is_empty speclist then () else begin
buf +> "\nOptions:\n";
let max_col = ref 0 in
Ext_array.iter speclist (fun (key,_,_) ->
if String.length key > !max_col then
max_col := String.length key
);
Ext_array.iter speclist (fun (key,_,doc) ->
if not (Ext_string.starts_with doc "*internal*") then begin
buf +> " ";
buf +> key ;
buf +> (String.make (!max_col - String.length key + 2 ) ' ');
let cur = ref 0 in
let doc_length = String.length doc in
while !cur < doc_length do
if !cur <> 0 then begin
buf +> "\n";
buf +> String.make (!max_col + 4) ' ' ;
end;
match String.index_from_opt doc !cur '\n' with
| None ->
buf +> String.sub doc !cur (String.length doc - !cur );
cur := doc_length
| Some new_line_pos ->
buf +> String.sub doc !cur (new_line_pos - !cur );
cur := new_line_pos + 1
done ;
buf +> "\n"
end
)
end
;;


Expand Down Expand Up @@ -16747,16 +16749,21 @@ let clean_subcommand ~start argv =
if !make_world then
Bsb_clean.clean_bs_deps Bsb_global_paths.cwd ;
Bsb_clean.clean_self Bsb_global_paths.cwd

let init_usage = "Init the project\n\
rescript init [project-name]\n\
defaults to the current directory if not set\n\
"
let init_subcommand ~start argv =
Bsb_arg.parse_exn
~usage:"init the project" ~start ~argv [|
~usage:init_usage ~start ~argv [|
|] (fun
~rev_args ->
let location =
match rev_args with
| x :: _ ->
| [x] ->
x
| last :: _another :: _ ->
raise (Bsb_arg.Bad ("Don't know what to do with " ^ last))
| [] ->
"." in
Bsb_theme_init.init_sample_project
Expand Down
3 changes: 3 additions & 0 deletions scripts/rescript_arg.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function bad_arg(s) {
function usage_b(b, usage, specs) {
b.add(usage);
b.add(`\nOptions:\n`);
if(specs.length === 0){
return
}
var max_col = 0;
for (let [key] of specs) {
if (key.length > max_col) {
Expand Down