Compare commits

...

14 Commits

Author SHA1 Message Date
b1565dec3e 0.0.9 2015-10-14 21:14:29 +02:00
f6969ecfd5 improved readme 2015-10-14 21:14:20 +02:00
9bb85ca666 updated readme 2015-10-14 21:09:26 +02:00
9442f738d9 added devStatus badge 2015-10-14 21:01:39 +02:00
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
8 changed files with 125 additions and 49 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,16 +1,31 @@
# smartcli
nodejs wrapper for CLI related tasks
[![Dev Status](https://img.shields.io/badge/DevStatus-Active-green.svg)](https://github.com/pushrocks/smartcli/commits/dev)
### Buildstatus/Dependencies
[![Build Status](https://travis-ci.org/pushrocks/smartcli.svg?branch=master)](https://travis-ci.org/pushrocks/smartcli)
[![devDependency Status](https://david-dm.org/pushrocks/smartcli/dev-status.svg)](https://david-dm.org/pushrocks/smartcli#info=devDependencies)
### Usage
This npm package comes with everything you need to start your own gulp plugin.
### Install the package
npm install smartcli
We recommend modifying the ts/index.ts file,
then run `npm install` to install the dev dependencies
and use `npm test` to compile the TypeScript file.
### Usage
```js
var smartcli = require("smartcli");
//returns true for terminal command "node myjs.js jazz"
smartcli.checkCommand('jazz');
/**
* returns an object for terminal command "node myjs.js --myoption something like so
* {
* name: 'myoption',
* specified: true,
* value: 'something'
* }
*/
smartcli.getOption('myoption');
``
Cheers
Phil from Lossless Digital

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");
@ -24,11 +26,19 @@ smartcli.getCommands = function () {
return argv._;
};
// options
smartcli.checkOption = function (optionParam) {
if (argv.hasOwnProperty(optionParam)) {
return true;
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 false;
return {
name: optionName,
specified: false,
value: false
};
};
smartcli.getOptions = function () {
var options = {};
@ -40,11 +50,13 @@ smartcli.getOptions = function () {
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 -----------------------------

View File

@ -1,10 +1,11 @@
{
"name": "smartcli",
"version": "0.0.6",
"version": "0.0.9",
"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"

20
test.js
View File

@ -9,12 +9,23 @@ 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);
@ -24,10 +35,11 @@ var getAnswerTest = function () {
var getChoiceTest = function () {
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");
@ -34,20 +35,23 @@ smartcli.getCommands = function ():string[] {
// options
smartcli.checkOption = function(optionParam:string):boolean {
if (argv.hasOwnProperty(optionParam)) {
return true;
}
return false
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.
};
smartcli.getOptionValue = function(optionParam:string):any {
if (smartcli.checkOption(optionParam)) {
return argv[optionParam]
}
return false;
return {
name:optionName,
specified: false,
value: false
}
};
smartcli.getOptions = function() {
var options = {};
for (var key in argv) {
@ -59,11 +63,13 @@ smartcli.getOptions = function() {
};
/**
* returns the current working directory
* @returns {string}
* returns Directory of cwd
* @returns {{path: string}}
*/
smartcli.getCwd = function () {
return process.cwd();
smartcli.getCwd = function():Directory {
return {
path: process.cwd()
}
};

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

@ -12,12 +12,27 @@ for (var key in commands) {
}
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){
@ -29,12 +44,15 @@ var getAnswerTest = function() {
var getChoiceTest = function() {
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();