mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Merge branch 'main' into verbose-logging
This commit is contained in:
commit
0b393eeb5f
10 changed files with 288 additions and 160 deletions
|
|
@ -1,18 +1,28 @@
|
|||
// oxlint-disable no-console
|
||||
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,11 +36,29 @@ 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 writeVerboseInformation(message, ...optionalParams) {
|
||||
// TODO: Correctly implement verbose logging
|
||||
writeInformation(message, ...optionalParams);
|
||||
}
|
||||
|
||||
function startProcess(message) {
|
||||
if (isSilentMode()) {
|
||||
return {
|
||||
succeed: () => {},
|
||||
fail: () => {},
|
||||
stop: () => {},
|
||||
setText: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
if (isCi()) {
|
||||
return {
|
||||
succeed: (message) => {
|
||||
|
|
@ -63,40 +91,12 @@ function startProcess(message) {
|
|||
}
|
||||
}
|
||||
|
||||
async function confirm(config) {
|
||||
if (isCi()) {
|
||||
return Promise.resolve(config.default);
|
||||
}
|
||||
|
||||
const rl = createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const defaultText = config.default ? " (Y/n)" : " (y/N)";
|
||||
rl.question(`${config.message}${defaultText} `, (answer) => {
|
||||
rl.close();
|
||||
|
||||
const normalizedAnswer = answer.trim().toLowerCase();
|
||||
|
||||
if (normalizedAnswer === "y" || normalizedAnswer === "yes") {
|
||||
resolve(true);
|
||||
} else if (normalizedAnswer === "n" || normalizedAnswer === "no") {
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(config.default);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const ui = {
|
||||
writeInformation,
|
||||
writeVerboseInformation,
|
||||
writeWarning,
|
||||
writeError,
|
||||
writeExitWithoutInstallingMaliciousPackages,
|
||||
emptyLine,
|
||||
startProcess,
|
||||
confirm,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue