mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Introduce silent mode to disable logging
This commit is contained in:
parent
2e1ee0dfa4
commit
9a78cafbfd
7 changed files with 142 additions and 4 deletions
|
|
@ -3,16 +3,27 @@ import chalk from "chalk";
|
|||
import ora from "ora";
|
||||
import { createInterface } from "readline";
|
||||
import { isCi } from "./environment.js";
|
||||
import { getLoggingLevel, LOGGING_SILENT } from "../config/settings.js";
|
||||
|
||||
function isSilentMode() {
|
||||
return getLoggingLevel() === LOGGING_SILENT;
|
||||
}
|
||||
|
||||
function emptyLine() {
|
||||
if (isSilentMode()) return;
|
||||
|
||||
writeInformation("");
|
||||
}
|
||||
|
||||
function writeInformation(message, ...optionalParams) {
|
||||
if (isSilentMode()) return;
|
||||
|
||||
console.log(message, ...optionalParams);
|
||||
}
|
||||
|
||||
function writeWarning(message, ...optionalParams) {
|
||||
if (isSilentMode()) return;
|
||||
|
||||
if (!isCi()) {
|
||||
message = chalk.yellow(message);
|
||||
}
|
||||
|
|
@ -26,7 +37,24 @@ function writeError(message, ...optionalParams) {
|
|||
console.error(message, ...optionalParams);
|
||||
}
|
||||
|
||||
function writeExitWithoutInstallingMaliciousPackages() {
|
||||
let message = "Safe-chain: Exiting without installing malicious packages.";
|
||||
if (!isCi()) {
|
||||
message = chalk.red(message);
|
||||
}
|
||||
console.error(message);
|
||||
}
|
||||
|
||||
function startProcess(message) {
|
||||
if (isSilentMode()) {
|
||||
return {
|
||||
succeed: () => {},
|
||||
fail: () => {},
|
||||
stop: () => {},
|
||||
setText: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
if (isCi()) {
|
||||
return {
|
||||
succeed: (message) => {
|
||||
|
|
@ -60,7 +88,7 @@ function startProcess(message) {
|
|||
}
|
||||
|
||||
async function confirm(config) {
|
||||
if (isCi()) {
|
||||
if (isCi() || isSilentMode()) {
|
||||
return Promise.resolve(config.default);
|
||||
}
|
||||
|
||||
|
|
@ -91,6 +119,7 @@ export const ui = {
|
|||
writeInformation,
|
||||
writeWarning,
|
||||
writeError,
|
||||
writeExitWithoutInstallingMaliciousPackages,
|
||||
emptyLine,
|
||||
startProcess,
|
||||
confirm,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue