Skip to content

Commit cd1a879

Browse files
committed
Include the builtin options as part of the global options & augment types
1 parent 47c4228 commit cd1a879

File tree

7 files changed

+211
-75
lines changed

7 files changed

+211
-75
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { GlobalOptions } from "@ignored/hardhat-vnext/types/global-options";
2+
13
import { HardhatPluginError } from "@ignored/hardhat-vnext/plugins";
24

35
import {
@@ -126,6 +128,15 @@ const pluginExample = {
126128
],
127129
};
128130

131+
// Type includes the builtin global options
132+
const _globalOptions: GlobalOptions = {
133+
configPath: "",
134+
help: false,
135+
init: false,
136+
showStackTraces: false,
137+
version: false,
138+
};
139+
129140
const config: HardhatUserConfig = {
130141
tasks: [
131142
exampleTaskOverride,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type { GlobalOptionDefinitions } from "../types/global-options.js";
2+
3+
import { globalOption, ArgumentType } from "../config.js";
4+
5+
export const BUILTIN_GLOBAL_OPTIONS_DEFINITIONS: GlobalOptionDefinitions =
6+
new Map([
7+
[
8+
"config",
9+
{
10+
pluginId: "hardhat",
11+
option: globalOption({
12+
name: "config",
13+
description: "A Hardhat config file.",
14+
type: ArgumentType.STRING,
15+
defaultValue: "",
16+
}),
17+
},
18+
],
19+
[
20+
"help",
21+
{
22+
pluginId: "hardhat",
23+
option: globalOption({
24+
name: "help",
25+
description:
26+
"Shows this message, or a task's help if its name is provided.",
27+
type: ArgumentType.BOOLEAN,
28+
defaultValue: false,
29+
}),
30+
},
31+
],
32+
[
33+
"showStackTraces",
34+
{
35+
pluginId: "hardhat",
36+
option: globalOption({
37+
name: "showStackTraces",
38+
description: "Show stack traces (always enabled on CI servers).",
39+
type: ArgumentType.BOOLEAN,
40+
defaultValue: false,
41+
}),
42+
},
43+
],
44+
[
45+
"version",
46+
{
47+
pluginId: "hardhat",
48+
option: globalOption({
49+
name: "version",
50+
description: "Shows hardhat's version.",
51+
type: ArgumentType.BOOLEAN,
52+
defaultValue: false,
53+
}),
54+
},
55+
],
56+
]);

v-next/hardhat/src/internal/builtin-options.ts

-31
This file was deleted.

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

+4-19
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import type { ArgumentType } from "@ignored/hardhat-vnext-core/config";
22
import type { GlobalOptionDefinitions } from "@ignored/hardhat-vnext-core/types/global-options";
33
import type { Task } from "@ignored/hardhat-vnext-core/types/tasks";
44

5-
import { BUILTIN_OPTIONS } from "../../builtin-options.js";
6-
75
export const GLOBAL_NAME_PADDING = 6;
86

97
interface ArgumentDescriptor {
@@ -16,23 +14,10 @@ interface ArgumentDescriptor {
1614
export function parseGlobalOptions(
1715
globalOptionDefinitions: GlobalOptionDefinitions,
1816
): ArgumentDescriptor[] {
19-
const formattedBuiltinOptions = BUILTIN_OPTIONS.map(
20-
({ name, description }) => ({
21-
name: formatOptionName(name),
22-
description,
23-
}),
24-
);
25-
26-
const formattedUserOptions = Array.from(globalOptionDefinitions).map(
27-
([, entry]) => {
28-
return {
29-
name: formatOptionName(entry.option.name),
30-
description: entry.option.description,
31-
};
32-
},
33-
);
34-
35-
return [...formattedBuiltinOptions, ...formattedUserOptions];
17+
return [...globalOptionDefinitions].map(([, { option }]) => ({
18+
name: formatOptionName(option.name),
19+
description: option.description,
20+
}));
3621
}
3722

3823
export function parseTasks(taskMap: Map<string, Task>): {

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { kebabToCamelCase } from "@ignored/hardhat-vnext-utils/string";
2828

2929
import { resolveHardhatConfigPath } from "../../config.js";
3030
import { createHardhatRuntimeEnvironment } from "../../hre.js";
31+
import { BUILTIN_GLOBAL_OPTIONS_DEFINITIONS } from "../builtin-global-options.js";
3132
import { builtinPlugins } from "../builtin-plugins/index.js";
3233
import { setGlobalHardhatRuntimeEnvironment } from "../global-hre-instance.js";
3334
import { importUserConfig } from "../helpers/config-loading.js";
@@ -77,8 +78,12 @@ export async function main(
7778
builtinGlobalOptions.configPath,
7879
);
7980

80-
const globalOptionDefinitions =
81+
const pluginGlobalOptionDefinitions =
8182
buildGlobalOptionDefinitions(resolvedPlugins);
83+
const globalOptionDefinitions = new Map([
84+
...BUILTIN_GLOBAL_OPTIONS_DEFINITIONS,
85+
...pluginGlobalOptionDefinitions,
86+
]);
8287
const userProvidedGlobalOptions = await parseGlobalOptions(
8388
globalOptionDefinitions,
8489
cliArguments,
@@ -87,7 +92,7 @@ export async function main(
8792

8893
const hre = await createHardhatRuntimeEnvironment(
8994
userConfig,
90-
userProvidedGlobalOptions,
95+
{ ...builtinGlobalOptions, ...userProvidedGlobalOptions },
9196
{ resolvedPlugins, globalOptionDefinitions },
9297
);
9398

+12
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1+
import "@ignored/hardhat-vnext-core/types/global-options";
2+
3+
declare module "@ignored/hardhat-vnext-core/types/global-options" {
4+
export interface GlobalOptions {
5+
configPath: string;
6+
help: boolean;
7+
init: boolean;
8+
showStackTraces: boolean;
9+
version: boolean;
10+
}
11+
}
12+
113
export type * from "@ignored/hardhat-vnext-core/types/global-options";
214
export * from "@ignored/hardhat-vnext-core/types/global-options";

0 commit comments

Comments
 (0)