update to latest standards

This commit is contained in:
Philipp Kunz 2017-04-22 21:03:28 +02:00
parent 089787454a
commit f0f1f9b86f
15 changed files with 2296 additions and 347 deletions

View File

@ -1,64 +1,26 @@
# smartcli # smartcli
nodejs wrapper for CLI related tasks. TypeScript ready. nodejs wrapper for CLI related tasks
## Availabililty ## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartcli) [![npm](https://pushrocks.gitlab.io/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://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartcli)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartcli) [![git](https://pushrocks.gitlab.io/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) [![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartcli/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/smartcli/badges/master/build.svg)](https://gitlab.com/pushrocks/smartcli/commits/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) [![coverage report](https://GitLab.com/pushrocks/smartcli/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartcli/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartcli.svg)](https://www.npmjs.com/package/smartcli)
[![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 Dependencies](https://www.bithound.io/github/pushrocks/smartcli/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartcli/master/dependencies/npm) [![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/) [![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/) [![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Install the package For further information read the linked docs at the top of this README.
npm install smartcli --save
## Usage > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
this plugin tries to establish some logic in which CLI tools work. [![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://)
take the following commandline input:
```
mytool command argument1 argument2 --option1 -o2 option2Value
```
* `mytool` obviously is the tool (like git)
* `command` 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)
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.
```javascript
import {Smartcli} from "smartcli"
mySmartcli = new Smartcli();
mySmartcli.standardTask()
.then(argvArg => {
// do something if program is called without an command
});
mySmartcli.addCommand({commandname: 'install'})
.then(argvArg => {
// do something if program is called with command "install"
})
mySmartcli.addVersion('1.0.0') // -v and --version options will display the specified version in the terminal
mySmartCli.addHelp({ // is triggered by help command and --help option
helpText: 'some help text to print' // the helpText to display
})
mySmartcli.startParse() // starts the evaluation and fullfills or rejects promises.
```
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

3
dist/index.js vendored
View File

@ -1,4 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var smartcli_classes_smartcli_1 = require("./smartcli.classes.smartcli"); var smartcli_classes_smartcli_1 = require("./smartcli.classes.smartcli");
exports.Smartcli = smartcli_classes_smartcli_1.Smartcli; exports.Smartcli = smartcli_classes_smartcli_1.Smartcli;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEseUVBQXNEO0FBQTdDLCtDQUFBLFFBQVEsQ0FBQSJ9 //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHlFQUFzRDtBQUE3QywrQ0FBQSxRQUFRLENBQUEifQ==

View File

@ -1,10 +1,8 @@
/// <reference types="q" />
import * as q from 'q';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { Objectmap } from 'lik'; import { Objectmap } from 'lik';
export interface ICommandPromiseObject { export interface ICommandPromiseObject {
commandName: string; commandName: string;
promise: q.Promise<void>; promise: Promise<void>;
} }
export interface ITriggerObservableObject { export interface ITriggerObservableObject {
triggerName: string; triggerName: string;
@ -34,11 +32,11 @@ export declare class Smartcli {
* adds a Command by returning a Promise that reacts to the specific commandString given. * 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. * Note: in e.g. "npm install something" the "install" is considered the command.
*/ */
addCommand(commandNameArg: string): q.Promise<any>; addCommand(commandNameArg: string): Promise<any>;
/** /**
* gets a Promise for a command word * gets a Promise for a command word
*/ */
getCommandPromiseByName(commandNameArg: string): q.Promise<void>; getCommandPromiseByName(commandNameArg: string): Promise<void>;
/** /**
* adds a Trigger. Like addCommand(), but returns an subscribable observable * adds a Trigger. Like addCommand(), but returns an subscribable observable
*/ */
@ -61,7 +59,7 @@ export declare class Smartcli {
/** /**
* returns promise that is resolved when no commands are specified * returns promise that is resolved when no commands are specified
*/ */
standardTask(): q.Promise<any>; standardTask(): Promise<any>;
/** /**
* start the process of evaluating commands * start the process of evaluating commands
*/ */

View File

@ -1,5 +1,6 @@
"use strict"; "use strict";
const q = require("q"); Object.defineProperty(exports, "__esModule", { value: true });
const smartq = require("smartq");
const rxjs_1 = require("rxjs"); const rxjs_1 = require("rxjs");
const plugins = require("./smartcli.plugins"); const plugins = require("./smartcli.plugins");
// import classes // import classes
@ -15,8 +16,8 @@ class Smartcli {
*/ */
this.allTriggerObservablesMap = new lik_1.Objectmap(); this.allTriggerObservablesMap = new lik_1.Objectmap();
this.argv = plugins.yargs; this.argv = plugins.yargs;
this.questionsDone = q.defer(); this.questionsDone = smartq.defer();
this.parseStarted = q.defer(); this.parseStarted = smartq.defer();
} }
/** /**
* adds an alias, meaning one equals the other in terms of command execution. * adds an alias, meaning one equals the other in terms of command execution.
@ -30,7 +31,7 @@ class Smartcli {
* Note: in e.g. "npm install something" the "install" is considered the command. * Note: in e.g. "npm install something" the "install" is considered the command.
*/ */
addCommand(commandNameArg) { addCommand(commandNameArg) {
let done = q.defer(); let done = smartq.defer();
this.allCommandPromisesMap.add({ this.allCommandPromisesMap.add({
commandName: commandNameArg, commandName: commandNameArg,
promise: done.promise promise: done.promise
@ -104,7 +105,7 @@ class Smartcli {
* returns promise that is resolved when no commands are specified * returns promise that is resolved when no commands are specified
*/ */
standardTask() { standardTask() {
let done = q.defer(); let done = smartq.defer();
this.allCommandPromisesMap.add({ this.allCommandPromisesMap.add({
commandName: 'standard', commandName: 'standard',
promise: done.promise promise: done.promise
@ -130,4 +131,4 @@ class Smartcli {
} }
} }
exports.Smartcli = Smartcli; exports.Smartcli = Smartcli;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHVCQUFzQjtBQUN0QiwrQkFBOEI7QUFFOUIsOENBQTZDO0FBRTdDLGlCQUFpQjtBQUNqQiw2QkFBK0I7QUFhL0I7SUFrQkk7UUFWQTs7V0FFRztRQUNILDBCQUFxQixHQUFHLElBQUksZUFBUyxFQUF5QixDQUFBO1FBRTlEOztXQUVHO1FBQ0gsNkJBQXdCLEdBQUcsSUFBSSxlQUFTLEVBQTRCLENBQUE7UUFHaEUsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsS0FBSyxDQUFBO1FBQ3pCLElBQUksQ0FBQyxhQUFhLEdBQUcsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQzlCLElBQUksQ0FBQyxZQUFZLEdBQUcsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO0lBQ2pDLENBQUM7SUFFRDs7T0FFRztJQUNILGVBQWUsQ0FBQyxNQUFNLEVBQUMsUUFBUTtRQUMzQixJQUFJLENBQUMsSUFBSSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLE1BQU0sRUFBQyxRQUFRLENBQUMsQ0FBQTtRQUM1QyxNQUFNLENBQUE7SUFDVixDQUFDO0lBRUQ7OztPQUdHO0lBQ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xDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQTtRQUMxQixJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQzNCLE1BQU0sQ0FBQTtJQUNSLENBQUM7Q0FFRjtBQS9JRCw0QkErSUMifQ==

View File

@ -1,4 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global"); require("typings-global");
const yargs = require("yargs"); const yargs = require("yargs");
exports.yargs = yargs; exports.yargs = yargs;
@ -10,4 +11,4 @@ const path = require("path");
exports.path = path; exports.path = path;
const smartparam = require("smartparam"); const smartparam = require("smartparam");
exports.smartparam = smartparam; exports.smartparam = smartparam;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUV2QiwrQkFBOEI7QUFPMUIsc0JBQUs7QUFOVCx1Q0FBc0M7QUFPbEMsOEJBQVM7QUFOYiwyQkFBMEI7QUFPdEIsa0JBQUc7QUFOUCw2QkFBNEI7QUFPeEIsb0JBQUk7QUFOUix5Q0FBd0M7QUFPcEMsZ0NBQVUifQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFFdkIsK0JBQThCO0FBTzVCLHNCQUFLO0FBTlAsdUNBQXNDO0FBT3BDLDhCQUFTO0FBTlgsMkJBQTBCO0FBT3hCLGtCQUFHO0FBTkwsNkJBQTRCO0FBTzFCLG9CQUFJO0FBTk4seUNBQXdDO0FBT3RDLGdDQUFVIn0=

View File

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

View File

@ -1,23 +1,22 @@
# smartcli # smartcli
nodejs wrapper for CLI related tasks. TypeScript ready. nodejs wrapper for CLI related tasks
## Availabililty ## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartcli) [![npm](https://pushrocks.gitlab.io/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://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartcli)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartcli) [![git](https://pushrocks.gitlab.io/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) [![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartcli/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/smartcli/badges/master/build.svg)](https://gitlab.com/pushrocks/smartcli/commits/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) [![coverage report](https://GitLab.com/pushrocks/smartcli/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartcli/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartcli.svg)](https://www.npmjs.com/package/smartcli)
[![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 Dependencies](https://www.bithound.io/github/pushrocks/smartcli/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartcli/master/dependencies/npm) [![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/) [![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/) [![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Install the package
npm install smartcli --save
## Usage ## Usage
@ -26,16 +25,20 @@ 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 -o2 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)
* argument1 and argument2 are arguments * `argument1` and `argument2` are arguments
* option1 is a longform option you can add (like --message for message) * `option1` is a longform option you can add (like --message for message)
* optionValue is the referenced option value (like a commit message) * `optionValue` is the referenced option value (like a commit message)
```typescript 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.
```javascript
import {Smartcli} from "smartcli" import {Smartcli} from "smartcli"
mySmartcli = new Smartcli(); mySmartcli = new Smartcli();
mySmartcli.standardTask() mySmartcli.standardTask()
@ -43,5 +46,23 @@ mySmartcli.standardTask()
// do something if program is called without an command // do something if program is called without an command
}); });
mySmartcli.question mySmartcli.addCommand({commandname: 'install'})
``` .then(argvArg => {
// do something if program is called with command "install"
})
mySmartcli.addVersion('1.0.0') // -v and --version options will display the specified version in the terminal
mySmartCli.addHelp({ // is triggered by help command and --help option
helpText: 'some help text to print' // the helpText to display
})
mySmartcli.startParse() // starts the evaluation and fullfills or rejects promises.
```
For further information read the linked docs at the top of this README.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

@ -29,20 +29,16 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartcli", "homepage": "https://gitlab.com/pushrocks/smartcli",
"dependencies": { "dependencies": {
"@types/q": "0.x.x",
"@types/yargs": "6.x.x", "@types/yargs": "6.x.x",
"beautylog": "^6.0.0", "beautylog": "^6.1.10",
"lik": "^1.0.24", "lik": "^1.0.30",
"q": "^1.4.1", "rxjs": "^5.3.0",
"rxjs": "^5.0.1",
"smartparam": "0.1.1", "smartparam": "0.1.1",
"smartq": "^1.1.1",
"typings-global": "^1.0.14", "typings-global": "^1.0.14",
"yargs": "^6.4.0" "yargs": "^7.1.0"
}, },
"devDependencies": { "devDependencies": {
"@types/should": "^8.1.30", "tapbundle": "^1.0.5"
"npmts-g": "^5.2.8",
"should": "^11.1.1",
"typings-test": "^1.0.3"
} }
} }

1
test/test.d.ts vendored
View File

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

View File

@ -1,51 +0,0 @@
"use strict";
require("typings-test");
const smartcli = require("../dist/index");
const should = require("should");
describe('smartcli.Smartcli class', function () {
let smartCliTestObject;
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();
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQiwwQ0FBMEM7QUFDMUMsaUNBQWdDO0FBRWhDLFFBQVEsQ0FBQyx5QkFBeUIsRUFBQztJQUMvQixJQUFJLGtCQUFxQyxDQUFBO0lBQ3pDLFFBQVEsQ0FBQyxnQkFBZ0IsRUFBQztRQUN0QixFQUFFLENBQUMsOEJBQThCLEVBQUM7WUFDOUIsa0JBQWtCLEdBQUcsSUFBSSxRQUFRLENBQUMsUUFBUSxFQUFFLENBQUE7WUFDNUMsTUFBTSxDQUFDLGtCQUFrQixDQUFDLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxRQUFRLENBQUMsUUFBUSxDQUFDLENBQUE7UUFDL0QsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtJQUNGLFFBQ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AAC;AACF,aAAa,EAAE,CAAC;AAEhB,IAAI,UAAU,GAAG;IACb,SAAS,CAAC,IAAI,CAAC,4BAA4B,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AAC3E,CAAC,CAAC;AACF,UAAU,EAAE,CAAC;AAGb;;wEAEwE;AAGxE,IAAI,wBAAwB,GAAG;IAC3B,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,kBAAkB,EAAC,UAAS,MAAM;QAC7D,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,MAAM,CAAC,CAAC;QACxC,wBAAwB,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAIF,IAAI,wBAAwB,GAAG;IAC3B,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,iCAAiC,EAAC,CAAC,MAAM,EAAC,OAAO,EAAC,WAAW,CAAC,EAAC,UAAS,MAAM;QACzG,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,MAAM,CAAC,CAAC;QACxC,QAAQ,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,IAAI,QAAQ,GAAG;IACX,SAAS,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC;IAC/B,SAAS,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF,EAAE,CAAA,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA,CAAC;IACjC,wBAAwB,EAAE,CAAC;AAC/B,CAAC;AAAC,IAAI,CAAC,CAAC;IACJ,SAAS,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAC;IAC3F,QAAQ,EAAE,CAAC;AACf,CAAC;AAAA,CAAC"}

View File

@ -1,51 +1,44 @@
import 'typings-test' import { tap, expect } from 'tapbundle'
import smartcli = require('../dist/index') import smartcli = require('../dist/index')
import * as should from 'should'
describe('smartcli.Smartcli class',function(){ let smartCliTestObject: smartcli.Smartcli
let smartCliTestObject: smartcli.Smartcli
describe('new Smartcli()',function(){ tap.test('should create a new Smartcli', async () => {
it('should create a new Smartcli',function(){ smartCliTestObject = new smartcli.Smartcli()
smartCliTestObject = new smartcli.Smartcli() return expect(smartCliTestObject).be.instanceof(smartcli.Smartcli)
should(smartCliTestObject).be.instanceof(smartcli.Smartcli) })
})
})
describe('.addCommand',function(){ tap.test('should add an command', async () => {
it('should add an command',function(){ smartCliTestObject.addCommand('awesome')
smartCliTestObject.addCommand('awesome') })
})
})
describe('.standardTask',function(){ tap.test('should start parsing a standardTask', async () => {
it('should start parsing a standardTask',function(done){ smartCliTestObject.standardTask()
smartCliTestObject.standardTask() .then(() => {
.then(() => { console.log('this is the standard Task!')
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()
})
}) })
}) })
let hasExecuted: boolean = false
tap.test('should accept a command', async () => {
smartCliTestObject.addTrigger('triggerme')
.subscribe(() => {
hasExecuted = true
})
})
tap.test('should not have executed yet', async () => {
expect(hasExecuted).to.be.false
})
tap.test('should execute when triggered', async () => {
smartCliTestObject.trigger('triggerme')
expect(hasExecuted).be.true
})
tap.test('should start parsing the CLI input', async () => {
smartCliTestObject.startParse()
})

View File

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

View File

@ -7,9 +7,9 @@ import * as path from 'path'
import * as smartparam from 'smartparam' import * as smartparam from 'smartparam'
export { export {
yargs, yargs,
beautylog, beautylog,
lik, lik,
path, path,
smartparam smartparam
} }

2044
yarn.lock Normal file

File diff suppressed because it is too large Load Diff