Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable debug logging via CLI flag #6033

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading