Skip to content

Commit 36190a4

Browse files
Merge pull request #6033 from NomicFoundation/add-verbose-flag
Enable debug logging via CLI flag
2 parents 899331f + 13c0b98 commit 36190a4

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

Diff for: v-next/hardhat/src/internal/builtin-global-options.ts

+12
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ export const BUILTIN_GLOBAL_OPTIONS_DEFINITIONS: GlobalOptionDefinitions =
5454
}),
5555
},
5656
],
57+
[
58+
"verbose",
59+
{
60+
pluginId: "builtin",
61+
option: globalOption({
62+
name: "verbose",
63+
description: "Enables Hardhat verbose logging.",
64+
type: ArgumentType.BOOLEAN,
65+
defaultValue: false,
66+
}),
67+
},
68+
],
5769
[
5870
"version",
5971
{

Diff for: v-next/hardhat/src/internal/cli/main.ts

+6
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ export async function parseBuiltinGlobalOptions(
259259
version = true;
260260
continue;
261261
}
262+
263+
if (arg === "--verbose") {
264+
usedCliArguments[i] = true;
265+
debug.enable("hardhat*");
266+
continue;
267+
}
262268
}
263269

264270
if (init && configPath !== undefined) {

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

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ GLOBAL OPTIONS:
200200
--show-stack-traces Show stack traces (always enabled on CI servers).
201201
--user-option-1 userOption1 description.
202202
--user-option-2 userOption2 description.
203+
--verbose Enables Hardhat verbose logging.
203204
--version Shows hardhat's version.
204205
205206
To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
@@ -298,6 +299,7 @@ GLOBAL OPTIONS:
298299
--show-stack-traces Show stack traces (always enabled on CI servers).
299300
--user-option-1 userOption1 description.
300301
--user-option-2 userOption2 description.
302+
--verbose Enables Hardhat verbose logging.
301303
--version Shows hardhat's version.
302304
303305
To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;

Diff for: v-next/hardhat/test/internal/cli/main.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
} from "../../../src/types/tasks.js";
1212

1313
import assert from "node:assert/strict";
14-
import { afterEach, before, describe, it } from "node:test";
14+
import { afterEach, before, describe, it, mock } from "node:test";
1515
import { pathToFileURL } from "node:url";
1616

1717
import { HardhatError } from "@ignored/hardhat-vnext-errors";
@@ -22,6 +22,7 @@ import {
2222
useFixtureProject,
2323
} from "@nomicfoundation/hardhat-test-utils";
2424
import chalk from "chalk";
25+
import debug from "debug";
2526

2627
import {
2728
main,
@@ -105,6 +106,19 @@ describe("main", function () {
105106
resetGlobalHardhatRuntimeEnvironment();
106107
});
107108

109+
describe("verbose", function () {
110+
useFixtureProject("cli/parsing/base-project");
111+
112+
it("should enable the debug logs", async function () {
113+
const spy = mock.method(debug, "enable");
114+
115+
const command = "npx hardhat --verbose";
116+
await runMain(command);
117+
118+
assert.equal(spy.mock.calls.length, 1);
119+
});
120+
});
121+
108122
describe("version", function () {
109123
useFixtureProject("cli/parsing/base-project");
110124

@@ -228,6 +242,7 @@ GLOBAL OPTIONS:
228242
--init Initializes a Hardhat project.
229243
--network The network to connect to
230244
--show-stack-traces Show stack traces (always enabled on CI servers).
245+
--verbose Enables Hardhat verbose logging.
231246
--version Shows hardhat's version.
232247
233248
To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;

Diff for: v-next/hardhat/test/internal/hre-intialization.ts

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ describe("HRE intialization", () => {
189189
help: false,
190190
init: false,
191191
showStackTraces: false,
192+
verbose: false,
192193
version: false,
193194
myGlobalOption: "default",
194195
network: "",

0 commit comments

Comments
 (0)