Skip to content

Commit 8eadda9

Browse files
committed
experimental support for format/convert subcommands
1 parent 75bf0fb commit 8eadda9

File tree

8 files changed

+869
-327
lines changed

8 files changed

+869
-327
lines changed

jscomp/bsb/bsb_arg.ml

+4-9
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,15 @@ let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
7171
let cur = ref 0 in
7272
let doc_length = String.length doc in
7373
while !cur < doc_length do
74+
if !cur <> 0 then begin
75+
buf +> "\n";
76+
buf +> String.make (!max_col + 4) ' ' ;
77+
end;
7478
match String.index_from_opt doc !cur '\n' with
7579
| None ->
76-
if !cur <> 0 then begin
77-
buf +> "\n";
78-
buf +> String.make (!max_col + 4) ' ' ;
79-
end;
8080
buf +> String.sub doc !cur (String.length doc - !cur );
8181
cur := doc_length
8282
| Some new_line_pos ->
83-
if !cur <> 0 then begin
84-
buf +> "\n";
85-
buf +> String.make (!max_col + 4) ' ' ;
86-
end;
8783
buf +> String.sub doc !cur (new_line_pos - !cur );
8884
cur := new_line_pos + 1
8985
done ;
@@ -149,4 +145,3 @@ let parse_exn ~usage ~argv ?(start=1) ?(finish=Array.length argv) (speclist : t
149145
anonfun ~rev_args:!rev_list
150146
;;
151147

152-

jscomp/main/rescript_main.ml

+43-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,47 @@ let init_subcommand ~start argv =
189189
Bsb_theme_init.init_sample_project
190190
~cwd:Bsb_global_paths.cwd
191191
~theme:!current_theme location
192-
)
192+
)
193+
194+
let list_files = ref false
195+
let info_subcommand ~start argv =
196+
Bsb_arg.parse_exn
197+
~usage:"query the project" ~start ~argv [|
198+
"-list-files", unit_set_spec list_files,
199+
"list source files"
200+
|] (fun
201+
~rev_args ->
202+
203+
(match rev_args with
204+
| x :: _ ->
205+
raise (Bsb_arg.Bad ("Don't know what to do with " ^ x))
206+
| [] ->
207+
());
208+
if !list_files then begin
209+
match
210+
Bsb_ninja_regen.regenerate_ninja
211+
~package_kind:Toplevel
212+
~forced:true ~per_proj_dir:Bsb_global_paths.cwd with
213+
| None -> assert false
214+
| Some {file_groups = {files}} ->
215+
Ext_list.iter files (fun {sources } ->
216+
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
217+
let extensions =
218+
match syntax_kind,info with
219+
| _, Intf -> assert false
220+
| Reason , Impl -> [".re" ]
221+
| Reason, Impl_intf -> [".re"; ".rei"]
222+
| Ml, Impl -> [".ml"]
223+
| Ml, Impl_intf -> [".ml"; ".mli"]
224+
| Res, Impl -> [".res"]
225+
| Res, Impl_intf -> [".res"; ".resi"] in
226+
Ext_list.iter extensions (fun x ->
227+
print_endline (name_sans_extension ^ x )
228+
)
229+
)
230+
)
231+
end
232+
) ;;
193233
(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
194234
let () =
195235
let argv = Sys.argv in
@@ -217,6 +257,8 @@ let () =
217257
clean_subcommand ~start:2 argv
218258
| "init" ->
219259
init_subcommand ~start:2 argv
260+
| "info" ->
261+
info_subcommand ~start:2 argv
220262
| "help" -> global_help ()
221263
| first_arg ->
222264
prerr_endline @@ "Unknown subcommand or flags: " ^ first_arg;

lib/4.06.1/bsb.ml

+4-9
Original file line numberDiff line numberDiff line change
@@ -1794,19 +1794,15 @@ let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
17941794
let cur = ref 0 in
17951795
let doc_length = String.length doc in
17961796
while !cur < doc_length do
1797+
if !cur <> 0 then begin
1798+
buf +> "\n";
1799+
buf +> String.make (!max_col + 4) ' ' ;
1800+
end;
17971801
match String.index_from_opt doc !cur '\n' with
17981802
| None ->
1799-
if !cur <> 0 then begin
1800-
buf +> "\n";
1801-
buf +> String.make (!max_col + 4) ' ' ;
1802-
end;
18031803
buf +> String.sub doc !cur (String.length doc - !cur );
18041804
cur := doc_length
18051805
| Some new_line_pos ->
1806-
if !cur <> 0 then begin
1807-
buf +> "\n";
1808-
buf +> String.make (!max_col + 4) ' ' ;
1809-
end;
18101806
buf +> String.sub doc !cur (new_line_pos - !cur );
18111807
cur := new_line_pos + 1
18121808
done ;
@@ -1873,7 +1869,6 @@ let parse_exn ~usage ~argv ?(start=1) ?(finish=Array.length argv) (speclist : t
18731869
;;
18741870

18751871

1876-
18771872
end
18781873
module Bsb_build_schemas
18791874
= struct

lib/4.06.1/rescript.ml

+47-10
Original file line numberDiff line numberDiff line change
@@ -1794,19 +1794,15 @@ let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
17941794
let cur = ref 0 in
17951795
let doc_length = String.length doc in
17961796
while !cur < doc_length do
1797+
if !cur <> 0 then begin
1798+
buf +> "\n";
1799+
buf +> String.make (!max_col + 4) ' ' ;
1800+
end;
17971801
match String.index_from_opt doc !cur '\n' with
17981802
| None ->
1799-
if !cur <> 0 then begin
1800-
buf +> "\n";
1801-
buf +> String.make (!max_col + 4) ' ' ;
1802-
end;
18031803
buf +> String.sub doc !cur (String.length doc - !cur );
18041804
cur := doc_length
18051805
| Some new_line_pos ->
1806-
if !cur <> 0 then begin
1807-
buf +> "\n";
1808-
buf +> String.make (!max_col + 4) ' ' ;
1809-
end;
18101806
buf +> String.sub doc !cur (new_line_pos - !cur );
18111807
cur := new_line_pos + 1
18121808
done ;
@@ -1873,7 +1869,6 @@ let parse_exn ~usage ~argv ?(start=1) ?(finish=Array.length argv) (speclist : t
18731869
;;
18741870

18751871

1876-
18771872
end
18781873
module Bsb_build_schemas
18791874
= struct
@@ -16761,7 +16756,47 @@ let init_subcommand ~start argv =
1676116756
Bsb_theme_init.init_sample_project
1676216757
~cwd:Bsb_global_paths.cwd
1676316758
~theme:!current_theme location
16764-
)
16759+
)
16760+
16761+
let list_files = ref false
16762+
let info_subcommand ~start argv =
16763+
Bsb_arg.parse_exn
16764+
~usage:"query the project" ~start ~argv [|
16765+
"-list-files", unit_set_spec list_files,
16766+
"list source files"
16767+
|] (fun
16768+
~rev_args ->
16769+
16770+
(match rev_args with
16771+
| x :: _ ->
16772+
raise (Bsb_arg.Bad ("Don't know what to do with " ^ x))
16773+
| [] ->
16774+
());
16775+
if !list_files then begin
16776+
match
16777+
Bsb_ninja_regen.regenerate_ninja
16778+
~package_kind:Toplevel
16779+
~forced:true ~per_proj_dir:Bsb_global_paths.cwd with
16780+
| None -> assert false
16781+
| Some {file_groups = {files}} ->
16782+
Ext_list.iter files (fun {sources } ->
16783+
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
16784+
let extensions =
16785+
match syntax_kind,info with
16786+
| _, Intf -> assert false
16787+
| Reason , Impl -> [".re" ]
16788+
| Reason, Impl_intf -> [".re"; ".rei"]
16789+
| Ml, Impl -> [".ml"]
16790+
| Ml, Impl_intf -> [".ml"; ".mli"]
16791+
| Res, Impl -> [".res"]
16792+
| Res, Impl_intf -> [".res"; ".resi"] in
16793+
Ext_list.iter extensions (fun x ->
16794+
print_endline (name_sans_extension ^ x )
16795+
)
16796+
)
16797+
)
16798+
end
16799+
) ;;
1676516800
(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
1676616801
let () =
1676716802
let argv = Sys.argv in
@@ -16789,6 +16824,8 @@ let () =
1678916824
clean_subcommand ~start:2 argv
1679016825
| "init" ->
1679116826
init_subcommand ~start:2 argv
16827+
| "info" ->
16828+
info_subcommand ~start:2 argv
1679216829
| "help" -> global_help ()
1679316830
| first_arg ->
1679416831
prerr_endline @@ "Unknown subcommand or flags: " ^ first_arg;

0 commit comments

Comments
 (0)