now handling CLI options

This commit is contained in:
Phil Kunz 2015-10-07 01:07:38 +02:00
parent 44b20b011c
commit ce1dde6d54
4 changed files with 110 additions and 0 deletions

View File

@ -10,6 +10,35 @@ var smartcli = {};
smartcli.inquirer = inquirer;
smartcli.cliff = cliff;
smartcli.argv = argv;
/* ------------------------------------------------------------------------------
*----------------------- initial call CLI args -----------------------------
*----------------------------------------------------------------------------- */
// commands
smartcli.checkCommand = function (commandString) {
if (argv._.indexOf(commandString) != -1) {
return true;
}
return false;
};
smartcli.getCommands = function () {
return argv._;
};
// options
smartcli.checkOption = function (optionParam) {
if (argv.hasOwnProperty(optionParam)) {
return true;
}
return false;
};
smartcli.getOptions = function () {
var options = {};
for (var key in argv) {
if (key != "_") {
options['key'] = argv['key'];
}
}
return options;
};
/**
* returns the current working directory
* @returns {string}
@ -17,6 +46,9 @@ smartcli.argv = argv;
smartcli.getCwd = function () {
return process.cwd();
};
/* ------------------------------------------------------------------------------
*----------------------- in program CLI interaction -----------------------------
*----------------------------------------------------------------------------- */
/**
* executes callback with answer to question as argument
* @param questionString the question you want to ask the user

15
test.js
View File

@ -1,5 +1,20 @@
/// <reference path="typings/tsd.d.ts" />
var smartcli = require("./index.js");
var bl = require("beautylog");
bl.log('now starting Test');
bl.log('starting with initial CLI commands and options');
var commandsString = 'You specified the following commands:';
var commands = smartcli.getCommands();
for (var key in commands) {
commandsString = commandsString + ' ' + commands[key];
}
bl.log(commandsString);
if (smartcli.checkCommand('jazz')) {
bl.log('One of your commands is jazz');
}
else {
bl.log('None of your commands is jazz');
}
var getAnswerTest = function () {
smartcli.getAnswer('How do you feel?', function (answer) {
console.log('The answer is: ' + answer);

View File

@ -14,6 +14,43 @@ smartcli.inquirer = inquirer;
smartcli.cliff = cliff;
smartcli.argv = argv;
/* ------------------------------------------------------------------------------
*----------------------- initial call CLI args -----------------------------
*----------------------------------------------------------------------------- */
// commands
smartcli.checkCommand = function(commandString:string):boolean {
if (argv._.indexOf(commandString) != -1) {
return true
}
return false;
};
smartcli.getCommands = function ():string[] {
return argv._;
};
// options
smartcli.checkOption = function(optionParam:string):boolean {
if (argv.hasOwnProperty(optionParam)) {
return true;
}
return false
}
smartcli.getOptions = function() {
var options = {};
for (var key in argv) {
if (key != "_") {
options['key'] = argv['key'];
}
}
return options;
};
/**
* returns the current working directory
* @returns {string}
@ -22,6 +59,14 @@ smartcli.getCwd = function () {
return process.cwd();
};
/* ------------------------------------------------------------------------------
*----------------------- in program CLI interaction -----------------------------
*----------------------------------------------------------------------------- */
/**
* executes callback with answer to question as argument
* @param questionString the question you want to ask the user

View File

@ -1,5 +1,23 @@
/// <reference path="typings/tsd.d.ts" />
var smartcli = require("./index.js");
var bl = require("beautylog");
bl.log('now starting Test');
bl.log('starting with initial CLI commands and options');
var commandsString:string = 'You specified the following commands:';
var commands = smartcli.getCommands();
for (var key in commands) {
commandsString = commandsString + ' ' + commands[key];
}
bl.log(commandsString);
if (smartcli.checkCommand('jazz')) {
bl.log('One of your commands is jazz');
} else {
bl.log('None of your commands is jazz');
}
var getAnswerTest = function() {
smartcli.getAnswer('How do you feel?',function(answer){