Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
b1565dec3e | |||
f6969ecfd5 | |||
9bb85ca666 | |||
9442f738d9 | |||
5043829132 | |||
09152c8f5f | |||
fd7352533f | |||
4b977eee3b | |||
bec0c4bbfa | |||
686fa6c6f9 | |||
400c5c6574 | |||
80770612f5 | |||
a65fcaffea | |||
f80006310b | |||
236cce7297 | |||
05595ac997 | |||
ce1dde6d54 | |||
44b20b011c | |||
b1dfe658c4 | |||
28b9666133 |
@ -17,3 +17,4 @@ deploy:
|
|||||||
notifications:
|
notifications:
|
||||||
slack:
|
slack:
|
||||||
secure: f5Uss0z9RPl/QcA/DroB8loyE93aOYI6bqCkrsiUscmZtlv/TVQtT4dxqGA6uvcG6iTQDBi3Ul88dQxWkRm4IqbhY35/iMaV2dHW4FVYMAh8GQMbsfL2sALCcufxD9blw47awv3iFcwhV1EeyesscjgL0JIjduk96v/7G/6QIO2838M1lzlgtj+kRUkim8qkaEs1je3gRrhMUIjLuAdscMXyUKYFMjWo9ACSjVUl30R/ZNemb18itIja6i92GotreBgcfEMczvy58ovDC7xdJUsY8LjMI01DwY+WPRnI0tAhsuI8moBwwcdM4e3bAjKjucQRjO33O5bMWRZ6QCiYd0DnCEFyCPQLJ4GSy/tkD00n8ijLHAOSV3AH1zNbdK1EAdSPQXDvlI36KJn/2hyQLoitGHVUPr76ujJWP82ypO2tgIp3XQU0dJVCxDuHnwJO2+hjdI+gCPqxNTpjeujHx3UdkTGNRjuuf9dlZ/D08fApjYxy2fxItTqo3QjP/nrqvBXUOPP8yPHpjIT4H2t5Pr4SJjBGI6X4qhKyFj6s9rA/Xu1rL+45zu1C3uC3z+u3T9UwrbzJ/cZM6r6UQvQmUvIfBNaMlg4I/diQCDIPL+Rhop2nylY3IcHmJnk2itn7kOqj1tohCpFEml5pRuSZy4udWywkdtyBAsHWFLF7oiQ=
|
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
|
31
README.md
31
README.md
@ -1,16 +1,31 @@
|
|||||||
# smartcli
|
# smartcli
|
||||||
nodejs wrapper for CLI related tasks
|
nodejs wrapper for CLI related tasks
|
||||||
|
[](https://github.com/pushrocks/smartcli/commits/dev)
|
||||||
|
|
||||||
### Buildstatus/Dependencies
|
### Buildstatus/Dependencies
|
||||||
[](https://travis-ci.org/pushrocks/smartcli)
|
[](https://travis-ci.org/pushrocks/smartcli)
|
||||||
[](https://david-dm.org/pushrocks/smartcli#info=devDependencies)
|
[](https://david-dm.org/pushrocks/smartcli#info=devDependencies)
|
||||||
|
|
||||||
### Usage
|
### Install the package
|
||||||
This npm package comes with everything you need to start your own gulp plugin.
|
npm install smartcli
|
||||||
|
|
||||||
We recommend modifying the ts/index.ts file,
|
### Usage
|
||||||
then run `npm install` to install the dev dependencies
|
```js
|
||||||
and use `npm test` to compile the TypeScript file.
|
var smartcli = require("smartcli");
|
||||||
|
|
||||||
Cheers
|
//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
|
Phil from Lossless Digital
|
||||||
|
50
index.js
50
index.js
@ -1,4 +1,6 @@
|
|||||||
|
/// <reference path="index.ts" />
|
||||||
/// <reference path="typings/tsd.d.ts" />
|
/// <reference path="typings/tsd.d.ts" />
|
||||||
|
/// <reference path="./interfaces.ts" />
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var beautylog = require("beautylog");
|
var beautylog = require("beautylog");
|
||||||
var cliff = require("cliff");
|
var cliff = require("cliff");
|
||||||
@ -10,13 +12,55 @@ 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.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 Directory of cwd
|
||||||
* @returns {string}
|
* @returns {{path: string}}
|
||||||
*/
|
*/
|
||||||
smartcli.getCwd = function () {
|
smartcli.getCwd = function () {
|
||||||
return process.cwd();
|
return {
|
||||||
|
path: 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,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "smartcli",
|
"name": "smartcli",
|
||||||
"version": "0.0.3",
|
"version": "0.0.9",
|
||||||
"description": "nodejs wrapper for CLI related tasks",
|
"description": "nodejs wrapper for CLI related tasks",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(cd ts/compile && gulp)",
|
"test": "(cd ts/compile && gulp)",
|
||||||
|
"devTest": "(npm test) && (node test.js --test true)",
|
||||||
"reinstall": "(rm -r node_modules && npm install)",
|
"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)",
|
"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)"
|
"startdev": "(git checkout master && git pull origin master)"
|
||||||
@ -25,7 +26,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/smartcli",
|
"homepage": "https://github.com/pushrocks/smartcli",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "0.0.12",
|
"beautylog": "0.0.15",
|
||||||
"cliff": "^0.1.10",
|
"cliff": "^0.1.10",
|
||||||
"inquirer": "^0.10.1",
|
"inquirer": "^0.10.1",
|
||||||
"yargs": "^3.26.0"
|
"yargs": "^3.26.0"
|
||||||
|
37
test.js
37
test.js
@ -1,5 +1,31 @@
|
|||||||
/// <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);
|
||||||
|
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 () {
|
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,12 +33,13 @@ 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();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var getCwdTest = function () {
|
//starting command tests
|
||||||
console.log('The current directory is: ' + smartcli.getCwd());
|
getCwdTest();
|
||||||
};
|
checkCommandTest();
|
||||||
|
getOptionTest();
|
||||||
|
//starting first interaction test (the other tests are then started via callbacks)
|
||||||
getAnswerTest();
|
getAnswerTest();
|
||||||
|
70
ts/index.ts
70
ts/index.ts
@ -1,4 +1,5 @@
|
|||||||
/// <reference path="typings/tsd.d.ts" />
|
/// <reference path="typings/tsd.d.ts" />
|
||||||
|
/// <reference path="./interfaces.ts" />
|
||||||
|
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var beautylog = require("beautylog");
|
var beautylog = require("beautylog");
|
||||||
@ -14,14 +15,71 @@ smartcli.inquirer = inquirer;
|
|||||||
smartcli.cliff = cliff;
|
smartcli.cliff = cliff;
|
||||||
smartcli.argv = argv;
|
smartcli.argv = argv;
|
||||||
|
|
||||||
/**
|
/* ------------------------------------------------------------------------------
|
||||||
* returns the current working directory
|
*----------------------- initial call CLI args -----------------------------
|
||||||
* @returns {string}
|
*----------------------------------------------------------------------------- */
|
||||||
*/
|
|
||||||
smartcli.getCwd = function () {
|
// commands
|
||||||
return process.cwd();
|
|
||||||
|
|
||||||
|
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
|
* 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
|
||||||
|
11
ts/interfaces.ts
Normal file
11
ts/interfaces.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/// <reference path="index.ts" />
|
||||||
|
interface CliOption {
|
||||||
|
name: string;
|
||||||
|
specified:boolean;
|
||||||
|
value: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Directory {
|
||||||
|
path: string;
|
||||||
|
}
|
||||||
|
|
46
ts/test.ts
46
ts/test.ts
@ -1,5 +1,38 @@
|
|||||||
/// <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);
|
||||||
|
|
||||||
|
|
||||||
|
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() {
|
var getAnswerTest = function() {
|
||||||
smartcli.getAnswer('How do you feel?',function(answer){
|
smartcli.getAnswer('How do you feel?',function(answer){
|
||||||
@ -9,14 +42,17 @@ 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();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
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();
|
getAnswerTest();
|
Reference in New Issue
Block a user