Add -y/--yes to auto-confirm prompts; verbose keeps showing command output
This commit is contained in:
11
src/index.ts
11
src/index.ts
@@ -20,6 +20,7 @@ dotenv.config({ quiet: true });
|
|||||||
|
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
let globalVerbose = false;
|
let globalVerbose = false;
|
||||||
|
let globalYes = false;
|
||||||
|
|
||||||
function setVerbose(v: boolean) {
|
function setVerbose(v: boolean) {
|
||||||
globalVerbose = v;
|
globalVerbose = v;
|
||||||
@@ -29,12 +30,17 @@ function logVerbose(message: string) {
|
|||||||
if (globalVerbose) console.log(chalk.gray(message));
|
if (globalVerbose) console.log(chalk.gray(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setYes(v: boolean) {
|
||||||
|
globalYes = v;
|
||||||
|
}
|
||||||
|
|
||||||
type AuthMode =
|
type AuthMode =
|
||||||
| { accountSid: string; authToken: string }
|
| { accountSid: string; authToken: string }
|
||||||
| { accountSid: string; apiKey: string; apiSecret: string };
|
| { accountSid: string; apiKey: string; apiSecret: string };
|
||||||
|
|
||||||
type GlobalOptions = {
|
type GlobalOptions = {
|
||||||
verbose: boolean;
|
verbose: boolean;
|
||||||
|
yes?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type EnvConfig = {
|
type EnvConfig = {
|
||||||
@@ -120,6 +126,7 @@ async function ensureBinary(name: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function promptYesNo(question: string, defaultYes = false): Promise<boolean> {
|
async function promptYesNo(question: string, defaultYes = false): Promise<boolean> {
|
||||||
|
if (globalYes) return true;
|
||||||
const rl = readline.createInterface({ input, output });
|
const rl = readline.createInterface({ input, output });
|
||||||
const suffix = defaultYes ? ' [Y/n] ' : ' [y/N] ';
|
const suffix = defaultYes ? ' [Y/n] ' : ' [y/N] ';
|
||||||
const answer = (await rl.question(`${question}${suffix}`)).trim().toLowerCase();
|
const answer = (await rl.question(`${question}${suffix}`)).trim().toLowerCase();
|
||||||
@@ -593,6 +600,7 @@ program
|
|||||||
.option('-r, --reply <text>', 'Optional auto-reply text')
|
.option('-r, --reply <text>', 'Optional auto-reply text')
|
||||||
.option('--path <path>', 'Webhook path', '/webhook/whatsapp')
|
.option('--path <path>', 'Webhook path', '/webhook/whatsapp')
|
||||||
.option('--verbose', 'Log inbound and auto-replies', false)
|
.option('--verbose', 'Log inbound and auto-replies', false)
|
||||||
|
.option('-y, --yes', 'Auto-confirm prompts when possible', false)
|
||||||
.addHelpText(
|
.addHelpText(
|
||||||
'after',
|
'after',
|
||||||
`
|
`
|
||||||
@@ -607,6 +615,7 @@ With Tailscale:
|
|||||||
)
|
)
|
||||||
.action(async (opts) => {
|
.action(async (opts) => {
|
||||||
setVerbose(Boolean(opts.verbose));
|
setVerbose(Boolean(opts.verbose));
|
||||||
|
setYes(Boolean(opts.yes));
|
||||||
const port = Number.parseInt(opts.port, 10);
|
const port = Number.parseInt(opts.port, 10);
|
||||||
if (Number.isNaN(port) || port <= 0 || port >= 65536) {
|
if (Number.isNaN(port) || port <= 0 || port >= 65536) {
|
||||||
console.error('Port must be between 1 and 65535');
|
console.error('Port must be between 1 and 65535');
|
||||||
@@ -621,8 +630,10 @@ program
|
|||||||
.option('-p, --port <port>', 'Port to listen on', '42873')
|
.option('-p, --port <port>', 'Port to listen on', '42873')
|
||||||
.option('--path <path>', 'Webhook path', '/webhook/whatsapp')
|
.option('--path <path>', 'Webhook path', '/webhook/whatsapp')
|
||||||
.option('--verbose', 'Verbose logging during setup/webhook', false)
|
.option('--verbose', 'Verbose logging during setup/webhook', false)
|
||||||
|
.option('-y, --yes', 'Auto-confirm prompts when possible', false)
|
||||||
.action(async (opts) => {
|
.action(async (opts) => {
|
||||||
setVerbose(Boolean(opts.verbose));
|
setVerbose(Boolean(opts.verbose));
|
||||||
|
setYes(Boolean(opts.yes));
|
||||||
const port = Number.parseInt(opts.port, 10);
|
const port = Number.parseInt(opts.port, 10);
|
||||||
if (Number.isNaN(port) || port <= 0 || port >= 65536) {
|
if (Number.isNaN(port) || port <= 0 || port >= 65536) {
|
||||||
console.error('Port must be between 1 and 65535');
|
console.error('Port must be between 1 and 65535');
|
||||||
|
|||||||
Reference in New Issue
Block a user