Skip to content

Commit

Permalink
feat: only show --verbose flag if there are hidden logs (#1925)
Browse files Browse the repository at this point in the history
We currently always show details about this flag. The change will only
log this message if there are debug log messages an the user is not in
--verbose mode.
  • Loading branch information
blakef authored and thymikee committed May 16, 2023
1 parent 58cc6fb commit a00a896
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/cli-tools/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const SEPARATOR = ', ';

let verbose = false;
let disabled = false;
let hidden = false;

const formatMessages = (messages: Array<string>) =>
chalk.reset(messages.join(SEPARATOR));
Expand Down Expand Up @@ -35,6 +36,8 @@ const error = (...messages: Array<string>) => {
const debug = (...messages: Array<string>) => {
if (verbose && !disabled) {
console.log(`${chalk.gray.bold('debug')} ${formatMessages(messages)}`);
} else {
hidden = true;
}
};

Expand All @@ -58,6 +61,8 @@ const enable = () => {
disabled = false;
};

const hasDebugMessages = () => hidden;

export default {
success,
info,
Expand All @@ -67,6 +72,7 @@ export default {
log,
setVerbose,
isVerbose,
hasDebugMessages,
disable,
enable,
};
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const handleError = (err: Error) => {
if (err.stack) {
logger.log(err.stack);
}
if (!program.opts().verbose) {
if (!program.opts().verbose && logger.hasDebugMessages()) {
logger.info(
chalk.dim(
`Run CLI with ${chalk.reset('--verbose')} ${chalk.dim(
Expand Down

0 comments on commit a00a896

Please sign in to comment.