alwaysai
Version:
The alwaysAI command-line interface (CLI)
32 lines • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runWithEchoAndProceedPrompt = void 0;
const alwayscli_1 = require("@alwaysai/alwayscli");
const chalk = require("chalk");
const logSymbols = require("log-symbols");
const confirm_prompt_component_1 = require("./confirm-prompt-component");
const echo_1 = require("../../util/echo");
async function runWithEchoAndProceedPrompt(func, args, props = {}) {
const { yes = false, functionName } = props;
const commandString = `${functionName !== null && functionName !== void 0 ? functionName : func.name} ${args.join(' ')}`;
(0, echo_1.echoCommandInvocation)(commandString);
const result = await func(...args);
let endOfCommandMessage = `End of "${commandString}"`;
if (typeof result !== 'undefined') {
endOfCommandMessage = `${endOfCommandMessage} (result=${result})`;
}
if (!yes) {
const confirmed = await (0, confirm_prompt_component_1.confirmPromptComponent)({
message: `${endOfCommandMessage}. Proceed?`
});
if (!confirmed) {
throw new alwayscli_1.CliTerseError('User elected not to proceed');
}
}
else {
(0, echo_1.echo)(`${logSymbols.success} ${chalk.bold(endOfCommandMessage)}`);
}
(0, echo_1.echo)();
}
exports.runWithEchoAndProceedPrompt = runWithEchoAndProceedPrompt;
//# sourceMappingURL=run-with-echo-and-proceed-prompt.js.map