Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix: make the quiet flag actually work (#1587)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurdoch authored Nov 17, 2021
1 parent a244df2 commit 0422e58
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 10 deletions.
117 changes: 117 additions & 0 deletions src/chains/ethereum/options/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/chains/ethereum/options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@types/seedrandom": "3.0.1",
"cross-env": "7.0.3",
"mocha": "9.1.3",
"sinon": "12.0.1",
"ts-node": "9.1.1",
"ttypescript": "1.5.12",
"typescript": "4.1.3"
Expand Down
21 changes: 11 additions & 10 deletions src/chains/ethereum/options/src/logging-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export type LoggingConfig = {
};
};

const logger: Logger = { log: console.log };

export const LoggingOptions: Definitions<LoggingConfig> = {
debug: {
normalize,
Expand All @@ -87,12 +85,22 @@ export const LoggingOptions: Definitions<LoggingConfig> = {
legacyName: "debug",
cliType: "boolean"
},
quiet: {
normalize,
cliDescription: "Set to `true` to disable logging.",
default: () => false,
cliAliases: ["q", "quiet"],
cliType: "boolean"
},
logger: {
normalize,
cliDescription:
"An object, like `console`, that implements a `log` function.",
disableInCLI: true,
default: () => logger,
// disable the default logger if `quiet` is `true`
default: config => ({
log: config.quiet ? () => {} : console.log
}),
legacyName: "logger"
},
verbose: {
Expand All @@ -102,12 +110,5 @@ export const LoggingOptions: Definitions<LoggingConfig> = {
legacyName: "verbose",
cliAliases: ["v", "verbose"],
cliType: "boolean"
},
quiet: {
normalize,
cliDescription: "Set to `true` to disable logging.",
default: () => false,
cliAliases: ["q", "quiet"],
cliType: "boolean"
}
};
25 changes: 25 additions & 0 deletions src/chains/ethereum/options/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
import assert from "assert";
import { EthereumDefaults, EthereumOptionsConfig } from "../src";
import sinon from "sinon";

describe("EthereumOptionsConfig", () => {
describe("options", () => {
let spy: any;
beforeEach(() => {
spy = sinon.spy(console, "log");
});
afterEach(() => {
spy.restore();
});
it("logs via console.log by default", () => {
const message = "message";
const options = EthereumOptionsConfig.normalize({});
options.logging.logger.log(message);
assert.strictEqual(spy.withArgs(message).callCount, 1);
});

it("disables the logger when the quiet flag is used", () => {
const message = "message";
const options = EthereumOptionsConfig.normalize({
logging: { quiet: true }
});
options.logging.logger.log(message);
assert.strictEqual(spy.withArgs(message).callCount, 0);
});
});
describe(".normalize", () => {
it("returns an options object with all default namespaces", () => {
const options = EthereumOptionsConfig.normalize({});
Expand Down

0 comments on commit 0422e58

Please # to comment.