Skip to content

Commit 37f9c07

Browse files
authored
Merge pull request #5060 from rescript-lang/fix_5055
fix #5055, add rescript format/convert subcommands
2 parents 75bf0fb + fc22f91 commit 37f9c07

File tree

8 files changed

+958
-440
lines changed

8 files changed

+958
-440
lines changed

jscomp/bsb/bsb_arg.ml

Lines changed: 4 additions & 9 deletions
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

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ let watch_mode = ref false
3030
let make_world = ref false
3131
let do_install = ref false
3232
let force_regenerate = ref false
33-
let bs_version_string = Bs_version.version
34-
let print_version_string () =
35-
print_string bs_version_string;
36-
print_newline ();
37-
exit 0
33+
3834
type spec = Bsb_arg.spec
3935

4036
let call_spec f : spec = Unit (Unit_call f )
@@ -115,17 +111,7 @@ let install_target () =
115111
if eid <> 0 then
116112
Bsb_unix.command_fatal_error install_command eid
117113

118-
let global_help () =
119-
print_string {|Available flags
120-
-v, -version display version number
121-
-h, -help display help
122-
Subcommands:
123-
build
124-
clean
125-
help
126-
Run rescript subcommand -h for more details, for example
127-
rescript build -h
128-
|}
114+
129115

130116
let build_subcommand ~start argv argv_len =
131117
let i = Ext_array.rfind_with_index argv Ext_string.equal separator in
@@ -189,7 +175,47 @@ let init_subcommand ~start argv =
189175
Bsb_theme_init.init_sample_project
190176
~cwd:Bsb_global_paths.cwd
191177
~theme:!current_theme location
192-
)
178+
)
179+
180+
let list_files = ref false
181+
let info_subcommand ~start argv =
182+
Bsb_arg.parse_exn
183+
~usage:"query the project" ~start ~argv [|
184+
"-list-files", unit_set_spec list_files,
185+
"list source files"
186+
|] (fun
187+
~rev_args ->
188+
189+
(match rev_args with
190+
| x :: _ ->
191+
raise (Bsb_arg.Bad ("Don't know what to do with " ^ x))
192+
| [] ->
193+
());
194+
if !list_files then begin
195+
match
196+
Bsb_ninja_regen.regenerate_ninja
197+
~package_kind:Toplevel
198+
~forced:true ~per_proj_dir:Bsb_global_paths.cwd with
199+
| None -> assert false
200+
| Some {file_groups = {files}} ->
201+
Ext_list.iter files (fun {sources } ->
202+
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
203+
let extensions =
204+
match syntax_kind,info with
205+
| _, Intf -> assert false
206+
| Reason , Impl -> [".re" ]
207+
| Reason, Impl_intf -> [".re"; ".rei"]
208+
| Ml, Impl -> [".ml"]
209+
| Ml, Impl_intf -> [".ml"; ".mli"]
210+
| Res, Impl -> [".res"]
211+
| Res, Impl_intf -> [".res"; ".resi"] in
212+
Ext_list.iter extensions (fun x ->
213+
print_endline (name_sans_extension ^ x )
214+
)
215+
)
216+
)
217+
end
218+
) ;;
193219
(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
194220
let () =
195221
let argv = Sys.argv in
@@ -203,21 +229,15 @@ let () =
203229
~per_proj_dir:Bsb_global_paths.cwd |> ignore;
204230
ninja_command_exit [||]
205231
end else
206-
207-
208-
209232
match argv.(1) with
210-
| "-version" | "-v"
211-
-> print_version_string ()
212-
| "-help" | "-h"
213-
-> global_help ()
214233
| "build" ->
215234
build_subcommand ~start:2 argv argv_len
216235
| "clean" ->
217236
clean_subcommand ~start:2 argv
218237
| "init" ->
219238
init_subcommand ~start:2 argv
220-
| "help" -> global_help ()
239+
| "info" -> (* internal *)
240+
info_subcommand ~start:2 argv
221241
| first_arg ->
222242
prerr_endline @@ "Unknown subcommand or flags: " ^ first_arg;
223243
exit 1

lib/4.06.1/bsb.ml

Lines changed: 4 additions & 9 deletions
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

0 commit comments

Comments
 (0)