Compare commits

...

61 Commits

Author SHA1 Message Date
c6db092062 2.0.0 2016-12-18 20:53:53 +01:00
857d31dcb2 introduce triggers 2016-12-18 20:53:50 +01:00
e257a38688 1.0.16 2016-12-18 01:36:24 +01:00
19a5082381 added .triggerCommandByName 2016-12-18 01:36:19 +01:00
00f5539e6b improve README 2016-11-19 17:48:56 +01:00
cacb0221f1 IMprove README 2016-11-19 17:48:07 +01:00
b98b90163d 1.0.15 2016-11-19 17:41:16 +01:00
daa6312aea Update Metadata 2016-11-19 17:41:11 +01:00
7f2dab091f 1.0.14 2016-11-19 15:02:29 +01:00
dd293875c4 improve README 2016-11-19 15:02:24 +01:00
120eca42ac 1.0.13 2016-11-19 13:43:33 +01:00
fc289616f6 1.0.12 2016-11-19 13:43:10 +01:00
e7c1c1c45b cleanup 2016-11-19 13:43:06 +01:00
f33c759fa8 improve README 2016-10-15 02:12:10 +02:00
1185df362b update test file 2016-10-15 01:06:36 +02:00
36de8e11f0 1.0.11 2016-10-15 01:01:25 +02:00
74ffb3aa87 update deps 2016-10-15 01:01:22 +02:00
96a6d01720 1.0.10 2016-10-15 00:56:05 +02:00
7833bd0be8 implement standardJS 2016-10-15 00:56:02 +02:00
7ca18c4a46 1.0.9 2016-09-04 17:50:36 +02:00
b98e2a1a62 improve typings 2016-09-04 17:50:10 +02:00
e102203422 1.0.8 2016-09-04 17:36:19 +02:00
92a37cf29b fix ci 2016-09-04 17:36:07 +02:00
8408d1f3b5 1.0.7 2016-09-04 17:34:34 +02:00
d88e05466b fix base image 2016-09-04 17:34:29 +02:00
3a789d052c 1.0.6 2016-09-04 17:32:31 +02:00
d76d829e46 add page stage 2016-09-04 17:32:26 +02:00
f8157ab8aa improve typings and docs 2016-09-04 17:32:12 +02:00
5c67015779 update smartcli 2016-09-04 17:23:29 +02:00
b67e3c0de1 Add new file 2016-08-28 23:00:00 +00:00
c7a647d4ef start interaction module 2016-08-26 11:52:09 +02:00
9e5fb7a13a 1.0.5 2016-08-26 09:21:53 +02:00
c115d222c0 improve intellisense 2016-08-26 09:21:42 +02:00
643514c64a 1.0.4 2016-06-22 11:55:26 +02:00
19498f7b11 compile fix 2016-06-22 11:55:23 +02:00
3afadd9045 1.0.3 2016-06-22 11:54:19 +02:00
0889423a24 fix 2016-06-22 11:54:12 +02:00
86b4cf4cc3 add getCommandPromise 2016-06-22 01:21:09 +02:00
4cb4eabef4 update deps and transition from npmts to npmts-g 2016-06-22 01:18:04 +02:00
bad0971f1c 1.0.2 2016-06-16 02:58:49 +02:00
016f03bd8a standard tasks now returns argv 2016-06-16 02:58:45 +02:00
63a9da11be some cosmetics 2016-06-13 12:57:24 +02:00
ab18c75b28 introduce new classes 2016-06-13 12:56:42 +02:00
088d4ef11b 1.0.1 2016-06-10 04:32:14 +02:00
5ee866d9c6 fix version return 2016-06-10 04:32:11 +02:00
d65061aaaa return argv to command 2016-06-10 04:21:03 +02:00
506bb0cdaf 1.0.0 2016-06-10 04:13:30 +02:00
834a6c2953 first version with basic funtionality 2016-06-10 04:13:23 +02:00
e1c2de8a40 remove bulk and add some features to Smartcli class 2016-06-10 03:48:01 +02:00
9e76f2afb1 Start restructuring to use a smarter Smartcli class that handles command evaluation for you 2016-06-10 03:10:21 +02:00
cf78839e12 update dependencies 2016-06-10 02:27:04 +02:00
8733a601b4 compile 2016-06-09 14:03:18 +02:00
fdd1761333 add gitlab ci 2016-06-09 14:02:21 +02:00
542c77069f start smartcli class 2016-06-09 14:01:06 +02:00
96d82c3a20 update dependencies 2016-05-23 04:09:06 +02:00
ab8ce876a3 add class smartcli 2016-05-23 03:17:19 +02:00
de4d3bcf3a Update README 2016-05-12 03:33:23 +02:00
75ab5552e1 include commander and update README 2016-05-12 03:27:45 +02:00
eb3d9d722f fixed type issue 2016-05-10 17:21:30 -07:00
c32f41cc23 fixed test issue 2016-05-10 17:11:40 -07:00
cf03c6681b update deps 2016-05-10 03:18:40 +02:00
33 changed files with 682 additions and 939 deletions

4
.gitignore vendored
View File

@ -1,8 +1,6 @@
node_modules/ node_modules/
.settings/
.idea/
coverage/ coverage/
docs/ pages/
ts/*.js ts/*.js

50
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,50 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
- page
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
script:
- npmci publish
only:
- tags
tags:
- docker
pages:
image: hosttoday/ht-docker-node:npmpage
stage: page
script:
- npmci test stable
- npmci command npmpage --host gitlab
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,17 +0,0 @@
language: node_js
node_js:
- "4.2.2"
before_install:
- npm install -g tsd
deploy:
provider: npm
email: npm@smart-coordination.com
api_key:
secure: XAtA2XHAr96ILKpm1VnB/Nff9hiQv3FUa/NDfGZgvJKimuF/TwU2+kXyAag/LlEQGckZ9/IDx0PTIe8x4wOvg2VyKceYktGt6G5/MHeAXwzkkM253k2CKweVtBgnpZ2doTZXeeV/h7hHuEWZbWRXIVCgM6/inaaNe4cMRGCWqwb1xmw6D8VkLpNo6PiB37gR4GfMokasgVHZEVMg2evWKk0moREGW9XKqoE6PS9TPHPHerdqFqfbmeOq3nNgHrJZkNsAJ3PPESWCe/NGEBwtYDKrPI3QlouvXmxScI9/p2VCQmdFoUxKMDsVzBdRMrCx+XxoS8x81HxubZSpnvzUlzGtznZi7e6OyAlI7xXELIO551AH4V/pNWWUPATX+7vXVDGh7aAZYme/fejisjO5Tk9aqRvohh2jCDml3ED6alHHfI0oX5UvBpOE+XwGTIJ8qpf9RrLP5DC27JWE3fqY/WoqIZX7phoKeKYLl+R7Iln/dfvepbMBgcesnBf4PuMh3Qm2l2G1bElJ/hniV1dgggwjcg50nA0Ee9sCnORPxxjdDIMwJw//NJSe+Aq5Fm1ure9oNiBYOeF0bLVQyfGIC8J8coy1xdqv2klKnGHjMMN44bjNlmDp00SaRpbdDuavyocosQVpzfA+hY2QtGV5TXFv6TLgcMYwf8gNyVNkSGE=
on:
tags: true
repo: pushrocks/smartcli
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,11 +1,20 @@
# smartcli # smartcli
nodejs wrapper for CLI related tasks nodejs wrapper for CLI related tasks. TypeScript ready.
## Status ## Availabililty
[![Build Status](https://travis-ci.org/pushrocks/smartcli.svg?branch=master)](https://travis-ci.org/pushrocks/smartcli) [![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartcli)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartcli)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartcli)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartcli/docs)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartcli/badges/master/build.svg)](https://gitlab.com/pushrocks/smartcli/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartcli/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartcli/commits/master)
[![Dependency Status](https://david-dm.org/pushrocks/smartcli.svg)](https://david-dm.org/pushrocks/smartcli) [![Dependency Status](https://david-dm.org/pushrocks/smartcli.svg)](https://david-dm.org/pushrocks/smartcli)
[![bitHound Overall Score](https://www.bithound.io/github/pushrocks/smartcli/badges/score.svg)](https://www.bithound.io/github/pushrocks/smartcli) [![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartcli/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartcli/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartcli/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartcli) [![bitHound Code](https://www.bithound.io/github/pushrocks/smartcli/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartcli)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
## Install the package ## Install the package
npm install smartcli --save npm install smartcli --save
@ -17,40 +26,39 @@ this plugin tries to establish some logic in which CLI tools work.
take the following commandline input: take the following commandline input:
``` ```
mytool function argument1 argument2 --option1 option1Value --option2 option2Value mytool command argument1 argument2 --option1 -o2 option2Value
``` ```
* 'mytool' obviously is the tool (like git) * `mytool` obviously is the tool (like git)
* function is the main thing the tool shall do (like commit) * `command` is the main thing the tool shall do (like commit)
* option is an option you can add (like -m for message) * `argument1` and `argument2` are arguments
* optionValue is the referenced option value (like a commit message) * `option1` is a longform option you can add (like --message for message)
* `optionValue` is the referenced option value (like a commit message)
When there is no command and no option specified the standardTask applied.
When there is a option specified but no command, standardTask applies,
except when of the options is -v, --version or --help.
### The inner organization of smartcli ```javascript
**smartcli** exposes three major groups of functions: import {Smartcli} from "smartcli"
mySmartcli = new Smartcli();
mySmartcli.standardTask()
.then(argvArg => {
// do something if program is called without an command
});
* check functions mySmartcli.addCommand({commandname: 'install'})
* are grouped in **smartcli.checks** object .then(argvArg => {
* get functions // do something if program is called with command "install"
* are grouped in **smartcli.get** object })
* async interaction functions
* are grouped in **smartcli.interaction** object
```js mySmartcli.addVersion('1.0.0') // -v and --version options will display the specified version in the terminal
var smartcli = require("smartcli");
/* -------------- Check Functions -------------------*/ mySmartCli.addHelp({ // is triggered by help command and --help option
//returns true for terminal command "node myjs.js jazz" helpText: 'some help text to print' // the helpText to display
smartcli.check.command('jazz'); })
/** mySmartcli.startParse() // starts the evaluation and fullfills or rejects promises.
* returns an object for terminal command "node myjs.js --myoption something" like so
* {
* name: 'myoption',
* specified: true,
* value: 'something'
* }
*/
smartcli.get.option('myoption');
``` ```
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

1
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export { Smartcli } from './smartcli.classes.smartcli';

29
dist/index.js vendored
View File

@ -1,27 +1,4 @@
/// <reference path="typings/main.d.ts" />
/// <reference path="./smartcli.interfaces.ts" />
"use strict"; "use strict";
var plugins = require("./smartcli.plugins"); var smartcli_classes_smartcli_1 = require("./smartcli.classes.smartcli");
var SmartcliChecks = require("./smartcli.checks"); exports.Smartcli = smartcli_classes_smartcli_1.Smartcli;
var SmartcliGetters = require("./smartcli.getters"); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEseUVBQXNEO0FBQTdDLCtDQUFBLFFBQVEsQ0FBQSJ9
var SmartcliInteractions = require("./smartcli.interaction");
/* ------------------------------------------------ *
* ---------- plugins for direct use -------------- *
* ------------------------------------------------ */
exports.inquirer = plugins.inquirer; //inquirer is for asking questions
exports.cliff = plugins.cliff; // formats cli output
exports.argv = plugins.argv; //argv gets initial cli commands and options.
/* ------------------------------------------------ *
* ---------- checks ------------------------------ *
* ------------------------------------------------ */
exports.check = SmartcliChecks;
/* ------------------------------------------------ *
* ---------- getters ----------------------------- *
* ------------------------------------------------ */
exports.get = SmartcliGetters;
/* ------------------------------------------------ *
* ---------- interaction ----------------------------- *
* ------------------------------------------------ */
exports.interaction = SmartcliInteractions;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDBDQUEwQztBQUMxQyxpREFBaUQ7O0FBRWpELElBQU8sT0FBTyxXQUFXLG9CQUFvQixDQUFDLENBQUM7QUFDL0MsSUFBTyxjQUFjLFdBQVcsbUJBQW1CLENBQUMsQ0FBQztBQUNyRCxJQUFPLGVBQWUsV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBQ3ZELElBQU8sb0JBQW9CLFdBQVcsd0JBQXdCLENBQUMsQ0FBQztBQUVoRTs7c0RBRXNEO0FBQzNDLGdCQUFRLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDLGtDQUFrQztBQUMvRCxhQUFLLEdBQUcsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFDLHFCQUFxQjtBQUM1QyxZQUFJLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDLDZDQUE2QztBQUU3RTs7c0RBRXNEO0FBQzNDLGFBQUssR0FBRyxjQUFjLENBQUM7QUFFbEM7O3NEQ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XJndiBnZXRzIGluaXRpYWwgY2xpIGNvbW1hbmRzIGFuZCBvcHRpb25zLlxuXG4vKiAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKlxuICogLS0tLS0tLS0tLSBjaGVja3MgLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICpcbiAqIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqL1xuZXhwb3J0IGxldCBjaGVjayA9IFNtYXJ0Y2xpQ2hlY2tzO1xuXG4vKiAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKlxuICogLS0tLS0tLS0tLSBnZXR0ZXJzIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICpcbiAqIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqL1xuZXhwb3J0IGxldCBnZXQgPSBTbWFydGNsaUdldHRlcnM7XG5cbi8qIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqXG4gKiAtLS0tLS0tLS0tIGludGVyYWN0aW9uIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICpcbiAqIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqL1xuZXhwb3J0IGxldCBpbnRlcmFjdGlvbiA9IFNtYXJ0Y2xpSW50ZXJhY3Rpb25zO1xuIl0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9

View File

@ -1,62 +0,0 @@
/// <reference path="typings/main.d.ts" />
/// <reference path="./smartcli.interfaces.ts" />
"use strict";
var plugins = require("./smartcli.plugins");
/**
* checks for a special command string and returns true if found.
* @param commandString
* @returns {boolean}
*/
exports.command = function (commandString) {
if (plugins.argv._.indexOf(commandString) == 0) {
return true;
}
return false;
};
/**
* checks if a command is present, returns true if yes, false if no.
* @returns {boolean}
*/
exports.commandPresence = function () {
if (plugins.argv._.length > 0) {
return true;
}
return false;
};
/**
* checks for an special command argument at a certain position, returns true if matches, returns false if not
* @param level
* @returns {boolean}
*/
exports.commandArgument = function (commandArgumentString, level) {
if (level === void 0) { level = 1; }
if (exports.commandArgumentPresence(level) && (plugins.argv._[level] == commandArgumentString)) {
return true;
}
return false;
};
exports.commandArgumentPresence = function (level) {
if (level === void 0) { level = 1; }
if (plugins.argv._.length >= (level + 1)) {
return true;
}
return false;
};
/**
* checks for a specific option string, returns true if yes, returns false if no
* @returns {boolean}
*/
exports.option = function (optionString) {
if (plugins.smartparam.exists(plugins.argv, optionString)) {
return true;
}
return false;
};
exports.optionPresence = function () {
if (plugins.argv.indexOf() != -1) {
return true;
}
return false;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNoZWNrcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSwwQ0FBMEM7QUFDMUMsaURBQWlEOztBQUVqRCxJQUFPLE9BQU8sV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBRS9DOzs7O0dBSUc7QUFDUSxlQUFPLEdBQUcsVUFBUyxhQUFvQjtJQUM5QyxFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxPQUFPLENBQUMsYUFBYSxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUM3QyxNQUFNLENBQUMsSUFBSSxDQUFBO0lBQ2YsQ0FBQztJQUNELE1BQU0sQ0FBQyxLQUFLLENBQUM7QUFDakIsQ0FBQyxDQUFDO0FBRUY7OztHQUdHO0FBQ1EsdUJBQWUsR0FBRztJQUN6QixFQUFFLENBQUEs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0cnVlIGlmIHllcywgcmV0dXJucyBmYWxzZSBpZiBub1xuICogQHJldHVybnMge2Jvb2xlYW59XG4gKi9cbmV4cG9ydCBsZXQgb3B0aW9uID0gZnVuY3Rpb24ob3B0aW9uU3RyaW5nKTpib29sZWFuIHtcbiAgICBpZihwbHVnaW5zLnNtYXJ0cGFyYW0uZXhpc3RzKHBsdWdpbnMuYXJndiwgb3B0aW9uU3RyaW5nKSkge1xuICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICB9XG4gICAgcmV0dXJuIGZhbHNlO1xufTtcblxuZXhwb3J0IGxldCBvcHRpb25QcmVzZW5jZSA9IGZ1bmN0aW9uKCk6Ym9vbGVhbiB7XG4gICAgaWYgKHBsdWdpbnMuYXJndi5pbmRleE9mKCkgIT0gLTEpIHtcbiAgICAgICAgcmV0dXJuIHRydWVcbiAgICB9XG4gICAgcmV0dXJuIGZhbHNlO1xufTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

69
dist/smartcli.classes.smartcli.d.ts vendored Normal file
View File

@ -0,0 +1,69 @@
/// <reference types="q" />
import * as q from 'q';
import { Subject } from 'rxjs';
import { Objectmap } from 'lik';
export interface ICommandPromiseObject {
commandName: string;
promise: q.Promise<void>;
}
export interface ITriggerObservableObject {
triggerName: string;
subject: Subject<void>;
}
export declare class Smartcli {
argv: any;
questionsDone: any;
parseStarted: any;
commands: any;
questions: any;
version: string;
/**
* map of all Command/Promise objects to keep track
*/
allCommandPromisesMap: Objectmap<ICommandPromiseObject>;
/**
* map of all Trigger/Observable objects to keep track
*/
allTriggerObservablesMap: Objectmap<ITriggerObservableObject>;
constructor();
/**
* adds an alias, meaning one equals the other in terms of command execution.
*/
addCommandAlias(keyArg: any, aliasArg: any): void;
/**
* adds a Command by returning a Promise that reacts to the specific commandString given.
* Note: in e.g. "npm install something" the "install" is considered the command.
*/
addCommand(commandNameArg: string): q.Promise<any>;
/**
* gets a Promise for a command word
*/
getCommandPromiseByName(commandNameArg: string): q.Promise<void>;
/**
* adds a Trigger. Like addCommand(), but returns an subscribable observable
*/
addTrigger(triggerNameArg: string): Subject<void>;
/**
* execute trigger by name
* @param commandNameArg - the name of the command to trigger
*/
trigger(triggerName: string): Subject<void>;
/**
* allows to specify help text to be printed above the rest of the help text
*/
addHelp(optionsArg: {
helpText: string;
}): void;
/**
* specify version to be printed for -v --version
*/
addVersion(versionArg: string): void;
/**
* returns promise that is resolved when no commands are specified
*/
standardTask(): q.Promise<any>;
/**
* start the process of evaluating commands
*/
startParse(): void;
}

133
dist/smartcli.classes.smartcli.js vendored Normal file
View File

@ -0,0 +1,133 @@
"use strict";
const q = require("q");
const rxjs_1 = require("rxjs");
const plugins = require("./smartcli.plugins");
// import classes
const lik_1 = require("lik");
class Smartcli {
constructor() {
/**
* map of all Command/Promise objects to keep track
*/
this.allCommandPromisesMap = new lik_1.Objectmap();
/**
* map of all Trigger/Observable objects to keep track
*/
this.allTriggerObservablesMap = new lik_1.Objectmap();
this.argv = plugins.yargs;
this.questionsDone = q.defer();
this.parseStarted = q.defer();
}
/**
* adds an alias, meaning one equals the other in terms of command execution.
*/
addCommandAlias(keyArg, aliasArg) {
this.argv = this.argv.alias(keyArg, aliasArg);
return;
}
/**
* adds a Command by returning a Promise that reacts to the specific commandString given.
* Note: in e.g. "npm install something" the "install" is considered the command.
*/
addCommand(commandNameArg) {
let done = q.defer();
this.allCommandPromisesMap.add({
commandName: commandNameArg,
promise: done.promise
});
this.parseStarted.promise
.then(() => {
if (this.argv._.indexOf(commandNameArg) === 0) {
done.resolve(this.argv);
}
else {
done.reject(this.argv);
}
});
return done.promise;
}
/**
* gets a Promise for a command word
*/
getCommandPromiseByName(commandNameArg) {
return this.allCommandPromisesMap.find(commandDeferredObjectArg => {
return commandDeferredObjectArg.commandName === commandNameArg;
}).promise;
}
/**
* adds a Trigger. Like addCommand(), but returns an subscribable observable
*/
addTrigger(triggerNameArg) {
let triggerSubject = new rxjs_1.Subject();
this.allTriggerObservablesMap.add({
triggerName: triggerNameArg,
subject: triggerSubject
});
this.addCommand(triggerNameArg).then(() => {
triggerSubject.next();
});
return triggerSubject;
}
/**
* execute trigger by name
* @param commandNameArg - the name of the command to trigger
*/
trigger(triggerName) {
let triggerSubject = this.allTriggerObservablesMap.find(triggerObservableObjectArg => {
return triggerObservableObjectArg.triggerName === triggerName;
}).subject;
triggerSubject.next();
return triggerSubject;
}
/**
* allows to specify help text to be printed above the rest of the help text
*/
addHelp(optionsArg) {
this.addCommand('help').then(argvArg => {
plugins.beautylog.log(optionsArg.helpText);
});
}
/**
* specify version to be printed for -v --version
*/
addVersion(versionArg) {
this.version = versionArg;
this.addCommandAlias('v', 'version');
this.parseStarted.promise
.then(() => {
if (this.argv.v) {
console.log(this.version);
}
});
}
/**
* returns promise that is resolved when no commands are specified
*/
standardTask() {
let done = q.defer();
this.allCommandPromisesMap.add({
commandName: 'standard',
promise: done.promise
});
this.parseStarted.promise
.then(() => {
if (this.argv._.length === 0 && !this.argv.v) {
done.resolve(this.argv);
}
else {
done.reject(this.argv);
}
});
return done.promise;
}
/**
* start the process of evaluating commands
*/
startParse() {
this.argv = this.argv.argv;
this.parseStarted.resolve();
return;
}
}
exports.Smartcli = Smartcli;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHVCQUFzQjtBQUN0QiwrQkFBOEI7QUFFOUIsOENBQTZDO0FBRTdDLGlCQUFpQjtBQUNqQiw2QkFBK0I7QUFhL0I7SUFrQkk7UUFWQTs7V0FFRztRQUNILDBCQUFxQixHQUFHLElBQUksZUFBUyxFQUF5QixDQUFBO1FBRTlEOztXQUVHO1FBQ0gsNkJBQXdCLEdBQUcsSU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QUksQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7Z0JBQzNDLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFBO1lBQzNCLENBQUM7WUFBQyxJQUFJLENBQUMsQ0FBQztnQkFDSixJQUFJLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQTtZQUMxQixDQUFDO1FBQ0wsQ0FBQyxDQUFDLENBQUE7UUFDTixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUN2QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxVQUFVO1FBQ04sSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQTtRQUMxQixJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQzNCLE1BQU0sQ0FBQTtJQUNWLENBQUM7Q0FFSjtBQS9JRCw0QkErSUMifQ==

File diff suppressed because one or more lines are too long

View File

@ -1,55 +0,0 @@
/// <reference path="typings/main.d.ts" />
/// <reference path="./smartcli.interfaces.ts" />
"use strict";
var plugins = require("./smartcli.plugins");
/**
* executes callback with answer to question as argument
* @param questionString the question you want to ask the user
* @param cb the function to execute with answer as param
* @returns {null}
*/
exports.getAnswer = function (questionString, cb) {
if (typeof questionString != 'string') {
plugins.beautylog.error('no question specified');
return null;
}
//make inquirer compatible question object
var question = {
type: "input",
name: "userFeedback",
message: questionString,
validate: function (value) {
return true;
}
};
plugins.inquirer.prompt([question], function (answers) {
var answer = answers.userFeedback;
cb(answer);
});
};
/**
*
* @param questionString
* @param choiceOptions
* @param cb
* @returns {null}
*/
exports.getChoice = function (questionString, choiceOptions, cb) {
if (!Array.isArray(choiceOptions)) {
return null;
}
//make inquirer compatible question object
var question = {
type: "list",
name: "userFeedback",
message: questionString,
choices: choiceOptions,
filter: function (val) { return val.toLowerCase(); }
};
plugins.inquirer.prompt(question, function (answers) {
var answer = answers.userFeedback;
cb(answer);
});
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmludGVyYWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDBDQUEwQztBQUMxQyxpREFBaUQ7O0FBRWpELElBQU8sT0FBTyxXQUFXLG9CQUFvQixDQUFDLENBQUM7QUFFL0M7Ozs7O0dBS0c7QUFDUSxpQkFBUyxHQUFHLFVBQVMsY0FBcUIsRUFBRSxFQUFFO0lBQ3JELEVBQUUsQ0FBQyxDQUFDLE9BQU8sY0FBYyxJQUFJLFFBQVEsQ0FBQyxDQUFDLENBQUM7UUFDcEMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxLQUFLLENBQUMsdUJBQXVCLENBQUMsQ0FBQztRQUNqRCxNQUFNLENBQUMsSUFBSSxDQUFDO0lBQ2hCLENBQUM7SUFDRCwwQ0FBMEM7SUFDMUMsSUFBSSxRQUFRLEdBQUc7UUFDWCxJQUFJLEVBQUUsT0FBTztRQUNiLElBQUksRUFBRSxjQUFjO1FBQ3BCLE9BQU8sRUFBRSxjQUFjO1FBQ3ZCLFFBQVEsRUFBRSxVQUFVLEtBQUs7WUFDckIsTUFBTSxDQUFDLElBQUksQ0FBQztRQUNoQixDQUFDO0tBQ0osQ0FBQztJQUVGLE9BQU8sQ0FBQyxRQUFRLENBQUMsTUFBTSxDQUFDLENBQUMsUUFBUSxDQUFDLEVBQUMsVUFBUyxPQUFPO1FBQy9DLElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUM7UUFDbEMsRUFBRSxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBQ2YsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUM7QUFFRjs7Ozs7O0dBTUc7QUFDUSxpQkFBUyxHQUFHLFVBQVMsY0FBcUIs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bmV4cG9ydCBsZXQgZ2V0Q2hvaWNlID0gZnVuY3Rpb24ocXVlc3Rpb25TdHJpbmc6c3RyaW5nLCBjaG9pY2VPcHRpb25zOnN0cmluZ1tdLCBjYikge1xuICAgIGlmKCFBcnJheS5pc0FycmF5KGNob2ljZU9wdGlvbnMpKSB7XG4gICAgICAgIHJldHVybiBudWxsO1xuICAgIH1cblxuICAgIC8vbWFrZSBpbnF1aXJlciBjb21wYXRpYmxlIHF1ZXN0aW9uIG9iamVjdFxuICAgIHZhciBxdWVzdGlvbiA9IHtcbiAgICAgICAgdHlwZTogXCJsaXN0XCIsXG4gICAgICAgIG5hbWU6IFwidXNlckZlZWRiYWNrXCIsXG4gICAgICAgIG1lc3NhZ2U6IHF1ZXN0aW9uU3RyaW5nLFxuICAgICAgICBjaG9pY2VzOiBjaG9pY2VPcHRpb25zLFxuICAgICAgICBmaWx0ZXI6IGZ1bmN0aW9uKCB2YWwgKSB7IHJldHVybiB2YWwudG9Mb3dlckNhc2UoKTsgfVxuICAgIH07XG5cbiAgICBwbHVnaW5zLmlucXVpcmVyLnByb21wdChxdWVzdGlvbixmdW5jdGlvbihhbnN3ZXJzKXtcbiAgICAgICAgdmFyIGFuc3dlciA9IGFuc3dlcnMudXNlckZlZWRiYWNrO1xuICAgICAgICBjYihhbnN3ZXIpO1xuICAgIH0pO1xuXG59OyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==

View File

@ -1,3 +0,0 @@
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJzbWFydGNsaS5pbnRlcmZhY2VzLmpzIiwic291cmNlc0NvbnRlbnQiOltdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==

7
dist/smartcli.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import 'typings-global';
import * as yargs from 'yargs';
import * as beautylog from 'beautylog';
import * as lik from 'lik';
import * as path from 'path';
import * as smartparam from 'smartparam';
export { yargs, beautylog, lik, path, smartparam };

View File

@ -1,10 +1,13 @@
/// <reference path="typings/main.d.ts" />
"use strict"; "use strict";
exports.path = require("path"); require("typings-global");
exports.beautylog = require("beautylog"); const yargs = require("yargs");
exports.cliff = require("cliff"); exports.yargs = yargs;
exports.inquirer = require("inquirer"); const beautylog = require("beautylog");
exports.smartparam = require("smartparam"); exports.beautylog = beautylog;
exports.argv = require('yargs').argv; const lik = require("lik");
exports.lik = lik;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsMENBQTBDOztBQUUvQixZQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLGlCQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLGFBQUssR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7QUFDekIsZ0JBQVEsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDLENBQUM7QUFDL0Isa0JBQVUsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUM7QUFDbkMsWUFBSSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQyxJQUFJLENBQUMiLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCJ0eXBpbmdzL21haW4uZC50c1wiIC8+XG5cbmV4cG9ydCBsZXQgcGF0aCA9IHJlcXVpcmUoXCJwYXRoXCIpO1xuZXhwb3J0IGxldCBiZWF1dHlsb2cgPSByZXF1aXJlKFwiYmVhdXR5bG9nXCIpO1xuZXhwb3J0IGxldCBjbGlmZiA9IHJlcXVpcmUoXCJjbGlmZlwiKTtcbmV4cG9ydCBsZXQgaW5xdWlyZXIgPSByZXF1aXJlKFwiaW5xdWlyZXJcIik7XG5leHBvcnQgbGV0IHNtYXJ0cGFyYW0gPSByZXF1aXJlKFwic21hcnRwYXJhbVwiKTtcbmV4cG9ydCBsZXQgYXJndiA9IHJlcXVpcmUoJ3lhcmdzJykuYXJndjsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= const path = require("path");
exports.path = path;
const smartparam = require("smartparam");
exports.smartparam = smartparam;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUV2QiwrQkFBOEI7QUFPMUIsc0JBQUs7QUFOVCx1Q0FBc0M7QUFPbEMsOEJBQVM7QUFOYiwyQkFBMEI7QUFPdEIsa0JBQUc7QUFOUCw2QkFBNEI7QUFPeEIsb0JBQUk7QUFOUix5Q0FBd0M7QUFPcEMsZ0NBQVUifQ==

15
docs/book.json Normal file
View File

@ -0,0 +1,15 @@
{
"structure": {
"readme": "index.md"
},
"plugins": [
"tonic",
"edit-link"
],
"pluginsConfig": {
"edit-link": {
"base": "https://gitlab.com/pushrocks/npmts/edit/master/docs/",
"label": "Edit on GitLab"
}
}
}

47
docs/index.md Normal file
View File

@ -0,0 +1,47 @@
# smartcli
nodejs wrapper for CLI related tasks. TypeScript ready.
## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartcli)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartcli)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartcli)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartcli/docs)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartcli/badges/master/build.svg)](https://gitlab.com/pushrocks/smartcli/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartcli/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartcli/commits/master)
[![Dependency Status](https://david-dm.org/pushrocks/smartcli.svg)](https://david-dm.org/pushrocks/smartcli)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartcli/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartcli/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartcli/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartcli)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
## Install the package
npm install smartcli --save
## Usage
this plugin tries to establish some logic in which CLI tools work.
take the following commandline input:
```
mytool function argument1 argument2 --option1 -o2 option2Value
```
* 'mytool' obviously is the tool (like git)
* function is the main thing the tool shall do (like commit)
* argument1 and argument2 are arguments
* option1 is a longform option you can add (like --message for message)
* optionValue is the referenced option value (like a commit message)
```typescript
import {Smartcli} from "smartcli"
mySmartcli = new Smartcli();
mySmartcli.standardTask()
.then(argvArg => {
// do something if program is called without an command
});
mySmartcli.question
```

3
npmts.json Normal file
View File

@ -0,0 +1,3 @@
{
"mode":"default"
}

View File

@ -1,8 +1,9 @@
{ {
"name": "smartcli", "name": "smartcli",
"version": "0.0.13", "version": "2.0.0",
"description": "nodejs wrapper for CLI related tasks", "description": "nodejs wrapper for CLI related tasks",
"main": "index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "(npmts)", "test": "(npmts)",
"testm": "(cd ts/compile && gulp) && (node test.js jazz jam --awesome)", "testm": "(cd ts/compile && gulp) && (node test.js jazz jam --awesome)",
@ -13,27 +14,35 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/pushrocks/smartcli.git" "url": "https://gitlab.com/pushrocks/smartcli.git"
}, },
"keywords": [ "keywords": [
"json", "cli",
"jade", "promise",
"template" "task",
"push.rocks"
], ],
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)", "author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/pushrocks/smartcli/issues" "url": "https://gitlab.com/pushrocks/smartcli/issues"
}, },
"homepage": "https://github.com/pushrocks/smartcli", "homepage": "https://gitlab.com/pushrocks/smartcli",
"dependencies": { "dependencies": {
"beautylog": "4.1.2", "@types/q": "0.x.x",
"cliff": "^0.1.10", "@types/yargs": "6.x.x",
"inquirer": "^0.12.0", "beautylog": "^6.0.0",
"smartparam": "0.0.7", "lik": "^1.0.24",
"yargs": "^4.3.2" "q": "^1.4.1",
"rxjs": "^5.0.1",
"smartparam": "0.1.1",
"typings-global": "^1.0.14",
"yargs": "^6.4.0"
}, },
"devDependencies": { "devDependencies": {
"npmts": "^5.0.3" "@types/should": "^8.1.30",
"npmts-g": "^5.2.8",
"should": "^11.1.1",
"typings-test": "^1.0.3"
} }
} }

1
test/test.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import 'typings-test';

View File

@ -1,150 +1,51 @@
/// <reference path="../ts/typings/main.d.ts" /> "use strict";
var smartcli = require("../dist/index.js"); require("typings-test");
var should = req; const smartcli = require("../dist/index");
/* ------------------------------------------------------------------ * const should = require("should");
* ------------------- CHECKS TESTS --------------------------------- * describe('smartcli.Smartcli class', function () {
* ------------------------------------------------------------------ */ let smartCliTestObject;
describe("smartcli", function () { describe('new Smartcli()', function () {
describe(".check", function () { it('should create a new Smartcli', function () {
describe(".command", function () { smartCliTestObject = new smartcli.Smartcli();
it("should return true when specified command is found", function () { should(smartCliTestObject).be.instanceof(smartcli.Smartcli);
smartcli.check.command("jazz").should.be.true();
});
it("should return false when specified command is NOT found", function () {
smartcli.check.command("rock").should.be.false();
});
}); });
describe(".commandPresence", function () { });
describe('.addCommand', function () {
it('should add an command', function () {
smartCliTestObject.addCommand('awesome');
});
});
describe('.standardTask', function () {
it('should start parsing a standardTask', function (done) {
smartCliTestObject.standardTask()
.then(() => {
console.log('this is the standard Task!');
});
done();
});
});
describe('.trigger', function () {
let hasExecuted = false;
it('should accept a command', function (done) {
smartCliTestObject.addTrigger('triggerme')
.subscribe(() => {
hasExecuted = true;
});
done();
});
it('should not have executed yet', function () {
should(hasExecuted).be.false();
});
it('should execute when triggered', function (done) {
smartCliTestObject.trigger('triggerme');
should(hasExecuted).be.true();
done();
});
});
describe('.startParse', function () {
it('should start parsing the CLI input', function () {
smartCliTestObject.startParse();
}); });
}); });
}); });
var checkCommandArgumentTest = function () { //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQiwwQ0FBMEM7QUFDMUMsaUNBQWdDO0FBRWhDLFFBQVEsQ0FBQyx5QkFBeUIsRUFBQztJQUMvQixJQUFJLGtCQUFxQyxDQUFBO0lBQ3pDLFFBQVEsQ0FBQyxnQkFBZ0IsRUFBQztRQUN0QixFQUFFLENBQUMsOEJBQThCLEVBQUM7WUFDOUIsa0JBQWtCLEdBQUcsSUFBSSxRQUFRLENBQUMsUUFBUSxFQUFFLENBQUE7WUFDNUMsTUFBTSxDQUFDLGtCQUFrQixDQUFDLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxRQUFRLENBQUMsUUFBUSxDQUFDLENBQUE7UUFDL0QsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtJQUNGLFFBQVEsQ0FBQyxhQUFhLEVBQUM7UUFDbkIsRUFBRSxDQUFDLHVCQU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BRSxDQUFDLElBQUksRUFBRSxDQUFBO1lBQzdCLElBQUksRUFBRSxDQUFBO1FBQ1YsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtJQUNGLFFBQVEsQ0FBQyxhQUFhLEVBQUM7UUFDbkIsRUFBRSxDQUFDLG9DQUFvQyxFQUFDO1lBQ3BDLGtCQUFrQixDQUFDLFVBQVUsRUFBRSxDQUFBO1FBQ25DLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
if (smartcli.check.commandArgument("jam", 1)) {
beautylog.success('There is a level 1 argument! Perfect!');
}
else {
beautylog.error('There seems to be no level 1 argument... This is wrong');
process.exit(1);
}
if (!smartcli.check.commandArgument("session", 2)) {
beautylog.success('There is no level 2 argument with the name of "session"! Perfect!');
}
else {
beautylog.error('There seems to be a level 2 argument with the name of "session"! This is wrong');
process.exit(1);
}
};
checkCommandArgumentTest();
var checkCommandArgumentPresenceTest = function () {
if (smartcli.check.commandArgumentPresence(1)) {
beautylog.success('There is a level 1 argument! Perfect!');
}
else {
beautylog.error('There seems to be no level 1 argument... This is wrong');
process.exit(1);
}
if (!smartcli.check.commandArgumentPresence(2)) {
beautylog.success('There is no level 2 argument! Perfect!');
}
else {
beautylog.error('There seems to be a level 2 argument... This is wrong');
process.exit(1);
}
};
checkCommandArgumentPresenceTest();
/* ------------------------------------------------------------------ *
* ------------------- GETTERS TESTS -------------------------------- *
* ------------------------------------------------------------------ */
var getCommandTest = function () {
var cliCommand = smartcli.get.command();
if (cliCommand.name == "jazz") {
beautylog.success('The specified command name is "jazz". Perfect!');
}
else {
beautylog.error('The specified command name is not "jazz". Something is wrong!');
process.exit(1);
}
};
getCommandTest();
var getCommandArgumentTest = function () {
var cliArgument = smartcli.get.commandArgument(1);
var cliArgument2 = smartcli.get.commandArgument(2);
if (cliArgument.name == "jam") {
beautylog.success('The first specified command argument name is "jam". Perfect!');
}
else {
beautylog.error('The first specified command argument name is not "jam". Something is wrong!');
process.exit(1);
}
if (cliArgument2.name == "undefined") {
beautylog.success('The second specified command argument name is "undefined". Perfect!');
}
else {
beautylog.error('The second specified command argument name is not "undefined". Something is wrong!');
process.exit(1);
}
};
getCommandArgumentTest();
var getCommandArgsTest = function () {
var commandArgs = smartcli.get.commandArgs();
if (commandArgs[0].name == "jam") {
beautylog.success("first command argument is 'jam'. Perfect!");
}
else {
beautylog.error("first command argument is not 'jam'. Something is wromg!");
console.log(commandArgs[0].name);
process.exit(1);
}
};
getCommandArgsTest();
var getOptionTest = function () {
var cliOption = smartcli.get.option("awesome");
var cliOption2 = smartcli.get.option("terrific");
if (cliOption.specified) {
beautylog.success("awesome is specified. Perfect!");
}
else {
beautylog.error("awesome is not specified. Somehthing is wrong");
process.exit(1);
}
if (!cliOption2.specified) {
beautylog.success("terrific is not specified. Perfect!");
}
else {
beautylog.error("terrific is specified. Somehthing is wrong");
process.exit(1);
}
};
getOptionTest();
var getCwdTest = function () {
beautylog.info('The current directory is: ' + smartcli.get.cwd().path);
};
getCwdTest();
/* ------------------------------------------------------------------ *
* ------------------- INTERACTION TESTS ---------------------------- *
* ------------------------------------------------------------------ */
var interactionGetAnswerTest = function () {
smartcli.interaction.getAnswer('How do you feel?', function (answer) {
console.log('The answer is: ' + answer);
interactionGetChoiceTest();
});
};
var interactionGetChoiceTest = function () {
smartcli.interaction.getChoice('What music do you like to hear?', ['Jazz', 'Blues', 'Classical'], function (answer) {
console.log('The answer is: ' + answer);
endTests();
});
};
var endTests = function () {
beautylog.ok("No more tests!");
beautylog.success("Tests completed successfully!");
};
if (!smartcli.check.option("silent")) {
interactionGetAnswerTest();
}
else {
beautylog.info("--silent option is specified, thus we are not running interaction tests.");
endTests();
}
;
//# sourceMappingURL=test.js.map

View File

@ -1,164 +1,51 @@
/// <reference path="../ts/typings/main.d.ts" /> import 'typings-test'
let smartcli = require("../dist/index.js");
let should = req
/* ------------------------------------------------------------------ *
* ------------------- CHECKS TESTS --------------------------------- *
* ------------------------------------------------------------------ */
describe("smartcli",function(){
describe(".check",function(){
describe(".command",function(){
it("should return true when specified command is found",function(){
smartcli.check.command("jazz").should.be.true();
});
it("should return false when specified command is NOT found",function(){
smartcli.check.command("rock").should.be.false();
});
});
describe(".commandPresence",function(){
});
});
});
var checkCommandArgumentTest = function() {
if (smartcli.check.commandArgument("jam",1)) {
beautylog.success('There is a level 1 argument! Perfect!');
} else {
beautylog.error('There seems to be no level 1 argument... This is wrong');
process.exit(1);
}
if (!smartcli.check.commandArgument("session",2)) {
beautylog.success('There is no level 2 argument with the name of "session"! Perfect!');
} else {
beautylog.error('There seems to be a level 2 argument with the name of "session"! This is wrong');
process.exit(1);
}
};
checkCommandArgumentTest();
var checkCommandArgumentPresenceTest = function() {
if (smartcli.check.commandArgumentPresence(1)) {
beautylog.success('There is a level 1 argument! Perfect!');
} else {
beautylog.error('There seems to be no level 1 argument... This is wrong');
process.exit(1);
}
if (!smartcli.check.commandArgumentPresence(2)) {
beautylog.success('There is no level 2 argument! Perfect!');
} else {
beautylog.error('There seems to be a level 2 argument... This is wrong');
process.exit(1);
}
};
checkCommandArgumentPresenceTest();
/* ------------------------------------------------------------------ *
* ------------------- GETTERS TESTS -------------------------------- *
* ------------------------------------------------------------------ */
var getCommandTest = function(){
var cliCommand = smartcli.get.command();
if(cliCommand.name == "jazz") {
beautylog.success('The specified command name is "jazz". Perfect!');
} else {
beautylog.error('The specified command name is not "jazz". Something is wrong!');
process.exit(1);
}
};
getCommandTest();
var getCommandArgumentTest = function() {
var cliArgument = smartcli.get.commandArgument(1);
var cliArgument2 = smartcli.get.commandArgument(2);
if(cliArgument.name == "jam") {
beautylog.success('The first specified command argument name is "jam". Perfect!');
} else {
beautylog.error('The first specified command argument name is not "jam". Something is wrong!');
process.exit(1);
}
if(cliArgument2.name == "undefined") {
beautylog.success('The second specified command argument name is "undefined". Perfect!');
} else {
beautylog.error('The second specified command argument name is not "undefined". Something is wrong!');
process.exit(1);
}
};
getCommandArgumentTest();
var getCommandArgsTest = function() {
var commandArgs = smartcli.get.commandArgs();
if(commandArgs[0].name == "jam") {
beautylog.success("first command argument is 'jam'. Perfect!");
} else {
beautylog.error("first command argument is not 'jam'. Something is wromg!");
console.log(commandArgs[0].name);
process.exit(1);
}
};
getCommandArgsTest();
var getOptionTest = function() {
var cliOption = smartcli.get.option("awesome");
var cliOption2 = smartcli.get.option("terrific");
if(cliOption.specified){
beautylog.success("awesome is specified. Perfect!")
} else {
beautylog.error("awesome is not specified. Somehthing is wrong");
process.exit(1);
}
if(!cliOption2.specified){
beautylog.success("terrific is not specified. Perfect!")
} else {
beautylog.error("terrific is specified. Somehthing is wrong");
process.exit(1);
}
};
getOptionTest();
var getCwdTest = function(){
beautylog.info('The current directory is: ' + smartcli.get.cwd().path);
};
getCwdTest();
/* ------------------------------------------------------------------ *
* ------------------- INTERACTION TESTS ---------------------------- *
* ------------------------------------------------------------------ */
var interactionGetAnswerTest = function() {
smartcli.interaction.getAnswer('How do you feel?',function(answer){
console.log('The answer is: ' + answer);
interactionGetChoiceTest();
});
};
var interactionGetChoiceTest = function() {
smartcli.interaction.getChoice('What music do you like to hear?',['Jazz','Blues','Classical'],function(answer){
console.log('The answer is: ' + answer);
endTests();
});
};
var endTests = function() {
beautylog.ok("No more tests!");
beautylog.success("Tests completed successfully!");
};
if(!smartcli.check.option("silent")){
interactionGetAnswerTest();
} else {
beautylog.info("--silent option is specified, thus we are not running interaction tests.");
endTests();
};
import smartcli = require('../dist/index')
import * as should from 'should'
describe('smartcli.Smartcli class',function(){
let smartCliTestObject: smartcli.Smartcli
describe('new Smartcli()',function(){
it('should create a new Smartcli',function(){
smartCliTestObject = new smartcli.Smartcli()
should(smartCliTestObject).be.instanceof(smartcli.Smartcli)
})
})
describe('.addCommand',function(){
it('should add an command',function(){
smartCliTestObject.addCommand('awesome')
})
})
describe('.standardTask',function(){
it('should start parsing a standardTask',function(done){
smartCliTestObject.standardTask()
.then(() => {
console.log('this is the standard Task!')
})
done()
})
})
describe('.trigger', function() {
let hasExecuted = false
it('should accept a command', function(done) {
smartCliTestObject.addTrigger('triggerme')
.subscribe(() => {
hasExecuted = true
})
done()
})
it('should not have executed yet', function() {
should(hasExecuted).be.false()
})
it('should execute when triggered', function(done) {
smartCliTestObject.trigger('triggerme')
should(hasExecuted).be.true()
done()
})
})
describe('.startParse',function(){
it('should start parsing the CLI input',function(){
smartCliTestObject.startParse()
})
})
})

View File

@ -1,29 +1 @@
/// <reference path="typings/main.d.ts" /> export { Smartcli } from './smartcli.classes.smartcli'
/// <reference path="./smartcli.interfaces.ts" />
import plugins = require("./smartcli.plugins");
import SmartcliChecks = require("./smartcli.checks");
import SmartcliGetters = require("./smartcli.getters");
import SmartcliInteractions = require("./smartcli.interaction");
/* ------------------------------------------------ *
* ---------- plugins for direct use -------------- *
* ------------------------------------------------ */
export let inquirer = plugins.inquirer; //inquirer is for asking questions
export let cliff = plugins.cliff; // formats cli output
export let argv = plugins.argv; //argv gets initial cli commands and options.
/* ------------------------------------------------ *
* ---------- checks ------------------------------ *
* ------------------------------------------------ */
export let check = SmartcliChecks;
/* ------------------------------------------------ *
* ---------- getters ----------------------------- *
* ------------------------------------------------ */
export let get = SmartcliGetters;
/* ------------------------------------------------ *
* ---------- interaction ----------------------------- *
* ------------------------------------------------ */
export let interaction = SmartcliInteractions;

View File

@ -1,64 +0,0 @@
/// <reference path="typings/main.d.ts" />
/// <reference path="./smartcli.interfaces.ts" />
import plugins = require("./smartcli.plugins");
/**
* checks for a special command string and returns true if found.
* @param commandString
* @returns {boolean}
*/
export let command = function(commandString:string):boolean {
if (plugins.argv._.indexOf(commandString) == 0) {
return true
}
return false;
};
/**
* checks if a command is present, returns true if yes, false if no.
* @returns {boolean}
*/
export let commandPresence = function():boolean {
if(plugins.argv._.length > 0){
return true;
}
return false;
};
/**
* checks for an special command argument at a certain position, returns true if matches, returns false if not
* @param level
* @returns {boolean}
*/
export let commandArgument = function(commandArgumentString:string,level:number = 1):boolean {
if(commandArgumentPresence(level) && (plugins.argv._[level] == commandArgumentString )) {
return true;
}
return false;
};
export let commandArgumentPresence = function(level:number = 1) {
if(plugins.argv._.length >= (level + 1)) {
return true;
}
return false;
};
/**
* checks for a specific option string, returns true if yes, returns false if no
* @returns {boolean}
*/
export let option = function(optionString):boolean {
if(plugins.smartparam.exists(plugins.argv, optionString)) {
return true;
}
return false;
};
export let optionPresence = function():boolean {
if (plugins.argv.indexOf() != -1) {
return true
}
return false;
};

View File

@ -0,0 +1,163 @@
import * as q from 'q'
import { Subject } from 'rxjs'
import * as plugins from './smartcli.plugins'
// import classes
import { Objectmap } from 'lik'
// interfaces
export interface ICommandPromiseObject {
commandName: string,
promise: q.Promise<void>
}
export interface ITriggerObservableObject {
triggerName: string
subject: Subject<void>
}
export class Smartcli {
argv: any
questionsDone
parseStarted
commands
questions
version: string
/**
* map of all Command/Promise objects to keep track
*/
allCommandPromisesMap = new Objectmap<ICommandPromiseObject>()
/**
* map of all Trigger/Observable objects to keep track
*/
allTriggerObservablesMap = new Objectmap<ITriggerObservableObject>()
constructor() {
this.argv = plugins.yargs
this.questionsDone = q.defer()
this.parseStarted = q.defer()
}
/**
* adds an alias, meaning one equals the other in terms of command execution.
*/
addCommandAlias(keyArg,aliasArg): void {
this.argv = this.argv.alias(keyArg,aliasArg)
return
}
/**
* adds a Command by returning a Promise that reacts to the specific commandString given.
* Note: in e.g. "npm install something" the "install" is considered the command.
*/
addCommand(commandNameArg: string): q.Promise<any> {
let done = q.defer<any>()
this.allCommandPromisesMap.add({
commandName: commandNameArg,
promise: done.promise
})
this.parseStarted.promise
.then(() => {
if (this.argv._.indexOf(commandNameArg) === 0) {
done.resolve(this.argv)
} else {
done.reject(this.argv)
}
})
return done.promise
}
/**
* gets a Promise for a command word
*/
getCommandPromiseByName(commandNameArg: string): q.Promise<void> {
return this.allCommandPromisesMap.find(commandDeferredObjectArg => {
return commandDeferredObjectArg.commandName === commandNameArg
}).promise
}
/**
* adds a Trigger. Like addCommand(), but returns an subscribable observable
*/
addTrigger(triggerNameArg: string) {
let triggerSubject = new Subject<void>()
this.allTriggerObservablesMap.add({
triggerName: triggerNameArg,
subject: triggerSubject
})
this.addCommand(triggerNameArg).then(() => {
triggerSubject.next()
})
return triggerSubject
}
/**
* execute trigger by name
* @param commandNameArg - the name of the command to trigger
*/
trigger(triggerName: string) {
let triggerSubject = this.allTriggerObservablesMap.find(triggerObservableObjectArg => {
return triggerObservableObjectArg.triggerName === triggerName
}).subject
triggerSubject.next()
return triggerSubject
}
/**
* allows to specify help text to be printed above the rest of the help text
*/
addHelp(optionsArg: {
helpText: string
}) {
this.addCommand('help').then(argvArg => {
plugins.beautylog.log(optionsArg.helpText)
})
}
/**
* specify version to be printed for -v --version
*/
addVersion(versionArg: string) {
this.version = versionArg
this.addCommandAlias('v','version')
this.parseStarted.promise
.then(() => {
if (this.argv.v) {
console.log(this.version)
}
})
}
/**
* returns promise that is resolved when no commands are specified
*/
standardTask(): q.Promise<any> {
let done = q.defer<any>()
this.allCommandPromisesMap.add({
commandName: 'standard',
promise: done.promise
})
this.parseStarted.promise
.then(() => {
if (this.argv._.length === 0 && !this.argv.v) {
done.resolve(this.argv)
} else {
done.reject(this.argv)
}
})
return done.promise
}
/**
* start the process of evaluating commands
*/
startParse(): void {
this.argv = this.argv.argv
this.parseStarted.resolve()
return
}
}

View File

@ -1,110 +0,0 @@
/// <reference path="typings/main.d.ts" />
/// <reference path="./smartcli.interfaces.ts" />
import plugins = require("./smartcli.plugins");
import SmartcliChecks = require("./smartcli.checks");
/**
*
* @param commandString
* @returns {{specified: boolean, name: any, arguments: CliCommandArgument}}
*/
export let command = function():CliCommand {
var cliCommand = {
specified: SmartcliChecks.commandPresence(),
name: plugins.argv._[0],
arguments: commandArgs()
}
return cliCommand;
};
/**
* gets the second or higher value of plugins.argv._ if specified and returns it as commandArgument
* @param argumentLevel
* @returns {{specified: (boolean|boolean), name}}
*/
export let commandArgument = function(argumentLevel):CliCommandArgument {
var commandArgument:CliCommandArgument = {
specified: false,
name: "undefined",
level:argumentLevel
};
if(argumentLevel < 1) {
plugins.beautylog.error("smartcli.get.argument cannot be invoked with an argumentLevel smaller than 1");
return commandArgument;
}
if(SmartcliChecks.commandArgumentPresence(argumentLevel)) {
commandArgument.specified = true;
commandArgument.name = plugins.argv._[argumentLevel];
}
return commandArgument;
};
/**
* returns array with commandArgs
* @returns {CliCommandArgument[]}
*/
export let commandArgs = function():CliCommandArgument[] {
var commandArgs:CliCommandArgument[] = [];
var argsArray = commandArray().slice(0);
argsArray.shift();
for (var item in argsArray){
var commandArgument:CliCommandArgument = {
specified:true,
name:argsArray[item],
level: item + 1
}
commandArgs.push(commandArgument);
}
return commandArgs;
};
/**
* returns complete command array
* @returns {any}
*/
export let commandArray = function ():string[] {
var commandArray = plugins.argv._;
return commandArray;
};
/**
* returns a cli option
* @param optionName
* @returns {CliOption}
*/
export let option = function(optionName:string):CliOption {
var cliOption:CliOption = {
name:optionName,
specified: false,
value: false
};
if (plugins.smartparam.exists(plugins.argv,optionName)) {
cliOption.name = optionName;
cliOption.specified = true;
cliOption.value = plugins.argv[optionName] //we already know from the "if" above that the value is available.
}
return cliOption;
};
export let options = function() {
var options = {};
for (var key in plugins.argv) {
if (key != "_") {
options['key'] = plugins.argv['key'];
}
}
return options;
};
/**
* returns Directory of cwd
* @returns {{path: string}}
*/
export let cwd = function():Directory {
return {
path: process.cwd()
}
};

View File

@ -1,59 +0,0 @@
/// <reference path="typings/main.d.ts" />
/// <reference path="./smartcli.interfaces.ts" />
import plugins = require("./smartcli.plugins");
/**
* executes callback with answer to question as argument
* @param questionString the question you want to ask the user
* @param cb the function to execute with answer as param
* @returns {null}
*/
export let getAnswer = function(questionString:string, cb) {
if (typeof questionString != 'string') {
plugins.beautylog.error('no question specified');
return null;
}
//make inquirer compatible question object
var question = {
type: "input",
name: "userFeedback",
message: questionString,
validate: function( value ) {
return true;
}
};
plugins.inquirer.prompt([question],function(answers){
var answer = answers.userFeedback;
cb(answer);
});
};
/**
*
* @param questionString
* @param choiceOptions
* @param cb
* @returns {null}
*/
export let getChoice = function(questionString:string, choiceOptions:string[], cb) {
if(!Array.isArray(choiceOptions)) {
return null;
}
//make inquirer compatible question object
var question = {
type: "list",
name: "userFeedback",
message: questionString,
choices: choiceOptions,
filter: function( val ) { return val.toLowerCase(); }
};
plugins.inquirer.prompt(question,function(answers){
var answer = answers.userFeedback;
cb(answer);
});
};

View File

@ -1,22 +0,0 @@
interface CliOption {
name: string;
specified:boolean;
value: any;
}
interface Directory {
path: string;
}
interface CliCommand {
specified: boolean;
name: string;
arguments:CliCommandArgument[];
}
interface CliCommandArgument {
specified:boolean;
name:string;
level:number;
}

View File

@ -1,8 +1,15 @@
/// <reference path="typings/main.d.ts" /> import 'typings-global'
export let path = require("path"); import * as yargs from 'yargs'
export let beautylog = require("beautylog"); import * as beautylog from 'beautylog'
export let cliff = require("cliff"); import * as lik from 'lik'
export let inquirer = require("inquirer"); import * as path from 'path'
export let smartparam = require("smartparam"); import * as smartparam from 'smartparam'
export let argv = require('yargs').argv;
export {
yargs,
beautylog,
lik,
path,
smartparam
}

View File

@ -1,6 +0,0 @@
{
"ambientDependencies": {
"mocha": "registry:dt/mocha#2.2.5+20151023103246",
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts"
}
}

View File

@ -1,2 +0,0 @@
/// <reference path="browser/ambient/mocha/index.d.ts" />
/// <reference path="browser/ambient/node/index.d.ts" />

View File

@ -1,2 +0,0 @@
/// <reference path="main/ambient/mocha/index.d.ts" />
/// <reference path="main/ambient/node/index.d.ts" />

3
tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}