Skip to content

Commit d8fd59a

Browse files
committed
Use globalOption to create the builtin options
1 parent 91e4c91 commit d8fd59a

File tree

5 files changed

+49
-23
lines changed

5 files changed

+49
-23
lines changed

v-next/example-project/hardhat.config.ts

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
emptyTask,
77
overrideTask,
88
configVariable,
9+
globalOption,
910
} from "@ignored/hardhat-vnext/config";
1011

1112
const exampleEmptyTask = emptyTask("empty", "An example empty task").build();
@@ -116,6 +117,13 @@ const pluginExample = {
116117
})
117118
.build(),
118119
],
120+
globalOptions: [
121+
globalOption({
122+
name: "myGlobalOption",
123+
description: "A global option",
124+
defaultValue: "default",
125+
}),
126+
],
119127
};
120128

121129
const config: HardhatUserConfig = {
+27-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
export const BUILTIN_OPTIONS: Array<{
2-
name: string;
3-
description: string;
4-
}> = [
5-
{
6-
name: "--config",
1+
import type { GlobalOption } from "../types/global-options.js";
2+
3+
import { globalOption, ParameterType } from "../config.js";
4+
5+
export const BUILTIN_OPTIONS: GlobalOption[] = [
6+
globalOption({
7+
name: "config",
78
description: "A Hardhat config file.",
8-
},
9-
{
10-
name: "--help",
11-
description: "Shows this message, or a task's help if its name is provided",
12-
},
13-
{
14-
name: "--show-stack-traces",
9+
parameterType: ParameterType.STRING,
10+
defaultValue: "",
11+
}),
12+
globalOption({
13+
name: "help",
14+
description:
15+
"Shows this message, or a task's help if its name is provided.",
16+
parameterType: ParameterType.BOOLEAN,
17+
defaultValue: false,
18+
}),
19+
globalOption({
20+
name: "showStackTraces",
1521
description: "Show stack traces (always enabled on CI servers).",
16-
},
17-
{
18-
name: "--version",
22+
parameterType: ParameterType.BOOLEAN,
23+
defaultValue: false,
24+
}),
25+
globalOption({
26+
name: "version",
1927
description: "Shows hardhat's version.",
20-
},
28+
parameterType: ParameterType.BOOLEAN,
29+
defaultValue: false,
30+
}),
2131
];

v-next/hardhat/src/internal/cli/helpers/getGlobalHelpString.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getHardhatVersion } from "../../utils/package.js";
55

66
import {
77
GLOBAL_NAME_PADDING,
8+
formatOptionName,
89
getLongestNameLength,
910
getSection,
1011
parseTasks,
@@ -17,8 +18,15 @@ export async function getGlobalHelpString(
1718

1819
const { tasks, subtasks } = parseTasks(rootTasks);
1920

21+
const formattedBuiltinOptions = BUILTIN_OPTIONS.map(
22+
({ name, description }) => ({
23+
name: formatOptionName(name),
24+
description,
25+
}),
26+
);
27+
2028
const namePadding =
21-
getLongestNameLength([...tasks, ...subtasks, ...BUILTIN_OPTIONS]) +
29+
getLongestNameLength([...tasks, ...subtasks, ...formattedBuiltinOptions]) +
2230
GLOBAL_NAME_PADDING;
2331

2432
let output = `Hardhat version ${version}
@@ -34,7 +42,7 @@ Usage: hardhat [GLOBAL OPTIONS] <TASK> [SUBTASK] [TASK OPTIONS] [--] [TASK ARGUM
3442
output += getSection("AVAILABLE SUBTASKS", subtasks, namePadding);
3543
}
3644

37-
output += getSection("GLOBAL OPTIONS", BUILTIN_OPTIONS, namePadding);
45+
output += getSection("GLOBAL OPTIONS", formattedBuiltinOptions, namePadding);
3846

3947
output += `\nTo get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
4048

v-next/hardhat/test/internal/cli/helpers/getGlobalHelpString.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Usage: hardhat [GLOBAL OPTIONS] <TASK> [SUBTASK] [TASK OPTIONS] [--] [TASK ARGUM
2222
GLOBAL OPTIONS:
2323
2424
--config A Hardhat config file.
25-
--help Shows this message, or a task's help if its name is provided
25+
--help Shows this message, or a task's help if its name is provided.
2626
--show-stack-traces Show stack traces (always enabled on CI servers).
2727
--version Shows hardhat's version.
2828
@@ -79,7 +79,7 @@ AVAILABLE TASKS:
7979
GLOBAL OPTIONS:
8080
8181
--config A Hardhat config file.
82-
--help Shows this message, or a task's help if its name is provided
82+
--help Shows this message, or a task's help if its name is provided.
8383
--show-stack-traces Show stack traces (always enabled on CI servers).
8484
--version Shows hardhat's version.
8585
@@ -150,7 +150,7 @@ AVAILABLE SUBTASKS:
150150
GLOBAL OPTIONS:
151151
152152
--config A Hardhat config file.
153-
--help Shows this message, or a task's help if its name is provided
153+
--help Shows this message, or a task's help if its name is provided.
154154
--show-stack-traces Show stack traces (always enabled on CI servers).
155155
--version Shows hardhat's version.
156156

v-next/hardhat/test/internal/cli/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ AVAILABLE TASKS:
222222
GLOBAL OPTIONS:
223223
224224
--config A Hardhat config file.
225-
--help Shows this message, or a task's help if its name is provided
225+
--help Shows this message, or a task's help if its name is provided.
226226
--show-stack-traces Show stack traces (always enabled on CI servers).
227227
--version Shows hardhat's version.
228228

0 commit comments

Comments
 (0)