program .on('command:*', function() { console.error(('Invalid command ' + program.args[0]).red); program.outputHelp(); });
program .arguments('<command>') .action((cmd) => { program.outputHelp() console.log() console.log(` ` + chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)) console.log() })
execute() { if ( !process.argv.slice(2).length || !/[arudl]/.test(process.argv.slice(2)) ) { program.outputHelp(); process.exit(); } }
program .command('*') .action(() => { console.log("Sorry, that's not a valid Clay command. Try one of these commands:\n"); program.outputHelp(); })
const printHelpAndExit = () => { commander.outputHelp(); process.exit(); }
async function main() { if (program.args.length === 0) { program.outputHelp(); process.exit(1); } let template = Handlebars.compile(templateData); let result = await templateXmlFiles(template, program.args); if (program.output) { fs.writeFileSync(program.output, result); } else { console.log(result); } return 0; }
function uploadAddressbook(file, options) { if(!options.name || !options.phoneCol || !options.country){ console.error('Error: incomplete command, see address upload -h for more information'); app.outputHelp(); return; } var book = fs.readFileSync(file); let b64 = new Buffer(book).toString('base64'); options.description = options.description ? options.description : options.name; api.send('media.import_file_from_base64_async', [b64, null]) .success((jobId) => { console.log(`Import job id: ${jobId}, ${options.name}`); return setTimeout(checkBookUploadStatus, 1000, jobId, options); }) .error(error); }
/** * Create simple sms campaign * @param {Object} campaignObject - campaign object * @param {Object} options - options to pass to campaign ( passed from commander ) */ function doSmsSimple(campaignObject, options) { if (!options.content) { console.error('[5] Error: incomplete command, see campaign create -h for more information'); app.outputHelp(); return; } campaignObject.name = options.title; campaignObject.ivr.text = options.content; campaignObject.addressbook.hash = options.addressbook; checkCampaignObject(campaignObject, (res) => { api.send('sendr/10/campaign.save', [campaignObject]) .success((campaign) => { console.log(`Campaign created ID: ${campaign.hash}`); }) .error(error); }); }
program .command('help') .description('show this help') .action(() => program.outputHelp());
function exitError(message) { program.outputHelp(); console.error(); console.error(message); process.exit(1); }
// Validates any random command fired in program.arguments('<command>').action(cmd => { program.outputHelp(); console.log(` ` + chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`)); console.log(); suggestCommands(cmd); });
/** * Create simple voice campaign * @param {Object} campaignObject - campaign object * @param {Object} options - options to pass to campaign ( passed from commander ) */ function doVoiceSimple(campaignObject, options) { if (!options.media) { console.error('[7] Error: incomplete command, see campaign create -h for more information'); app.outputHelp(); return; } campaignObject.name = options.title; campaignObject.ivr.broadcast = options.media.split(','); campaignObject.addressbook.hash = options.addressbook; campaignObject.ivr.voicemail_detect_method = 'AUTO'; checkCampaignObject(campaignObject, (res) => { api.send('sendr/10/campaign.save', [campaignObject]) .success((campaign) => { console.log(`Campaign created ID: ${campaign.hash}`); }) .error(error); }); }
commander.outputHelp(str=>str);
program .arguments("<command>") .action((command) => { console.log(`Command ${command} not found\n`); program.outputHelp(); suggestCommands(command); });
// output help information on unknown commands program .arguments('<command>') .action((cmd) => { program.outputHelp() console.log(` ` + chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)) console.log() })