Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
f80006310b | |||
236cce7297 | |||
05595ac997 | |||
ce1dde6d54 | |||
44b20b011c | |||
b1dfe658c4 |
32
index.js
32
index.js
@ -10,6 +10,35 @@ var smartcli = {};
|
|||||||
smartcli.inquirer = inquirer;
|
smartcli.inquirer = inquirer;
|
||||||
smartcli.cliff = cliff;
|
smartcli.cliff = cliff;
|
||||||
smartcli.argv = argv;
|
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 the current working directory
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
@ -17,6 +46,9 @@ smartcli.argv = argv;
|
|||||||
smartcli.getCwd = function () {
|
smartcli.getCwd = function () {
|
||||||
return process.cwd();
|
return process.cwd();
|
||||||
};
|
};
|
||||||
|
/* ------------------------------------------------------------------------------
|
||||||
|
*----------------------- in program CLI interaction -----------------------------
|
||||||
|
*----------------------------------------------------------------------------- */
|
||||||
/**
|
/**
|
||||||
* executes callback with answer to question as argument
|
* executes callback with answer to question as argument
|
||||||
* @param questionString the question you want to ask the user
|
* @param questionString the question you want to ask the user
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "smartcli",
|
"name": "smartcli",
|
||||||
"version": "0.0.4",
|
"version": "0.0.7",
|
||||||
"description": "nodejs wrapper for CLI related tasks",
|
"description": "nodejs wrapper for CLI related tasks",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
17
test.js
17
test.js
@ -1,5 +1,20 @@
|
|||||||
/// <reference path="typings/tsd.d.ts" />
|
/// <reference path="typings/tsd.d.ts" />
|
||||||
var smartcli = require("./index.js");
|
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 () {
|
var getAnswerTest = function () {
|
||||||
smartcli.getAnswer('How do you feel?', function (answer) {
|
smartcli.getAnswer('How do you feel?', function (answer) {
|
||||||
console.log('The answer is: ' + answer);
|
console.log('The answer is: ' + answer);
|
||||||
@ -7,7 +22,7 @@ var getAnswerTest = function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
var getChoiceTest = function () {
|
var getChoiceTest = function () {
|
||||||
smartcli.getChoice('What to you like best?', ['Cars', 'Planes', 'Boats'], function (answer) {
|
smartcli.getChoice('What music do you like to hear?', ['Jazz', 'Blues', 'Classical'], function (answer) {
|
||||||
console.log('The answer is: ' + answer);
|
console.log('The answer is: ' + answer);
|
||||||
getCwdTest();
|
getCwdTest();
|
||||||
});
|
});
|
||||||
|
52
ts/index.ts
52
ts/index.ts
@ -14,6 +14,50 @@ smartcli.inquirer = inquirer;
|
|||||||
smartcli.cliff = cliff;
|
smartcli.cliff = cliff;
|
||||||
smartcli.argv = argv;
|
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.getOptionValue = function(optionParam:string):any {
|
||||||
|
if (smartcli.checkOption(optionParam)) {
|
||||||
|
return argv[optionParam]
|
||||||
|
}
|
||||||
|
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 the current working directory
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
@ -22,6 +66,14 @@ smartcli.getCwd = function () {
|
|||||||
return process.cwd();
|
return process.cwd();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------
|
||||||
|
*----------------------- in program CLI interaction -----------------------------
|
||||||
|
*----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* executes callback with answer to question as argument
|
* executes callback with answer to question as argument
|
||||||
* @param questionString the question you want to ask the user
|
* @param questionString the question you want to ask the user
|
||||||
|
20
ts/test.ts
20
ts/test.ts
@ -1,5 +1,23 @@
|
|||||||
/// <reference path="typings/tsd.d.ts" />
|
/// <reference path="typings/tsd.d.ts" />
|
||||||
var smartcli = require("./index.js");
|
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() {
|
var getAnswerTest = function() {
|
||||||
smartcli.getAnswer('How do you feel?',function(answer){
|
smartcli.getAnswer('How do you feel?',function(answer){
|
||||||
@ -9,7 +27,7 @@ var getAnswerTest = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var getChoiceTest = function() {
|
var getChoiceTest = function() {
|
||||||
smartcli.getChoice('What to you like best?',['Cars','Planes','Boats'],function(answer){
|
smartcli.getChoice('What music do you like to hear?',['Jazz','Blues','Classical'],function(answer){
|
||||||
console.log('The answer is: ' + answer);
|
console.log('The answer is: ' + answer);
|
||||||
getCwdTest();
|
getCwdTest();
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user