Compare commits

...

15 Commits

Author SHA1 Message Date
5043829132 0.0.8 2015-10-14 20:59:22 +02:00
09152c8f5f improved return objects 2015-10-14 20:59:01 +02:00
fd7352533f Merge pull request #3 from pushrocks/greenkeeper-beautylog-0.0.15
Update beautylog to version 0.0.15 🚀
2015-10-12 22:45:44 +02:00
4b977eee3b chore(package): update beautylog to version 0.0.15
http://greenkeeper.io/
2015-10-12 22:38:34 +02:00
bec0c4bbfa Merge pull request #2 from pushrocks/greenkeeper-beautylog-0.0.14
Update beautylog to version 0.0.14 🚀
2015-10-12 20:03:37 +02:00
686fa6c6f9 chore(package): update beautylog to version 0.0.14
http://greenkeeper.io/
2015-10-12 20:02:29 +02:00
400c5c6574 Merge pull request #1 from pushrocks/greenkeeper-beautylog-0.0.13
Update beautylog to version 0.0.13 🚀
2015-10-12 14:42:35 +02:00
80770612f5 chore(package): update beautylog to version 0.0.13
http://greenkeeper.io/
2015-10-12 13:15:41 +02:00
a65fcaffea disabled travis email 2015-10-08 00:50:10 +02:00
f80006310b 0.0.7 2015-10-08 00:49:15 +02:00
236cce7297 0.0.6 2015-10-07 01:16:28 +02:00
05595ac997 small update 2015-10-07 01:16:15 +02:00
ce1dde6d54 now handling CLI options 2015-10-07 01:07:38 +02:00
44b20b011c 0.0.5 2015-10-06 00:45:59 +02:00
b1dfe658c4 modified test 2015-10-06 00:45:52 +02:00
7 changed files with 199 additions and 21 deletions

View File

@ -17,3 +17,4 @@ deploy:
notifications:
slack:
secure: f5Uss0z9RPl/QcA/DroB8loyE93aOYI6bqCkrsiUscmZtlv/TVQtT4dxqGA6uvcG6iTQDBi3Ul88dQxWkRm4IqbhY35/iMaV2dHW4FVYMAh8GQMbsfL2sALCcufxD9blw47awv3iFcwhV1EeyesscjgL0JIjduk96v/7G/6QIO2838M1lzlgtj+kRUkim8qkaEs1je3gRrhMUIjLuAdscMXyUKYFMjWo9ACSjVUl30R/ZNemb18itIja6i92GotreBgcfEMczvy58ovDC7xdJUsY8LjMI01DwY+WPRnI0tAhsuI8moBwwcdM4e3bAjKjucQRjO33O5bMWRZ6QCiYd0DnCEFyCPQLJ4GSy/tkD00n8ijLHAOSV3AH1zNbdK1EAdSPQXDvlI36KJn/2hyQLoitGHVUPr76ujJWP82ypO2tgIp3XQU0dJVCxDuHnwJO2+hjdI+gCPqxNTpjeujHx3UdkTGNRjuuf9dlZ/D08fApjYxy2fxItTqo3QjP/nrqvBXUOPP8yPHpjIT4H2t5Pr4SJjBGI6X4qhKyFj6s9rA/Xu1rL+45zu1C3uC3z+u3T9UwrbzJ/cZM6r6UQvQmUvIfBNaMlg4I/diQCDIPL+Rhop2nylY3IcHmJnk2itn7kOqj1tohCpFEml5pRuSZy4udWywkdtyBAsHWFLF7oiQ=
email: false

View File

@ -1,4 +1,6 @@
/// <reference path="index.ts" />
/// <reference path="typings/tsd.d.ts" />
/// <reference path="./interfaces.ts" />
var path = require("path");
var beautylog = require("beautylog");
var cliff = require("cliff");
@ -10,13 +12,55 @@ 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.getOption = function (optionName) {
if (argv.hasOwnProperty(optionName)) {
return {
name: optionName,
specified: true,
value: argv[optionName] //we already know from the "if" above that the value is available.
};
}
return {
name: optionName,
specified: false,
value: 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}
* returns Directory of cwd
* @returns {{path: string}}
*/
smartcli.getCwd = function () {
return process.cwd();
return {
path: 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,10 +1,11 @@
{
"name": "smartcli",
"version": "0.0.4",
"version": "0.0.8",
"description": "nodejs wrapper for CLI related tasks",
"main": "index.js",
"scripts": {
"test": "(cd ts/compile && gulp)",
"devTest": "(npm test) && (node test.js --test true)",
"reinstall": "(rm -r node_modules && npm install)",
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
"startdev": "(git checkout master && git pull origin master)"
@ -25,7 +26,7 @@
},
"homepage": "https://github.com/pushrocks/smartcli",
"dependencies": {
"beautylog": "0.0.12",
"beautylog": "0.0.15",
"cliff": "^0.1.10",
"inquirer": "^0.10.1",
"yargs": "^3.26.0"

37
test.js
View File

@ -1,5 +1,31 @@
/// <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);
var getCwdTest = function () {
console.log('The current directory is: ' + smartcli.getCwd().path);
};
var checkCommandTest = function () {
if (smartcli.checkCommand('jazz')) {
bl.log('One of your commands is jazz');
}
else {
bl.log('None of your commands is jazz');
}
};
var getOptionTest = function () {
console.log('We now test for option --test');
console.log(smartcli.getOption('test'));
};
var checkOptionTest = function () {
};
var getAnswerTest = function () {
smartcli.getAnswer('How do you feel?', function (answer) {
console.log('The answer is: ' + answer);
@ -7,12 +33,13 @@ var getAnswerTest = 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);
getCwdTest();
});
};
var getCwdTest = function () {
console.log('The current directory is: ' + smartcli.getCwd());
};
//starting command tests
getCwdTest();
checkCommandTest();
getOptionTest();
//starting first interaction test (the other tests are then started via callbacks)
getAnswerTest();

View File

@ -1,4 +1,5 @@
/// <reference path="typings/tsd.d.ts" />
/// <reference path="./interfaces.ts" />
var path = require("path");
var beautylog = require("beautylog");
@ -14,14 +15,71 @@ smartcli.inquirer = inquirer;
smartcli.cliff = cliff;
smartcli.argv = argv;
/**
* returns the current working directory
* @returns {string}
*/
smartcli.getCwd = function () {
return process.cwd();
/* ------------------------------------------------------------------------------
*----------------------- 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.getOption = function(optionName:string):CliOption {
if (argv.hasOwnProperty(optionName)) {
return {
name:optionName,
specified: true,
value: argv[optionName] //we already know from the "if" above that the value is available.
};
}
return {
name:optionName,
specified: false,
value: false
}
};
smartcli.getOptions = function() {
var options = {};
for (var key in argv) {
if (key != "_") {
options['key'] = argv['key'];
}
}
return options;
};
/**
* returns Directory of cwd
* @returns {{path: string}}
*/
smartcli.getCwd = function():Directory {
return {
path: process.cwd()
}
};
/* ------------------------------------------------------------------------------
*----------------------- in program CLI interaction -----------------------------
*----------------------------------------------------------------------------- */
/**
* executes callback with answer to question as argument
* @param questionString the question you want to ask the user

11
ts/interfaces.ts Normal file
View File

@ -0,0 +1,11 @@
/// <reference path="index.ts" />
interface CliOption {
name: string;
specified:boolean;
value: any;
}
interface Directory {
path: string;
}

View File

@ -1,5 +1,38 @@
/// <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);
var getCwdTest = function(){
console.log('The current directory is: ' + smartcli.getCwd().path);
};
var checkCommandTest = function() {
if (smartcli.checkCommand('jazz')) {
bl.log('One of your commands is jazz');
} else {
bl.log('None of your commands is jazz');
}
};
var getOptionTest = function() {
console.log('We now test for option --test')
console.log(smartcli.getOption('test'));
}
var checkOptionTest = function() {
};
var getAnswerTest = function() {
smartcli.getAnswer('How do you feel?',function(answer){
@ -9,14 +42,17 @@ var getAnswerTest = 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);
getCwdTest();
});
};
var getCwdTest = function(){
console.log('The current directory is: ' + smartcli.getCwd());
};
//starting command tests
getCwdTest();
checkCommandTest();
getOptionTest();
//starting first interaction test (the other tests are then started via callbacks)
getAnswerTest();