Skip to content

Commit a5a7db2

Browse files
committed
misc-helper: make misc-helper.js <command> -h work
With this commit, we reap the benefits of using the modern paradigm: a proper usage is displayed when calling a sub-command with the `-h` option. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent f1a23b8 commit a5a7db2

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

script/misc-helper.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import { IPatchSeriesMetadata } from "../lib/patch-series-metadata.js";
1313
import { IConfig, loadConfig, setConfig } from "../lib/project-config.js";
1414
import path from "path";
1515

16-
const commander = new Command();
16+
let commander = new Command();
1717
const publishRemoteKey = "publishRemote";
1818

1919
commander
2020
.version("1.0.0")
21-
.usage("[options] ( update-open-prs | lookup-upstream-commit | annotate-commit <pr-number> <original> <git.git> )")
21+
.usage("[options] <command> [args...]")
2222
.description("Command-line helper for GitGitGadget")
23+
.passThroughOptions()
2324
.option(
2425
"-g, --git-work-dir [directory]",
2526
"Use a different git.git working directory than specified via `gitgitgadget.workDir`",
@@ -33,7 +34,7 @@ commander
3334
)
3435
.option("-c, --config <string>", "Use this configuration when using gitgitgadget with a project other than git", "")
3536
.option("-s, --skip-update", "Do not update the local refs (useful for debugging)")
36-
.argument("[args...]", "command and arguments")
37+
.argument("[args...]", "command arguments (call `list -h` for more information)")
3738
.parse(process.argv);
3839

3940
interface ICommanderOptions {
@@ -43,10 +44,6 @@ interface ICommanderOptions {
4344
skipUpdate: boolean | undefined;
4445
}
4546

46-
if (commander.args.length === 0) {
47-
commander.help();
48-
}
49-
5047
const commandOptions = commander.opts<ICommanderOptions>();
5148

5249
(async (): Promise<void> => {
@@ -75,6 +72,8 @@ const commandOptions = commander.opts<ICommanderOptions>();
7572

7673
const ci = new CIHelper(await getGitGitWorkDir(), commandOptions.skipUpdate, commandOptions.gitgitgadgetWorkDir);
7774

75+
const argv = commander.args;
76+
commander = new Command().version("1.0.0");
7877
commander
7978
.usage("[options] command")
8079
.command("update-open-prs")
@@ -474,7 +473,7 @@ const commandOptions = commander.opts<ICommanderOptions>();
474473
}
475474
await ci.handleNewMails(mailArchiveGitDir, onlyPRs.size ? onlyPRs : undefined);
476475
});
477-
await commander.parseAsync(commander.args, { from: "user" });
476+
await commander.parseAsync(argv, { from: "user" });
478477
})().catch((reason: Error) => {
479478
console.log(`Caught error ${reason}:\n${reason.stack}\n`);
480479
process.stderr.write(`Caught error ${reason}:\n${reason.stack}\n`);

0 commit comments

Comments
 (0)