// aux functions function printHelpMessage() { console.log('[ERROR] incorrect input'); commander.help(); }
program .version(pckg.version) .usage('[options]') // HACK: Commander only registers `-V` .option('-v, --version', 'output the version number') .on('option:version', () => { return console.log(program._version) }) .action(() => { program.help() })
function runProgram() { program.parse(process.argv); if (!program.args.length) program.help(); }
commander.help((help)=>{ return boxen(`\n${chalk.bold.whiteBright('Cogear.JS – modern static websites generator.')}\n\nv${cogear.package.version}\n\n(help)\n\n${chalk.bold.whiteBright('https://cogearjs.org')}`, { padding: {top: 1, bottom: 1,left: 8,right: 8}, margin: 0, dimBorder: true, align: 'center', borderStyle: 'single-double', borderColor: 'magenta' }) + ` ${chalk.white('Runs in development mode by default (without [command]).')} ${help} More info: ${chalk.bold.whiteBright('https://cogearjs.org')} `; });
program .command("*", undefined, {noHelp: true}) .action(() => program.help());
program.help();
// // // function sampleMain(tjs, options) { var temp = program.args[0]; if (!temp) { program.help(); } tjs.setTemps(options, f2c(temp), null, function (err, result) { if (result.result) { var str = (temp + " Deg.F").green; console.log("\nTemperature successfully set to: " + str); } else { console.log(result.reason.red); } }); }
// // // function sampleMain(tjs, options) { var subject = program.args[0]; var text = program.args[1]; var locale = program.args[1] || "en-US"; if (!subject || !text) { console.log("\n"); program.help(); } tjs.navigationRequest(options, subject, text, locale, function (err, result) { if (err) { console.error("\nnavigationRequest command: " + "Failed!".red + "\n"); } else { if (result.result) { console.log("\nnavigationRequest command: " + "Succeeded".green + "\n"); } else { console.log("\nnavigationRequest command: " + "Failed!".red + "\n"); console.log("Reason: " + result.reason.red + "\n"); } } }); }
// // // function sampleMain(tjs, options) { var which = program.args[0]; if (!which) { program.help(); } if (which.toUpperCase() == "FRUNK") { which = tjs.FRUNK; } else { which = tjs.TRUNK; } tjs.openTrunk(options, which, function (err, response) { if (response.result) { var str = which.toUpperCase(); console.log("\n" + str.bgGreen + " actuated."); } else { console.error(response.reason.red); } }); }
// Failsafe that shows the help dialogue if the command is not recognized (`$ react xyz`) program.on('*', function(opt) { program.help(); });
// // // function sampleMain(tjs, options) { var mode = program.args[0]; var pin = program.args[1]; if (!mode || !pin) { program.help(); } if (mode.toUpperCase() == "ON") { mode = true; } else { mode = false; } tjs.setValetMode(options, mode, pin, function (err, response) { if (response.result) { var str = mode ? "ENABLED" : "DISABLED"; console.log("\nValet mode: " + str.bgGreen); } else { console.error(response.reason.red); } }); }
// // // function sampleMain(tjs, options) { var state = program.args[0]; if (!state) { program.help(); } if (state.toLowerCase() == "closed") { state = "close"; } if (state.toLowerCase() != "close" && state.toLowerCase() != "vent") { program.help(); } tjs.sunRoofControl(options, state, function (err, result) { if (result && result.result) { console.log("\nSunroof successfully moved to : " + state.bgGreen); } else { console.log(err); console.log("Invalid option".red); } }); }
// // // function sampleMain(tjs, options) { var speed = program.args[0]; if (!speed) { program.help(); } tjs.speedLimitSetLimit(options, speed, function (err, result) { if (result.result) { var str = (speed + " MPH").green; console.log("\nSpeed limit successfully set to: " + str); } else { console.log(result.reason.red); } }); }
// // // function sampleMain(tjs, options) { var password = program.args[0] if (!password) { program.help(); } tjs.remoteStart(options, password, function (err, result) { if (err) { console.log(err); return; } if (result) { console.log("\nCommand completed successfully!\n"); console.log("You may now begin driving.\n"); console.log("You must start driving within " + "2 minutes".bold.green + " or Remote Start will expire."); } else { console.log(result.reason.red); } }); }
// // // function sampleMain(tjs, options) { var offset = program.args[0]; if (!offset) { program.help(); } tjs.scheduleSoftwareUpdate(options, offset, function (err, result) { if (err) { console.error("\nscheduleSoftwareUpdate command: " + "Failed!".red); } else { if (result.result) { console.log("\nscheduleSoftwareUpdate command: " + "Succeeded".green); } else { console.log("\nscheduleSoftwareUpdate command: " + "Failed!".red); console.log("Reason: " + result.reason.red); } } }); }