Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
089787454a | |||
f8a122b777 | |||
c6db092062 | |||
857d31dcb2 | |||
e257a38688 | |||
19a5082381 | |||
00f5539e6b | |||
cacb0221f1 | |||
b98b90163d | |||
daa6312aea | |||
7f2dab091f | |||
dd293875c4 | |||
120eca42ac | |||
fc289616f6 | |||
e7c1c1c45b | |||
f33c759fa8 | |||
1185df362b | |||
36de8e11f0 | |||
74ffb3aa87 |
28
README.md
28
README.md
@ -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()
|
||||||
@ -47,4 +51,14 @@ mySmartcli.addCommand({commandname: 'install'})
|
|||||||
.then(argvArg => {
|
.then(argvArg => {
|
||||||
// do something if program is called with command "install"
|
// 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.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
||||||
|
31
dist/smartcli.classes.interaction.d.ts
vendored
31
dist/smartcli.classes.interaction.d.ts
vendored
@ -1,31 +0,0 @@
|
|||||||
/**
|
|
||||||
* allows to specify an user interaction during runtime
|
|
||||||
*/
|
|
||||||
export declare type questionType = 'input' | 'confirm' | 'list' | 'rawlist' | 'expand' | 'checkbox' | 'password' | 'editor';
|
|
||||||
export interface IChoiceObject {
|
|
||||||
name: string;
|
|
||||||
value: any;
|
|
||||||
}
|
|
||||||
export interface IValidateFunction {
|
|
||||||
(any: any): boolean;
|
|
||||||
}
|
|
||||||
export declare class Interaction {
|
|
||||||
constructor();
|
|
||||||
askQuestion(optionsArg: {
|
|
||||||
type: questionType;
|
|
||||||
message: string;
|
|
||||||
default: any;
|
|
||||||
choices: string[] | IChoiceObject[];
|
|
||||||
validate: IValidateFunction;
|
|
||||||
}): void;
|
|
||||||
askQuestionArray: any;
|
|
||||||
}
|
|
||||||
export declare class QuestionTree {
|
|
||||||
constructor(questionString: string, optionsArray: any);
|
|
||||||
}
|
|
||||||
export declare class QuestionTreeNode {
|
|
||||||
constructor();
|
|
||||||
}
|
|
||||||
export declare class QuestionStorage {
|
|
||||||
constructor();
|
|
||||||
}
|
|
35
dist/smartcli.classes.interaction.js
vendored
35
dist/smartcli.classes.interaction.js
vendored
@ -1,35 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5pbnRlcmFjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuaW50ZXJhY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDhDQUE2QztBQWU3QztJQUNJO0lBQ0EsQ0FBQztJQUVELFdBQVcsQ0FBQyxVQU1YO1FBQ0csSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUM1QixPQUFPLENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQyxDQUFDO2dCQUNyQixJQUFJLEVBQUUsVUFBVSxDQUFDLElBQUk7Z0JBQ3JCLE9BQU8sRUFBRSxVQUFVLENBQUMsT0FBTztnQkFDM0IsT0FBTyxFQUFFLFVBQVUsQ0FBQyxPQUFPO2dCQUMzQixPQUFPLEVBQUUsVUFBVSxDQUFDLE9BQU87Z0JBQzNCLFFBQVEsRUFBRSxVQUFVLENBQUMsUUFBUTthQUNoQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsT0FBTztZQUNaLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7UUFDekIsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDO0NBRUo7QUF2QkQsa0NBdUJDO0FBR0Q7SUFFSSxZQUFZLGNBQXNCLEVBQUUsWUFBWTtJQUVoRCxDQUFDO0NBQ0o7QUFMRCxvQ0FLQztBQUVEO0lBQ0k7SUFFQSxDQUFDO0NBQ0o7QUFKRCw0Q0FJQztBQUVEO0lBQ0k7SUFFQSxDQUFDO0NBQ0o7QUFKRCwwQ0FJQyJ9
|
|
35
dist/smartcli.classes.smartcli.d.ts
vendored
35
dist/smartcli.classes.smartcli.d.ts
vendored
@ -1,9 +1,14 @@
|
|||||||
/// <reference types="q" />
|
/// <reference types="q" />
|
||||||
import * as q from 'q';
|
import * as q from 'q';
|
||||||
|
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<any>;
|
promise: q.Promise<void>;
|
||||||
|
}
|
||||||
|
export interface ITriggerObservableObject {
|
||||||
|
triggerName: string;
|
||||||
|
subject: Subject<any>;
|
||||||
}
|
}
|
||||||
export declare class Smartcli {
|
export declare class Smartcli {
|
||||||
argv: any;
|
argv: any;
|
||||||
@ -12,23 +17,37 @@ export declare class Smartcli {
|
|||||||
commands: any;
|
commands: any;
|
||||||
questions: any;
|
questions: any;
|
||||||
version: string;
|
version: string;
|
||||||
allCommandPromises: Objectmap<ICommandPromiseObject>;
|
/**
|
||||||
|
* 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();
|
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 command execution.
|
||||||
*/
|
*/
|
||||||
addAlias(keyArg: any, aliasArg: any): void;
|
addCommandAlias(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(commandNameArg: string): q.Promise<any>;
|
||||||
commandName: string;
|
|
||||||
}): q.Promise<any>;
|
|
||||||
/**
|
/**
|
||||||
* gets a Promise for a command word
|
* gets a Promise for a command word
|
||||||
*/
|
*/
|
||||||
getCommandPromiseByName(commandNameArg: string): q.Promise<any>;
|
getCommandPromiseByName(commandNameArg: string): q.Promise<void>;
|
||||||
|
/**
|
||||||
|
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
||||||
|
*/
|
||||||
|
addTrigger(triggerNameArg: string): Subject<any>;
|
||||||
|
/**
|
||||||
|
* execute trigger by name
|
||||||
|
* @param commandNameArg - the name of the command to trigger
|
||||||
|
*/
|
||||||
|
trigger(triggerName: string): Subject<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
|
||||||
*/
|
*/
|
||||||
|
64
dist/smartcli.classes.smartcli.js
vendored
64
dist/smartcli.classes.smartcli.js
vendored
@ -1,20 +1,27 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const q = require("q");
|
const q = require("q");
|
||||||
|
const rxjs_1 = require("rxjs");
|
||||||
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.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.argv = plugins.yargs;
|
||||||
this.questionsDone = q.defer();
|
this.questionsDone = q.defer();
|
||||||
this.parseStarted = 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 command execution.
|
||||||
*/
|
*/
|
||||||
addAlias(keyArg, aliasArg) {
|
addCommandAlias(keyArg, aliasArg) {
|
||||||
this.argv = this.argv.alias(keyArg, aliasArg);
|
this.argv = this.argv.alias(keyArg, aliasArg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -22,11 +29,15 @@ 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(definitionArg) {
|
addCommand(commandNameArg) {
|
||||||
let done = q.defer();
|
let done = q.defer();
|
||||||
|
this.allCommandPromisesMap.add({
|
||||||
|
commandName: commandNameArg,
|
||||||
|
promise: done.promise
|
||||||
|
});
|
||||||
this.parseStarted.promise
|
this.parseStarted.promise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (this.argv._.indexOf(definitionArg.commandName) === 0) {
|
if (this.argv._.indexOf(commandNameArg) === 0) {
|
||||||
done.resolve(this.argv);
|
done.resolve(this.argv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -39,17 +50,40 @@ class Smartcli {
|
|||||||
* 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.allCommandPromisesMap.find(commandDeferredObjectArg => {
|
||||||
return commandPromiseObjectArg.commandName === commandNameArg;
|
return commandDeferredObjectArg.commandName === commandNameArg;
|
||||||
}).promise;
|
}).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(this.argv);
|
||||||
|
});
|
||||||
|
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(this.argv);
|
||||||
|
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) {
|
||||||
this.addCommand({
|
this.addCommand('help').then(argvArg => {
|
||||||
commandName: 'help'
|
|
||||||
}).then(argvArg => {
|
|
||||||
plugins.beautylog.log(optionsArg.helpText);
|
plugins.beautylog.log(optionsArg.helpText);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -58,7 +92,7 @@ class Smartcli {
|
|||||||
*/
|
*/
|
||||||
addVersion(versionArg) {
|
addVersion(versionArg) {
|
||||||
this.version = versionArg;
|
this.version = versionArg;
|
||||||
this.addAlias('v', 'version');
|
this.addCommandAlias('v', 'version');
|
||||||
this.parseStarted.promise
|
this.parseStarted.promise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (this.argv.v) {
|
if (this.argv.v) {
|
||||||
@ -71,6 +105,10 @@ class Smartcli {
|
|||||||
*/
|
*/
|
||||||
standardTask() {
|
standardTask() {
|
||||||
let done = q.defer();
|
let done = q.defer();
|
||||||
|
this.allCommandPromisesMap.add({
|
||||||
|
commandName: 'standard',
|
||||||
|
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) {
|
||||||
@ -92,4 +130,4 @@ class Smartcli {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.Smartcli = Smartcli;
|
exports.Smartcli = Smartcli;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHVCQUFzQjtBQUV0Qiw4Q0FBNkM7QUFHN0MsaUJBQWlCO0FBQ2pCLDZCQUE2QjtBQVE3QjtJQVVJO1FBRkEsT0FBTztRQUNQLHVCQUFrQixHQUFHLElBQUksZUFBUyxFQUF5QixDQU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UMsSUFBSSxDQUFDLENBQUMsQ0FBQyxNQUFNLEtBQUssQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO2dCQUMzQyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQTtZQUMzQixDQUFDO1lBQUMsSUFBSSxDQUFDLENBQUM7Z0JBQ0osSUFBSSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUE7WUFDMUIsQ0FBQztRQUNMLENBQUMsQ0FBQyxDQUFBO1FBQ04sTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUVEOztPQUVHO0lBQ0gsVUFBVTtRQUNOLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUE7UUFDMUIsSUFBSSxDQUFDLFlBQVksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUMzQixNQUFNLENBQUE7SUFDVixDQUFDO0NBRUo7QUEvSUQsNEJBK0lDIn0=
|
3
dist/smartcli.plugins.d.ts
vendored
3
dist/smartcli.plugins.d.ts
vendored
@ -1,8 +1,7 @@
|
|||||||
import 'typings-global';
|
import 'typings-global';
|
||||||
import * as yargs from 'yargs';
|
import * as yargs from 'yargs';
|
||||||
import * as beautylog from 'beautylog';
|
import * as beautylog from 'beautylog';
|
||||||
import * as inquirer from 'inquirer';
|
|
||||||
import * as lik from 'lik';
|
import * as lik from 'lik';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as smartparam from 'smartparam';
|
import * as smartparam from 'smartparam';
|
||||||
export { yargs, beautylog, cliff, inquirer, lik, path, smartparam };
|
export { yargs, beautylog, lik, path, smartparam };
|
||||||
|
4
dist/smartcli.plugins.js
vendored
4
dist/smartcli.plugins.js
vendored
@ -4,12 +4,10 @@ const yargs = require("yargs");
|
|||||||
exports.yargs = yargs;
|
exports.yargs = yargs;
|
||||||
const beautylog = require("beautylog");
|
const beautylog = require("beautylog");
|
||||||
exports.beautylog = beautylog;
|
exports.beautylog = beautylog;
|
||||||
const inquirer = require("inquirer");
|
|
||||||
exports.inquirer = inquirer;
|
|
||||||
const lik = require("lik");
|
const lik = require("lik");
|
||||||
exports.lik = lik;
|
exports.lik = lik;
|
||||||
const path = require("path");
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QjtBQUV4QiwrQkFBOEI7QUFRMUIsZ0JBUlEsS0FBSyxDQVFSO0FBUFQsdUNBQXNDO0FBUWxDLG9CQVJRLFNBQVMsQ0FRUjtBQVBiLHFDQUFvQztBQVNoQyxtQkFUUSxRQUFRLENBU1I7QUFSWiwyQkFBMEI7QUFTdEIsY0FUUSxHQUFHLENBU1I7QUFSUCw2QkFBNEI7QUFTeEIsZUFUUSxJQUFJLENBU1I7QUFSUix5Q0FBd0M7QUFTcEMscUJBVFEsVUFBVSxDQVNSIn0=
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUV2QiwrQkFBOEI7QUFPMUIsc0JBQUs7QUFOVCx1Q0FBc0M7QUFPbEMsOEJBQVM7QUFOYiwyQkFBMEI7QUFPdEIsa0JBQUc7QUFOUCw2QkFBNEI7QUFPeEIsb0JBQUk7QUFOUix5Q0FBd0M7QUFPcEMsZ0NBQVUifQ==
|
29
package.json
29
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "smartcli",
|
"name": "smartcli",
|
||||||
"version": "1.0.10",
|
"version": "2.0.1",
|
||||||
"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,31 +17,32 @@
|
|||||||
"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/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",
|
||||||
"inquirer": "^1.1.2",
|
"lik": "^1.0.24",
|
||||||
"lik": "^1.0.15",
|
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
|
"rxjs": "^5.0.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
2
test/test.d.ts
vendored
@ -1 +1 @@
|
|||||||
import "typings-test";
|
import 'typings-test';
|
||||||
|
49
test/test.js
49
test/test.js
@ -1,36 +1,51 @@
|
|||||||
"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('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('.trigger', function () {
|
||||||
it("should start parsing the CLI input", 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();
|
smartCliTestObject.startParse();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFzQjtBQUV0QiwwQ0FBMkM7QUFDM0MsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ3JDLElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyx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'
|
||||||
|
|
||||||
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('awesome')
|
||||||
commandName:"awesome"
|
})
|
||||||
});
|
})
|
||||||
|
describe('.standardTask',function(){
|
||||||
});
|
it('should start parsing a standardTask',function(done){
|
||||||
});
|
|
||||||
describe(".standardTask",function(){
|
|
||||||
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('.trigger', function() {
|
||||||
it("should start parsing the CLI input",function(){
|
let hasExecuted = false
|
||||||
smartCliTestObject.startParse();
|
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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
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 IChoiceObject {
|
|
||||||
name: string
|
|
||||||
value: any
|
|
||||||
}
|
|
||||||
export interface IValidateFunction {
|
|
||||||
(any): boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Interaction {
|
|
||||||
constructor() {
|
|
||||||
}
|
|
||||||
|
|
||||||
askQuestion(optionsArg: {
|
|
||||||
type: questionType,
|
|
||||||
message: string
|
|
||||||
default: any
|
|
||||||
choices: string[] | IChoiceObject[]
|
|
||||||
validate: IValidateFunction
|
|
||||||
}) {
|
|
||||||
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() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +1,20 @@
|
|||||||
import * as q from 'q'
|
import * as q from 'q'
|
||||||
|
import { Subject } from 'rxjs'
|
||||||
|
|
||||||
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 ICommandPromiseObject {
|
export interface ICommandPromiseObject {
|
||||||
commandName: string
|
commandName: string,
|
||||||
promise: q.Promise<any>
|
promise: q.Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ITriggerObservableObject {
|
||||||
|
triggerName: string
|
||||||
|
subject: Subject<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Smartcli {
|
export class Smartcli {
|
||||||
@ -20,8 +25,16 @@ export class Smartcli {
|
|||||||
questions
|
questions
|
||||||
version: string
|
version: string
|
||||||
|
|
||||||
// maps
|
/**
|
||||||
allCommandPromises = new Objectmap<ICommandPromiseObject>()
|
* 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() {
|
constructor() {
|
||||||
this.argv = plugins.yargs
|
this.argv = plugins.yargs
|
||||||
this.questionsDone = q.defer()
|
this.questionsDone = q.defer()
|
||||||
@ -29,9 +42,9 @@ export class Smartcli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 command execution.
|
||||||
*/
|
*/
|
||||||
addAlias(keyArg,aliasArg): void {
|
addCommandAlias(keyArg,aliasArg): void {
|
||||||
this.argv = this.argv.alias(keyArg,aliasArg)
|
this.argv = this.argv.alias(keyArg,aliasArg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -40,11 +53,15 @@ export 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(definitionArg: {commandName: string}): q.Promise<any> {
|
addCommand(commandNameArg: string): q.Promise<any> {
|
||||||
let done = q.defer<any>()
|
let done = q.defer<any>()
|
||||||
|
this.allCommandPromisesMap.add({
|
||||||
|
commandName: commandNameArg,
|
||||||
|
promise: done.promise
|
||||||
|
})
|
||||||
this.parseStarted.promise
|
this.parseStarted.promise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (this.argv._.indexOf(definitionArg.commandName) === 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)
|
||||||
@ -56,21 +73,46 @@ export class Smartcli {
|
|||||||
/**
|
/**
|
||||||
* 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.allCommandPromisesMap.find(commandDeferredObjectArg => {
|
||||||
return commandPromiseObjectArg.commandName === commandNameArg
|
return commandDeferredObjectArg.commandName === commandNameArg
|
||||||
}).promise
|
}).promise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
||||||
|
*/
|
||||||
|
addTrigger(triggerNameArg: string) {
|
||||||
|
let triggerSubject = new Subject<any>()
|
||||||
|
this.allTriggerObservablesMap.add({
|
||||||
|
triggerName: triggerNameArg,
|
||||||
|
subject: triggerSubject
|
||||||
|
})
|
||||||
|
this.addCommand(triggerNameArg).then(() => {
|
||||||
|
triggerSubject.next(this.argv)
|
||||||
|
})
|
||||||
|
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(this.argv)
|
||||||
|
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({
|
this.addCommand('help').then(argvArg => {
|
||||||
commandName: 'help'
|
|
||||||
}).then(argvArg => {
|
|
||||||
plugins.beautylog.log(optionsArg.helpText)
|
plugins.beautylog.log(optionsArg.helpText)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -80,7 +122,7 @@ export class Smartcli {
|
|||||||
*/
|
*/
|
||||||
addVersion(versionArg: string) {
|
addVersion(versionArg: string) {
|
||||||
this.version = versionArg
|
this.version = versionArg
|
||||||
this.addAlias('v','version')
|
this.addCommandAlias('v','version')
|
||||||
this.parseStarted.promise
|
this.parseStarted.promise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (this.argv.v) {
|
if (this.argv.v) {
|
||||||
@ -94,6 +136,10 @@ export class Smartcli {
|
|||||||
*/
|
*/
|
||||||
standardTask(): q.Promise<any> {
|
standardTask(): q.Promise<any> {
|
||||||
let done = q.defer<any>()
|
let done = q.defer<any>()
|
||||||
|
this.allCommandPromisesMap.add({
|
||||||
|
commandName: 'standard',
|
||||||
|
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) {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import 'typings-global';
|
import 'typings-global'
|
||||||
|
|
||||||
import * as yargs from 'yargs'
|
import * as yargs from 'yargs'
|
||||||
import * as beautylog from 'beautylog'
|
import * as beautylog from 'beautylog'
|
||||||
import * as inquirer from 'inquirer'
|
|
||||||
import * as lik from 'lik'
|
import * as lik from 'lik'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as smartparam from 'smartparam'
|
import * as smartparam from 'smartparam'
|
||||||
@ -10,8 +9,6 @@ import * as smartparam from 'smartparam'
|
|||||||
export {
|
export {
|
||||||
yargs,
|
yargs,
|
||||||
beautylog,
|
beautylog,
|
||||||
cliff,
|
|
||||||
inquirer,
|
|
||||||
lik,
|
lik,
|
||||||
path,
|
path,
|
||||||
smartparam
|
smartparam
|
||||||
|
Reference in New Issue
Block a user