@@ -3,6 +3,11 @@ import type { Task } from "@ignored/hardhat-vnext-core/types/tasks";
3
3
import assert from "node:assert/strict" ;
4
4
import { describe , it } from "node:test" ;
5
5
6
+ import { buildGlobalOptionsMap } from "@ignored/hardhat-vnext-core" ;
7
+ import {
8
+ globalOption ,
9
+ ParameterType ,
10
+ } from "@ignored/hardhat-vnext-core/config" ;
6
11
import { readClosestPackageJson } from "@ignored/hardhat-vnext-utils/package" ;
7
12
8
13
import { getGlobalHelpString } from "../../../../src/internal/cli/helpers/getGlobalHelpString.js" ;
@@ -13,7 +18,7 @@ describe("getGlobalHelpString", async function () {
13
18
describe ( "when there are no tasks" , function ( ) {
14
19
it ( "should return the global help string" , async function ( ) {
15
20
const tasks = new Map ( ) ;
16
- const help = await getGlobalHelpString ( tasks ) ;
21
+ const help = await getGlobalHelpString ( tasks , new Map ( ) ) ;
17
22
18
23
const expected = `Hardhat version ${ packageJson . version }
19
24
@@ -65,7 +70,7 @@ To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
65
70
] ,
66
71
] ) ;
67
72
68
- const help = await getGlobalHelpString ( tasks ) ;
73
+ const help = await getGlobalHelpString ( tasks , new Map ( ) ) ;
69
74
70
75
const expected = `Hardhat version ${ packageJson . version }
71
76
@@ -132,7 +137,7 @@ To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
132
137
] ,
133
138
] ) ;
134
139
135
- const help = await getGlobalHelpString ( tasks ) ;
140
+ const help = await getGlobalHelpString ( tasks , new Map ( ) ) ;
136
141
137
142
const expected = `Hardhat version ${ packageJson . version }
138
143
@@ -154,6 +159,49 @@ GLOBAL OPTIONS:
154
159
--show-stack-traces Show stack traces (always enabled on CI servers).
155
160
--version Shows hardhat's version.
156
161
162
+ To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help` ;
163
+
164
+ assert . equal ( help , expected ) ;
165
+ } ) ;
166
+ } ) ;
167
+
168
+ describe ( "when there are user-defined global options" , function ( ) {
169
+ it ( "should return the global help string with the user-defined global options" , async function ( ) {
170
+ const tasks = new Map ( ) ;
171
+ const globalOptionsMap = buildGlobalOptionsMap ( [
172
+ {
173
+ id : "plugin1" ,
174
+ globalOptions : [
175
+ globalOption ( {
176
+ name : "userOption1" ,
177
+ description : "userOption1 description." ,
178
+ parameterType : ParameterType . STRING ,
179
+ defaultValue : "default" ,
180
+ } ) ,
181
+ globalOption ( {
182
+ name : "userOption2" ,
183
+ description : "userOption2 description." ,
184
+ parameterType : ParameterType . STRING ,
185
+ defaultValue : "default" ,
186
+ } ) ,
187
+ ] ,
188
+ } ,
189
+ ] ) ;
190
+ const help = await getGlobalHelpString ( tasks , globalOptionsMap ) ;
191
+
192
+ const expected = `Hardhat version ${ packageJson . version }
193
+
194
+ Usage: hardhat [GLOBAL OPTIONS] <TASK> [SUBTASK] [TASK OPTIONS] [--] [TASK ARGUMENTS]
195
+
196
+ GLOBAL OPTIONS:
197
+
198
+ --config A Hardhat config file.
199
+ --help Shows this message, or a task's help if its name is provided.
200
+ --show-stack-traces Show stack traces (always enabled on CI servers).
201
+ --version Shows hardhat's version.
202
+ --user-option-1 userOption1 description.
203
+ --user-option-2 userOption2 description.
204
+
157
205
To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help` ;
158
206
159
207
assert . equal ( help , expected ) ;
0 commit comments