Skip to content

Add reanalyze and doc subcommands to rescript cli #7587

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

Closed
Closed
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
13 changes: 6 additions & 7 deletions analysis/reanalyze/src/Reanalyze.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ let runAnalysisAndReport ~cmtRoot =
let cli () =
let analysisKindSet = ref false in
let cmtRootRef = ref None in
let usage = "reanalyze version " ^ Version.version in
let versionAndExit () =
print_endline usage;
exit 0
[@@raises exit]
let usage =
{|Usage: rescript reanalyze [options]

`rescript reanalyze` is powerful dead code analysis tools to maintain a clean, efficient, and distraction-free codebase

Options:|}
in
let rec setAll cmtRoot =
RunConfig.all ();
Expand Down Expand Up @@ -203,8 +204,6 @@ let cli () =
"comma-separated-path-prefixes Report on files whose path has a prefix \
in the list, overriding -suppress (no-op if -suppress is not \
specified)" );
("-version", Unit versionAndExit, "Show version information and exit");
("--version", Unit versionAndExit, "Show version information and exit");
( "-write",
Set Common.Cli.write,
"Write @dead annotations directly in the source files" );
Expand Down
4 changes: 0 additions & 4 deletions analysis/reanalyze/src/Version.ml

This file was deleted.

19 changes: 16 additions & 3 deletions cli/rescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
// It matters since we need read .sourcedirs(location)
// and its content are file/directories with regard to project root

import * as tty from "node:tty";
import * as child_process from "node:child_process";
import * as fs from "node:fs";
import * as tty from "node:tty";

import { bsc_exe, rescript_exe } from "./common/bins.js";
import { bsc_exe, rescript_exe, rescript_tools_exe } from "./common/bins.js";
import * as bsb from "./common/bsb.js";

const cwd = process.cwd();
Expand Down Expand Up @@ -44,6 +45,8 @@ Subcommands:
build
clean
format
doc
reanalyze
dump
help

Expand Down Expand Up @@ -94,7 +97,7 @@ if (
console.log(helpMessage);
} else if (argPatterns.version.includes(args[0])) {
const packageSpec = JSON.parse(
fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8")
fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
);

console.log(packageSpec.version);
Expand Down Expand Up @@ -125,6 +128,16 @@ if (
mod.main(subcmdArgs, rescript_exe, bsc_exe);
break;
}
case "doc": {
const args = process.argv.slice(2);
child_process.spawnSync(rescript_tools_exe, args, { stdio: "inherit" });
break;
}
case "reanalyze": {
const args = process.argv.slice(2);
child_process.spawnSync(rescript_tools_exe, args, { stdio: "inherit" });
break;
}
default: {
console.error(`Error: Unknown command "${subcmd}".\n${helpMessage}`);
process.exit(2);
Expand Down
2 changes: 2 additions & 0 deletions tests/build_tests/cli_help/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const cliHelp =
" build\n" +
" clean\n" +
" format\n" +
" doc\n" +
" reanalyze\n" +
" dump\n" +
" help\n" +
"\n" +
Expand Down
12 changes: 2 additions & 10 deletions tools/bin/main.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
let docHelp =
{|ReScript Tools

Output documentation to standard output
{|Usage: rescript doc [file]

Usage: rescript-tools doc <FILE>

Example: rescript-tools doc ./path/to/EntryPointLib.res|}
`rescript doc` generate documentation and print to standard output|}

let help =
{|ReScript Tools
Expand All @@ -16,7 +12,6 @@ Commands:

doc <file> Generate documentation
reanalyze Reanalyze
-v, --version Print version
-h, --help Print help|}

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

let version = Version.version

let main () =
match Sys.argv |> Array.to_list |> List.tl with
| "doc" :: rest -> (
Expand Down Expand Up @@ -77,7 +70,6 @@ let main () =
close_out oc;
exit 0
| ["-h"] | ["--help"] -> logAndExit (Ok help)
| ["-v"] | ["--version"] -> logAndExit (Ok version)
| _ -> logAndExit (Error help)

let () = main ()
1 change: 0 additions & 1 deletion tools/bin/version.ml

This file was deleted.