Skip to content

Commit

Permalink
Merge pull request #6033 from NomicFoundation/add-verbose-flag
Browse files Browse the repository at this point in the history
Enable debug logging via CLI flag
  • Loading branch information
ChristopherDedominici authored Dec 10, 2024
2 parents 899331f + 13c0b98 commit 36190a4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions v-next/hardhat/src/internal/builtin-global-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ export const BUILTIN_GLOBAL_OPTIONS_DEFINITIONS: GlobalOptionDefinitions =
}),
},
],
[
"verbose",
{
pluginId: "builtin",
option: globalOption({
name: "verbose",
description: "Enables Hardhat verbose logging.",
type: ArgumentType.BOOLEAN,
defaultValue: false,
}),
},
],
[
"version",
{
Expand Down
6 changes: 6 additions & 0 deletions v-next/hardhat/src/internal/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ export async function parseBuiltinGlobalOptions(
version = true;
continue;
}

if (arg === "--verbose") {
usedCliArguments[i] = true;
debug.enable("hardhat*");
continue;
}
}

if (init && configPath !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ GLOBAL OPTIONS:
--show-stack-traces Show stack traces (always enabled on CI servers).
--user-option-1 userOption1 description.
--user-option-2 userOption2 description.
--verbose Enables Hardhat verbose logging.
--version Shows hardhat's version.
To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
Expand Down Expand Up @@ -298,6 +299,7 @@ GLOBAL OPTIONS:
--show-stack-traces Show stack traces (always enabled on CI servers).
--user-option-1 userOption1 description.
--user-option-2 userOption2 description.
--verbose Enables Hardhat verbose logging.
--version Shows hardhat's version.
To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
Expand Down
17 changes: 16 additions & 1 deletion v-next/hardhat/test/internal/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
} from "../../../src/types/tasks.js";

import assert from "node:assert/strict";
import { afterEach, before, describe, it } from "node:test";
import { afterEach, before, describe, it, mock } from "node:test";
import { pathToFileURL } from "node:url";

import { HardhatError } from "@ignored/hardhat-vnext-errors";
Expand All @@ -22,6 +22,7 @@ import {
useFixtureProject,
} from "@nomicfoundation/hardhat-test-utils";
import chalk from "chalk";
import debug from "debug";

import {
main,
Expand Down Expand Up @@ -105,6 +106,19 @@ describe("main", function () {
resetGlobalHardhatRuntimeEnvironment();
});

describe("verbose", function () {
useFixtureProject("cli/parsing/base-project");

it("should enable the debug logs", async function () {
const spy = mock.method(debug, "enable");

const command = "npx hardhat --verbose";
await runMain(command);

assert.equal(spy.mock.calls.length, 1);
});
});

describe("version", function () {
useFixtureProject("cli/parsing/base-project");

Expand Down Expand Up @@ -228,6 +242,7 @@ GLOBAL OPTIONS:
--init Initializes a Hardhat project.
--network The network to connect to
--show-stack-traces Show stack traces (always enabled on CI servers).
--verbose Enables Hardhat verbose logging.
--version Shows hardhat's version.
To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
Expand Down
1 change: 1 addition & 0 deletions v-next/hardhat/test/internal/hre-intialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ describe("HRE intialization", () => {
help: false,
init: false,
showStackTraces: false,
verbose: false,
version: false,
myGlobalOption: "default",
network: "",
Expand Down

0 comments on commit 36190a4

Please sign in to comment.