now handling CLI options
This commit is contained in:
45
ts/index.ts
45
ts/index.ts
@@ -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
|
||||
|
18
ts/test.ts
18
ts/test.ts
@@ -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){
|
||||
|
Reference in New Issue
Block a user