Skip to content

Commit d85cac0

Browse files
committed
Add reanalyze and doc subcommands to rescript cli
1 parent 9b911ac commit d85cac0

File tree

8 files changed

+25
-26
lines changed

8 files changed

+25
-26
lines changed

analysis/reanalyze/src/Reanalyze.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,12 @@ let runAnalysisAndReport ~cmtRoot =
106106
let cli () =
107107
let analysisKindSet = ref false in
108108
let cmtRootRef = ref None in
109-
let usage = "reanalyze version " ^ Version.version in
110-
let versionAndExit () =
111-
print_endline usage;
112-
exit 0
113-
[@@raises exit]
109+
let usage =
110+
{|Usage: rescript reanalyze [options]
111+
112+
`rescript reanalyze` is powerful dead code analysis tools to maintain a clean, efficient, and distraction-free codebase
113+
114+
Options:|}
114115
in
115116
let rec setAll cmtRoot =
116117
RunConfig.all ();
@@ -203,14 +204,12 @@ let cli () =
203204
"comma-separated-path-prefixes Report on files whose path has a prefix \
204205
in the list, overriding -suppress (no-op if -suppress is not \
205206
specified)" );
206-
("-version", Unit versionAndExit, "Show version information and exit");
207-
("--version", Unit versionAndExit, "Show version information and exit");
208207
( "-write",
209208
Set Common.Cli.write,
210209
"Write @dead annotations directly in the source files" );
211210
]
212211
in
213-
Arg.parse speclist print_endline usage;
212+
Arg.parse speclist (fun _ -> ()) usage;
214213
if !analysisKindSet = false then setConfig ();
215214
let cmtRoot = !cmtRootRef in
216215
runAnalysisAndReport ~cmtRoot

analysis/reanalyze/src/Version.ml

Lines changed: 0 additions & 4 deletions
This file was deleted.

cli/rescript.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
import * as tty from "node:tty";
1010
import * as fs from "node:fs";
11+
import * as child_process from "node:child_process";
1112

12-
import { bsc_exe, rescript_exe } from "./common/bins.js";
13+
import { bsc_exe, rescript_exe, rescript_tools_exe } from "./common/bins.js";
1314
import * as bsb from "./common/bsb.js";
1415

1516
const cwd = process.cwd();
@@ -44,6 +45,8 @@ Subcommands:
4445
build
4546
clean
4647
format
48+
doc
49+
reanalyze
4750
dump
4851
help
4952
@@ -125,6 +128,16 @@ if (
125128
mod.main(subcmdArgs, rescript_exe, bsc_exe);
126129
break;
127130
}
131+
case "doc": {
132+
const args = process.argv.slice(2);
133+
child_process.spawnSync(rescript_tools_exe, args, { stdio: "inherit" });
134+
break;
135+
}
136+
case "reanalyze": {
137+
const args = process.argv.slice(2);
138+
child_process.spawnSync(rescript_tools_exe, args, { stdio: "inherit" });
139+
break;
140+
}
128141
default: {
129142
console.error(`Error: Unknown command "${subcmd}".\n${helpMessage}`);
130143
process.exit(2);

tests/analysis_tests/tests-reanalyze/deadcode/expected/deadcode.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Scanning AutoAnnotate.cmt Source:AutoAnnotate.res
32
addVariantCaseDeclaration R AutoAnnotate.res:1:15 path:+AutoAnnotate.variant
43
addRecordLabelDeclaration variant AutoAnnotate.res:4:15 path:+AutoAnnotate.record

tests/analysis_tests/tests-reanalyze/deadcode/expected/exception.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
32
Exception Analysis
43
Exn.res:1:5-10
54
raises might raise Not_found (Exn.res:1:19) and is not annotated with @raises(Not_found)

tests/build_tests/cli_help/input.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const cliHelp =
1919
" build\n" +
2020
" clean\n" +
2121
" format\n" +
22+
" doc\n" +
23+
" reanalyze\n" +
2224
" dump\n" +
2325
" help\n" +
2426
"\n" +

tools/bin/main.ml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
let docHelp =
2-
{|ReScript Tools
3-
4-
Output documentation to standard output
2+
{|Usage: rescript doc [file]
53

6-
Usage: rescript-tools doc <FILE>
7-
8-
Example: rescript-tools doc ./path/to/EntryPointLib.res|}
4+
`rescript doc` generate documentation and print to standard output|}
95

106
let help =
117
{|ReScript Tools
@@ -16,7 +12,6 @@ Commands:
1612

1713
doc <file> Generate documentation
1814
reanalyze Reanalyze
19-
-v, --version Print version
2015
-h, --help Print help|}
2116

2217
let logAndExit = function
@@ -27,8 +22,6 @@ let logAndExit = function
2722
Printf.eprintf "%s\n" log;
2823
exit 1
2924

30-
let version = Version.version
31-
3225
let main () =
3326
match Sys.argv |> Array.to_list |> List.tl with
3427
| "doc" :: rest -> (
@@ -77,7 +70,6 @@ let main () =
7770
close_out oc;
7871
exit 0
7972
| ["-h"] | ["--help"] -> logAndExit (Ok help)
80-
| ["-v"] | ["--version"] -> logAndExit (Ok version)
8173
| _ -> logAndExit (Error help)
8274

8375
let () = main ()

tools/bin/version.ml

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)