Compare commits

..

23 Commits

Author SHA1 Message Date
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
20 changed files with 292 additions and 335 deletions

View File

@ -1,4 +1,4 @@
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-node:npmts
stages: stages:
- test - test
@ -40,7 +40,7 @@ pages:
image: hosttoday/ht-docker-node:npmpage image: hosttoday/ht-docker-node:npmpage
stage: page stage: page
script: script:
- npmci command npmts - npmci test stable
- npmci command npmpage --host gitlab - npmci command npmpage --host gitlab
only: only:
- tags - tags

View File

View File

@ -26,16 +26,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 +47,18 @@ 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.
``` ```
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

3
dist/index.d.ts vendored
View File

@ -1,2 +1 @@
import "typings-global"; export { Smartcli } from './smartcli.classes.smartcli';
export { Smartcli } from "./smartcli.classes.smartcli";

3
dist/index.js vendored
View File

@ -1,5 +1,4 @@
"use strict"; "use strict";
require("typings-global");
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBR3hCLDBDQUF1Qiw2QkFBNkIsQ0FBQztBQUE3Qyx3REFBNkMifQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEseUVBQXNEO0FBQTdDLCtDQUFBLFFBQVEsQ0FBQSJ9

View File

@ -1,32 +0,0 @@
import "typings-global";
/**
* allows to specify an user interaction during runtime
*/
export declare type questionType = "input" | "confirm" | "list" | "rawlist" | "expand" | "checkbox" | "password" | "editor";
export interface choiceObject {
name: string;
value: any;
}
export interface validateFunction {
(any: any): boolean;
}
export declare class Interaction {
constructor();
askQuestion(optionsArg: {
type: questionType;
message: string;
default: any;
choices: string[] | choiceObject[];
validate: validateFunction;
}): void;
askQuestionArray: any;
}
export declare class QuestionTree {
constructor(questionString: string, optionsArray: any);
}
export declare class QuestionTreeNode {
constructor();
}
export declare class QuestionStorage {
constructor();
}

View File

@ -1,41 +0,0 @@
"use strict";
require("typings-global");
const plugins = require("./smartcli.plugins");
class Interaction {
constructor() {
}
;
askQuestion(optionsArg) {
let done = plugins.q.defer();
plugins.inquirer.prompt([{
type: optionsArg.type,
message: optionsArg.message,
default: optionsArg.default,
choices: optionsArg.choices,
validate: optionsArg.validate
}]).then(answers => {
done.resolve(answers);
});
}
;
}
exports.Interaction = Interaction;
class QuestionTree {
constructor(questionString, optionsArray) {
}
;
}
exports.QuestionTree = QuestionTree;
;
class QuestionTreeNode {
constructor() {
}
}
exports.QuestionTreeNode = QuestionTreeNode;
;
class QuestionStorage {
constructor() {
}
}
exports.QuestionStorage = QuestionStorage;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWx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UVGO0lBQ0k7SUFFQSxDQUFDO0FBQ0wsQ0FBQztBQUpZLHVCQUFlLGtCQUkzQixDQUFBIn0=

View File

@ -1,10 +1,9 @@
/// <reference types="q" /> /// <reference types="q" />
import "typings-global"; import * as q from 'q';
import * as plugins from "./smartcli.plugins"; import { Objectmap } from 'lik';
import { Objectmap } from "lik"; export interface ICommandDeferredObject {
export interface commandPromiseObject {
commandName: string; commandName: string;
promise: plugins.q.Promise<any>; deferred: q.Deferred<any>;
} }
export declare class Smartcli { export declare class Smartcli {
argv: any; argv: any;
@ -13,7 +12,10 @@ export declare class Smartcli {
commands: any; commands: any;
questions: any; questions: any;
version: string; version: string;
allCommandPromises: Objectmap<commandPromiseObject>; /**
* map of all Command/Promise objects to keep track
*/
allCommandDeferredsMap: Objectmap<ICommandDeferredObject>;
constructor(); constructor();
/** /**
* adds an alias, meaning one equals the other in terms of triggering associated commands * adds an alias, meaning one equals the other in terms of triggering associated commands
@ -21,16 +23,20 @@ export declare class Smartcli {
addAlias(keyArg: any, aliasArg: any): void; addAlias(keyArg: any, aliasArg: any): void;
/** /**
* 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(definitionArg: { addCommand(definitionArg: {
commandName: string; commandName: string;
}): plugins.q.Promise<{}>; }): q.Promise<any>;
/** /**
* gets a Promise for a command word * gets a Promise for a command word
*/ */
getCommandPromiseByName(commandNameArg: string): plugins.q.Promise<any>; getCommandPromiseByName(commandNameArg: string): q.Promise<void>;
/**
* triggers a command by name
* @param commandNameArg - the name of the command to trigger
*/
triggerCommandByName(commandNameArg: string): q.Promise<any>;
/** /**
* 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
*/ */
@ -44,7 +50,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(): plugins.q.Promise<{}>; standardTask(): q.Promise<any>;
/** /**
* start the process of evaluating commands * start the process of evaluating commands
*/ */

View File

@ -1,35 +1,38 @@
"use strict"; "use strict";
require("typings-global"); const q = require("q");
const plugins = require("./smartcli.plugins"); const plugins = require("./smartcli.plugins");
// import classes // import classes
const lik_1 = require("lik"); const lik_1 = require("lik");
;
class Smartcli { class Smartcli {
constructor() { constructor() {
// maps /**
this.allCommandPromises = new lik_1.Objectmap(); * map of all Command/Promise objects to keep track
*/
this.allCommandDeferredsMap = new lik_1.Objectmap();
this.argv = plugins.yargs; this.argv = plugins.yargs;
this.questionsDone = plugins.q.defer(); this.questionsDone = q.defer();
this.parseStarted = plugins.q.defer(); this.parseStarted = q.defer();
} }
;
/** /**
* adds an alias, meaning one equals the other in terms of triggering associated commands * adds an alias, meaning one equals the other in terms of triggering associated commands
*/ */
addAlias(keyArg, aliasArg) { addAlias(keyArg, aliasArg) {
this.argv = this.argv.alias(keyArg, aliasArg); this.argv = this.argv.alias(keyArg, aliasArg);
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(definitionArg) { addCommand(definitionArg) {
let done = plugins.q.defer(); let done = q.defer();
this.allCommandDeferredsMap.add({
commandName: definitionArg.commandName,
deferred: done
});
this.parseStarted.promise this.parseStarted.promise
.then(() => { .then(() => {
if (this.argv._.indexOf(definitionArg.commandName) == 0) { if (this.argv._.indexOf(definitionArg.commandName) === 0) {
done.resolve(this.argv); done.resolve(this.argv);
} }
else { else {
@ -38,33 +41,41 @@ class Smartcli {
}); });
return done.promise; return done.promise;
} }
;
/** /**
* gets a Promise for a command word * gets a Promise for a command word
*/ */
getCommandPromiseByName(commandNameArg) { getCommandPromiseByName(commandNameArg) {
return this.allCommandPromises.find(commandPromiseObjectArg => { return this.allCommandDeferredsMap.find(commandDeferredObjectArg => {
return commandPromiseObjectArg.commandName === commandNameArg; return commandDeferredObjectArg.commandName === commandNameArg;
}).promise; }).deferred.promise;
}
/**
* triggers a command by name
* @param commandNameArg - the name of the command to trigger
*/
triggerCommandByName(commandNameArg) {
let commandDeferred = this.allCommandDeferredsMap.find(commandDeferredObjectArg => {
return commandDeferredObjectArg.commandName === commandNameArg;
}).deferred;
commandDeferred.resolve();
return commandDeferred.promise;
} }
;
/** /**
* 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) {
this.addCommand({ this.addCommand({
commandName: "help" commandName: 'help'
}).then(argvArg => { }).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) { addVersion(versionArg) {
this.version = versionArg; this.version = versionArg;
this.addAlias("v", "version"); this.addAlias('v', 'version');
this.parseStarted.promise this.parseStarted.promise
.then(() => { .then(() => {
if (this.argv.v) { if (this.argv.v) {
@ -72,21 +83,19 @@ 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 = plugins.q.defer(); let done = q.defer();
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;
} }
@ -96,7 +105,8 @@ class Smartcli {
startParse() { startParse() {
this.argv = this.argv.argv; this.argv = this.argv.argv;
this.parseStarted.resolve(); this.parseStarted.resolve();
return;
} }
} }
exports.Smartcli = Smartcli; exports.Smartcli = Smartcli;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic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PQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFBO1lBQzNCLENBQUM7WUFBQyxJQUFJLENBQUMsQ0FBQztnQkFDSixJQUFJLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQTtZQUMxQixDQUFDO1FBQ0wsQ0FBQyxDQUFDLENBQUE7UUFDTixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUN2QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxVQUFVO1FBQ04sSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQTtRQUMxQixJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQzNCLE1BQU0sQ0FBQTtJQUNWLENBQUM7Q0FFSjtBQXpIRCw0QkF5SEMifQ==

View File

@ -1,9 +1,7 @@
import "typings-global"; import 'typings-global';
export import yargs = require('yargs'); import * as yargs from 'yargs';
export import beautylog = require("beautylog"); import * as beautylog from 'beautylog';
export import cliff = require("cliff"); import * as lik from 'lik';
export import inquirer = require("inquirer"); import * as path from 'path';
export import lik = require("lik"); import * as smartparam from 'smartparam';
export import path = require("path"); export { yargs, beautylog, lik, path, smartparam };
export import q = require("q");
export import smartparam = require("smartparam");

View File

@ -1,11 +1,13 @@
"use strict"; "use strict";
require("typings-global"); require("typings-global");
exports.yargs = require('yargs'); const yargs = require("yargs");
exports.beautylog = require("beautylog"); exports.yargs = yargs;
exports.cliff = require("cliff"); const beautylog = require("beautylog");
exports.inquirer = require("inquirer"); exports.beautylog = beautylog;
exports.lik = require("lik"); const lik = require("lik");
exports.path = require("path"); exports.lik = lik;
exports.q = require("q"); const path = require("path");
exports.smartparam = require("smartparam"); exports.path = path;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUVWLGFBQUssV0FBVyxPQUFPLENBQUMsQ0FBQztBQUN6QixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLGFBQUssV0FBVyxPQUFPLENBQUMsQ0FBQztBQUN6QixnQkFBUSxXQUFXLFVBQVUsQ0FBQyxDQUFDO0FBQy9CLFdBQUcsV0FBVyxLQUFLLENBQUMsQ0FBQztBQUNyQixZQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDdkIsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGtCQUFVLFdBQVcsWUFBWSxDQUFDLENBQUMifQ== const smartparam = require("smartparam");
exports.smartparam = smartparam;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QjtBQUV4QiwrQkFBOEI7QUFPMUIsc0JBQUs7QUFOVCx1Q0FBc0M7QUFPbEMsOEJBQVM7QUFOYiwyQkFBMEI7QUFPdEIsa0JBQUc7QUFOUCw2QkFBNEI7QUFPeEIsb0JBQUk7QUFOUix5Q0FBd0M7QUFPcEMsZ0NBQVUifQ==

View File

@ -1,6 +1,6 @@
{ {
"name": "smartcli", "name": "smartcli",
"version": "1.0.6", "version": "1.0.16",
"description": "nodejs wrapper for CLI related tasks", "description": "nodejs wrapper for CLI related tasks",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
@ -17,33 +17,31 @@
"url": "https://gitlab.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://gitlab.com/pushrocks/smartcli/issues" "url": "https://gitlab.com/pushrocks/smartcli/issues"
}, },
"homepage": "https://gitlab.com/pushrocks/smartcli", "homepage": "https://gitlab.com/pushrocks/smartcli",
"dependencies": { "dependencies": {
"@types/cliff": "^0.1.3",
"@types/inquirer": "0.x.x",
"@types/q": "0.x.x", "@types/q": "0.x.x",
"@types/yargs": "0.x.x", "@types/yargs": "6.x.x",
"beautylog": "^5.0.20", "beautylog": "^6.0.0",
"cliff": "^0.1.10", "lik": "^1.0.24",
"inquirer": "^1.1.2",
"lik": "^1.0.15",
"q": "^1.4.1", "q": "^1.4.1",
"smartparam": "0.1.1", "smartparam": "0.1.1",
"typings-global": "^1.0.6", "typings-global": "^1.0.14",
"yargs": "^5.0.0" "yargs": "^6.4.0"
}, },
"devDependencies": { "devDependencies": {
"@types/should": "^8.1.30",
"npmts-g": "^5.2.8", "npmts-g": "^5.2.8",
"should": "^11.1.0", "should": "^11.1.1",
"typings-test": "^1.0.1" "typings-test": "^1.0.3"
} }
} }

2
test/test.d.ts vendored
View File

@ -1 +1 @@
import "typings-test"; import 'typings-test';

View File

@ -1,36 +1,55 @@
"use strict"; "use strict";
require("typings-test"); require("typings-test");
const smartcli = require("../dist/index"); const smartcli = require("../dist/index");
let beautylog = require("beautylog"); const should = require("should");
let should = require("should"); describe('smartcli.Smartcli class', function () {
describe("smartcli.Smartcli class", function () {
let smartCliTestObject; let smartCliTestObject;
describe("new Smartcli()", function () { describe('new Smartcli()', function () {
it("should create a new Smartcli", function () { it('should create a new Smartcli', function () {
smartCliTestObject = new smartcli.Smartcli(); smartCliTestObject = new smartcli.Smartcli();
smartCliTestObject.should.be.instanceof(smartcli.Smartcli); should(smartCliTestObject).be.instanceof(smartcli.Smartcli);
}); });
}); });
describe(".addCommand", function () { describe('.addCommand', function () {
it("should add an command", function () { it('should add an command', function () {
smartCliTestObject.addCommand({ smartCliTestObject.addCommand({
commandName: "awesome" commandName: 'awesome'
}); });
}); });
}); });
describe(".standardTask", function () { describe('.standardTask', function () {
it("should start parsing a standardTask", function (done) { 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(); done();
}); });
}); });
describe(".startParse", function () { describe('.triggerCommandByName', function () {
it("should start parsing the CLI input", function () { let hasExecuted = false;
it('should accept a command', function (done) {
smartCliTestObject.addCommand({ commandName: 'triggerme' })
.then(argvArg => {
hasExecuted = true;
});
done();
});
it('should not have executed yet', function () {
should(hasExecuted).be.false();
});
it('should execute when triggered', function (done) {
smartCliTestObject.triggerCommandByName('triggerme')
.then(argvArg => {
should(hasExecuted).be.true();
done();
}).catch(err => { done(err); });
});
});
describe('.startParse', function () {
it('should start parsing the CLI input', function () {
smartCliTestObject.startParse(); smartCliTestObject.startParse();
}); });
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFFdEIsTUFBTyxRQUFRLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDM0MsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ3JDLElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUUvQixRQUFRLENBQUMseUJBQXlCLEVBQU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LENBQUE7UUFDbkMsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=

View File

@ -1,37 +1,55 @@
import "typings-test"; import 'typings-test'
import smartcli = require("../dist/index"); import smartcli = require('../dist/index')
let beautylog = require("beautylog"); import * as should from 'should'
let should = require("should");
describe("smartcli.Smartcli class",function(){ describe('smartcli.Smartcli class',function(){
let smartCliTestObject:smartcli.Smartcli; let smartCliTestObject: smartcli.Smartcli
describe("new Smartcli()",function(){ describe('new Smartcli()',function(){
it("should create a new Smartcli",function(){ it('should create a new Smartcli',function(){
smartCliTestObject = new smartcli.Smartcli(); smartCliTestObject = new smartcli.Smartcli()
smartCliTestObject.should.be.instanceof(smartcli.Smartcli); should(smartCliTestObject).be.instanceof(smartcli.Smartcli)
}); })
}); })
describe(".addCommand",function(){ describe('.addCommand',function(){
it("should add an command",function(){ it('should add an command',function(){
smartCliTestObject.addCommand({ smartCliTestObject.addCommand({
commandName:"awesome" commandName: 'awesome'
}); })
})
}); })
}); describe('.standardTask',function(){
describe(".standardTask",function(){ it('should start parsing a standardTask',function(done){
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(); done()
}) })
}) })
describe(".startParse",function(){ describe('.triggerCommandByName', function() {
it("should start parsing the CLI input",function(){ let hasExecuted = false
smartCliTestObject.startParse(); it('should accept a command', function(done) {
smartCliTestObject.addCommand({commandName: 'triggerme'})
.then(argvArg => {
hasExecuted = true
})
done()
})
it('should not have executed yet', function() {
should(hasExecuted).be.false()
})
it('should execute when triggered', function(done) {
smartCliTestObject.triggerCommandByName('triggerme')
.then(argvArg => {
should(hasExecuted).be.true()
done()
}).catch(err => { done(err) })
}) })
}) })
}); describe('.startParse',function(){
it('should start parsing the CLI input',function(){
smartCliTestObject.startParse()
})
})
})

View File

@ -1,4 +1 @@
import "typings-global"; export { Smartcli } from './smartcli.classes.smartcli'
import {Smartcli} from "./smartcli.classes.smartcli";
export {Smartcli} from "./smartcli.classes.smartcli";

View File

@ -1,60 +0,0 @@
import "typings-global";
import * as plugins from "./smartcli.plugins";
/**
* allows to specify an user interaction during runtime
*/
export type questionType = "input" | "confirm" | "list" | "rawlist" | "expand" | "checkbox" | "password" | "editor"
export interface choiceObject {
name: string;
value: any
}
export interface validateFunction {
(any):boolean
}
export class Interaction {
constructor() {
};
askQuestion(optionsArg: {
type: questionType,
message: string
default: any
choices: string[] | choiceObject[];
validate: validateFunction
}) {
let done = plugins.q.defer();
plugins.inquirer.prompt([{
type: optionsArg.type,
message: optionsArg.message,
default: optionsArg.default,
choices:optionsArg.choices,
validate: optionsArg.validate
}]).then(answers => {
done.resolve(answers);
});
};
askQuestionArray
}
export class QuestionTree {
constructor(questionString: string, optionsArray) {
};
};
export class QuestionTreeNode {
constructor() {
}
};
export class QuestionStorage {
constructor() {
}
}

View File

@ -1,116 +1,135 @@
import "typings-global"; import * as q from 'q'
import * as plugins from "./smartcli.plugins"; import * as plugins from './smartcli.plugins'
import * as interaction from "./smartcli.classes.interaction";
// import classes // import classes
import {Objectmap} from "lik"; import {Objectmap} from 'lik'
// interfaces // interfaces
export interface commandPromiseObject { export interface ICommandDeferredObject {
commandName:string; commandName: string
promise: plugins.q.Promise<any>; deferred: q.Deferred<any>
}; }
export class Smartcli { export class Smartcli {
argv:any; argv: any
questionsDone; questionsDone
parseStarted; parseStarted
commands; commands
questions; questions
version:string; version: string
// maps /**
allCommandPromises = new Objectmap<commandPromiseObject>(); * map of all Command/Promise objects to keep track
constructor(){ */
this.argv = plugins.yargs; allCommandDeferredsMap = new Objectmap<ICommandDeferredObject>()
this.questionsDone = plugins.q.defer();
this.parseStarted = plugins.q.defer(); constructor() {
}; this.argv = plugins.yargs
this.questionsDone = q.defer()
this.parseStarted = q.defer()
}
/** /**
* adds an alias, meaning one equals the other in terms of triggering associated commands * adds an alias, meaning one equals the other in terms of triggering associated commands
*/ */
addAlias(keyArg,aliasArg){ addAlias(keyArg,aliasArg): void {
this.argv = this.argv.alias(keyArg,aliasArg); this.argv = this.argv.alias(keyArg,aliasArg)
}; 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(definitionArg:{commandName:string}){ addCommand(definitionArg: {commandName: string}): q.Promise<any> {
let done = plugins.q.defer(); let done = q.defer<any>()
this.allCommandDeferredsMap.add({
commandName: definitionArg.commandName,
deferred: done
})
this.parseStarted.promise this.parseStarted.promise
.then(() => { .then(() => {
if (this.argv._.indexOf(definitionArg.commandName) == 0) { if (this.argv._.indexOf(definitionArg.commandName) === 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){ getCommandPromiseByName(commandNameArg: string): q.Promise<void> {
return this.allCommandPromises.find(commandPromiseObjectArg => { return this.allCommandDeferredsMap.find(commandDeferredObjectArg => {
return commandPromiseObjectArg.commandName === commandNameArg; return commandDeferredObjectArg.commandName === commandNameArg
}).promise; }).deferred.promise
}; }
/**
* triggers a command by name
* @param commandNameArg - the name of the command to trigger
*/
triggerCommandByName(commandNameArg: string) {
let commandDeferred = this.allCommandDeferredsMap.find(commandDeferredObjectArg => {
return commandDeferredObjectArg.commandName === commandNameArg
}).deferred
commandDeferred.resolve()
return commandDeferred.promise
}
/** /**
* 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({ this.addCommand({
commandName:"help" commandName: 'help'
}).then(argvArg => { }).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.addAlias("v","version"); this.addAlias('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(){ standardTask(): q.Promise<any> {
let done = plugins.q.defer(); let done = q.defer<any>()
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(){ startParse(): void {
this.argv = this.argv.argv; this.argv = this.argv.argv
this.parseStarted.resolve(); this.parseStarted.resolve()
return
} }
} }

View File

@ -1,10 +1,15 @@
import "typings-global"; import 'typings-global';
export import yargs = require('yargs'); import * as yargs from 'yargs'
export import beautylog = require("beautylog"); import * as beautylog from 'beautylog'
export import cliff = require("cliff"); import * as lik from 'lik'
export import inquirer = require("inquirer"); import * as path from 'path'
export import lik = require("lik"); import * as smartparam from 'smartparam'
export import path = require("path");
export import q = require("q"); export {
export import smartparam = require("smartparam"); yargs,
beautylog,
lik,
path,
smartparam
}

3
tslint.json Normal file
View File

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