start interaction module

This commit is contained in:
Philipp Kunz 2016-08-26 11:52:09 +02:00
parent 9e5fb7a13a
commit c7a647d4ef
14 changed files with 219 additions and 188 deletions

View File

@ -17,38 +17,22 @@ this plugin tries to establish some logic in which CLI tools work.
take the following commandline input:
```
mytool function argument1 argument2 --option1 option1Value --option2 option2Value
mytool function argument1 argument2 --option1 -o2 option2Value
```
* 'mytool' obviously is the tool (like git)
* function is the main thing the tool shall do (like commit)
* option is an option you can add (like -m for message)
* 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)
### The inner organization of smartcli
**smartcli** exposes three major groups of functions:
* check functions
* are grouped in **smartcli.checks** object
* get functions
* are grouped in **smartcli.get** object
* async interaction functions
* are grouped in **smartcli.interaction** object
### Methods
The examples are written in TypeScript
```typescript
import * as smartcli from "smartcli"
/* -------------- Check Functions -------------------*/
smartcli.check.command("jazz"); // check for a special command.
smartcli.check.commandPresence() // check if any command is specified
smartcli.check.commandArguemnt("myargument",1) // checks if a special argument is given, second argument is level
smartcli.check.commandArguemntPresence // checks of any Argument is present
smartcli.check.option("someoption") // checks for a specific option
smartcli.check.optionPresence() // checks if any option is specified
smartcli.get.option('myoption'); //
```
import {Smartcli} from "smartcli"
mySmartcli = new Smartcli();
mySmartcli.standardTask()
.then(argvArg => {
// do something if program is called without an command
});
mySmartcli.question
```

View File

@ -1,4 +1,32 @@
import "typings-global";
export declare class Question {
/**
* 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,17 +0,0 @@
import "typings-global";
import "./smartcli.interfaces";
/**
* executes callback with answer to question as argument
* @param questionString the question you want to ask the user
* @param cb the function to execute with answer as param
* @returns {null}
*/
export declare let getAnswer: (questionString: string, cb: any) => any;
/**
*
* @param questionString
* @param choiceOptions
* @param cb
* @returns {null}
*/
export declare let getChoice: (questionString: string, choiceOptions: string[], cb: any) => any;

View File

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

View File

@ -1,8 +1,41 @@
"use strict";
require("typings-global");
class Question {
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.Question = Question;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5pbnRlcmFjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuaW50ZXJhY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUd4QjtJQUNJO0lBRUEsQ0FBQztBQUNMLENBQUM7QUFKWSxnQkFBUSxXQUlwQixDQUFBIn0=
exports.QuestionTreeNode = QuestionTreeNode;
;
class QuestionStorage {
constructor() {
}
}
exports.QuestionStorage = QuestionStorage;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5pbnRlcmFjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuaW50ZXJhY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixNQUFZLE9BQU8sV0FBTSxvQkFBb0IsQ0FBQyxDQUFBO0FBZTlDO0lBQ0k7SUFDQSxDQUFDOztJQUVELFdBQVcsQ0FBQyxVQU1YO1FBQ0csSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUM3QixPQUFPLENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQyxDQUFDO2dCQUNyQixJQUFJLEVBQUUsVUFBVSxDQUFDLElBQUk7Z0JBQ3JCLE9BQU8sRUFBRSxVQUFVLENBQUMsT0FBTztnQkFDM0IsT0FBTyxFQUFFLFVBQVUsQ0FBQyxPQUFPO2dCQUMzQixPQUFPLEVBQUMsVUFBVSxDQUFDLE9BQU87Z0JBQzFCLFFBQVEsRUFBRSxVQUFVLENBQUMsUUFBUTthQUNoQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsT0FBTztZQUNaLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDMUIsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDOztBQUVMLENBQUM7QUF2QlksbUJBQVcsY0F1QnZCLENBQUE7QUFHRDtJQUVJLFlBQVksY0FBc0IsRUFBRSxZQUFZO0lBRWhELENBQUM7O0FBQ0wsQ0FBQztBQUxZLG9CQUFZLGVBS3hCLENBQUE7QUFBQSxDQUFDO0FBRUY7SUFDSTtJQUVBLENBQUM7QUFDTCxDQUFDO0FBSlksd0JBQWdCLG1CQUk1QixDQUFBO0FBQUEsQ0FBQztBQUVGO0lBQ0k7SUFFQSxDQUFDO0FBQ0wsQ0FBQztBQUpZLHVCQUFlLGtCQUkzQixDQUFBIn0=

View File

@ -1,6 +1,11 @@
/// <reference types="q" />
import "typings-global";
import * as plugins from "./smartcli.plugins";
import { Objectmap } from "lik";
export interface commandPromiseObject {
commandName: string;
promise: plugins.q.Promise<any>;
}
export declare class Smartcli {
argv: any;
questionsDone: any;
@ -8,6 +13,7 @@ export declare class Smartcli {
commands: any;
questions: any;
version: string;
allCommandPromises: Objectmap<commandPromiseObject>;
constructor();
/**
* adds an alias, meaning one equals the other in terms of triggering associated commands
@ -24,13 +30,20 @@ export declare class Smartcli {
/**
* gets a Promise for a command word
*/
getCommandPromise(commandNameArg: any): void;
addQuestion(definitionArg: {
questionString: string;
questionType: string;
getCommandPromiseByName(commandNameArg: string): plugins.q.Promise<any>;
/**
* allows to specify help text to be printed above the rest of the help text
*/
addHelp(optionsArg: {
helpText: string;
}): void;
addHelp(): void;
/**
* specify version to be printed for -v --version
*/
addVersion(versionArg: string): void;
/**
* returns promise that is resolved when no commands are specified
*/
standardTask(): plugins.q.Promise<{}>;
startParse(): void;
}

View File

@ -1,8 +1,13 @@
"use strict";
require("typings-global");
const plugins = require("./smartcli.plugins");
// import classes
const lik_1 = require("lik");
;
class Smartcli {
constructor() {
// maps
this.allCommandPromises = new lik_1.Objectmap();
this.argv = plugins.argv;
this.questionsDone = plugins.q.defer();
this.parseStarted = plugins.q.defer();
@ -37,14 +42,26 @@ class Smartcli {
/**
* gets a Promise for a command word
*/
getCommandPromise(commandNameArg) {
//TODO
}
addQuestion(definitionArg) {
getCommandPromiseByName(commandNameArg) {
return this.allCommandPromises.find(commandPromiseObjectArg => {
return commandPromiseObjectArg.commandName === commandNameArg;
}).promise;
}
;
addHelp() {
/**
* allows to specify help text to be printed above the rest of the help text
*/
addHelp(optionsArg) {
this.addCommand({
commandName: "help"
}).then(argvArg => {
plugins.beautylog.log(optionsArg.helpText);
});
}
;
/**
* specify version to be printed for -v --version
*/
addVersion(versionArg) {
this.version = versionArg;
this.addAlias("v", "version");
@ -55,6 +72,10 @@ class Smartcli {
}
});
}
;
/**
* returns promise that is resolved when no commands are specified
*/
standardTask() {
let done = plugins.q.defer();
this.parseStarted.promise
@ -75,4 +96,4 @@ class Smartcli {
}
}
exports.Smartcli = Smartcli;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4QixNQUFZLE9BQU8sV0FBTSxvQkFBb0IsQ0FBQyxDQUFBO0FBRzlDO0lBT0k7UUFDSSxJQUFJLENBQUMsSUFBSSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUM7UUFDekIsSUFBSSxDQUFDLGFBQWEsR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQ3ZDLElBQUksQ0FBQyxZQUFZLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUMxQyxDQUFDOztJQUVEOztPQUVHO0lBQ0gsUUFBUSxDQUFDLE1BQU0sRUFBQyxRQUFRO1FBQ3BCLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsTUFBTSxFQUFDLFFBQVEsQ0FBQyxDQUFDO0lBQ2pELENBQUM7O0lBRUQ7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0FBQSxDQUFDO2dCQUNaLE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDO1lBQzlCLENBQUM7UUFDTCxDQUFDLENBQUMsQ0FBQTtJQUNWLENBQUM7O0lBRUQ7O09BRUc7SUFDSCxZQUFZO1FBQ1IsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUM3QixJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU87YUFDcEIsSUFBSSxDQUFDO1lBQ0YsRUFBRSxDQUFBLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsTUFBTSxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUEsQ0FBQztnQkFDeEMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUM7WUFDNUIsQ0FBQztZQUFDLElBQUksQ0FBQyxDQUFDO2dCQUNKLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQzNCLENBQUM7WUFBQSxDQUFDO1FBQ04sQ0FBQyxDQUFDLENBQUM7UUFDUCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDO0lBQ0QsVUFBVTtRQUNOLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUM7UUFDM0IsSUFBSSxDQUFDLFlBQVksQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUNoQyxDQUFDO0FBRUwsQ0FBQztBQWpHWSxnQkFBUSxXQWlHcEIsQ0FBQSJ9

View File

@ -2,7 +2,7 @@ import "typings-global";
export declare let argv: any;
export import beautylog = require("beautylog");
export declare let cliff: any;
export declare let inquirer: any;
export import inquirer = require("inquirer");
export import lik = require("lik");
export declare let path: any;
export import q = require("q");

View File

@ -8,4 +8,4 @@ exports.lik = require("lik");
exports.path = require("path");
exports.q = require("q");
exports.smartparam = require("smartparam");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUViLFlBQUksR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7QUFDckIsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNwQyxhQUFLLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0FBQ3pCLGdCQUFRLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0FBQzVCLFdBQUcsV0FBVyxLQUFLLENBQUMsQ0FBQztBQUN4QixZQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQ3BCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNqQixrQkFBVSxXQUFXLFlBQVksQ0FBQyxDQUFDIn0=
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUViLFlBQUksR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7QUFDckIsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNwQyxhQUFLLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0FBQ3RCLGdCQUFRLFdBQVcsVUFBVSxDQUFDLENBQUM7QUFDL0IsV0FBRyxXQUFXLEtBQUssQ0FBQyxDQUFDO0FBQ3hCLFlBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7QUFDcEIsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGtCQUFVLFdBQVcsWUFBWSxDQUFDLENBQUMifQ==

View File

@ -28,7 +28,8 @@
},
"homepage": "https://gitlab.com/pushrocks/smartcli",
"dependencies": {
"@types/q": "0.0.30",
"@types/inquirer": "0.x.x",
"@types/q": "0.x.x",
"beautylog": "^5.0.20",
"cliff": "^0.1.10",
"inquirer": "^1.1.2",

View File

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

View File

@ -1,8 +1,60 @@
import "typings-global";
import * as plugins from "./smartcli.plugins";
export class Question {
constructor(){
/**
* 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,7 +1,16 @@
import "typings-global";
import * as plugins from "./smartcli.plugins";
import {Question} from "./smartcli.classes.interaction";
import * as interaction from "./smartcli.classes.interaction";
// import classes
import {Objectmap} from "lik";
// interfaces
export interface commandPromiseObject {
commandName:string;
promise: plugins.q.Promise<any>;
};
export class Smartcli {
argv;
@ -10,6 +19,9 @@ export class Smartcli {
commands;
questions;
version:string;
// maps
allCommandPromises = new Objectmap<commandPromiseObject>();
constructor(){
this.argv = plugins.argv;
this.questionsDone = plugins.q.defer();
@ -44,15 +56,28 @@ export class Smartcli {
/**
* gets a Promise for a command word
*/
getCommandPromise(commandNameArg){
//TODO
}
addQuestion(definitionArg:{questionString:string,questionType:string}){
getCommandPromiseByName(commandNameArg:string){
return this.allCommandPromises.find(commandPromiseObjectArg => {
return commandPromiseObjectArg.commandName === commandNameArg;
}).promise;
};
addHelp(){
}
/**
* allows to specify help text to be printed above the rest of the help text
*/
addHelp(optionsArg:{
helpText:string
}){
this.addCommand({
commandName:"help"
}).then(argvArg => {
plugins.beautylog.log(optionsArg.helpText);
})
};
/**
* specify version to be printed for -v --version
*/
addVersion(versionArg:string){
this.version = versionArg;
this.addAlias("v","version");
@ -62,7 +87,11 @@ export class Smartcli {
console.log(this.version);
}
})
}
};
/**
* returns promise that is resolved when no commands are specified
*/
standardTask(){
let done = plugins.q.defer();
this.parseStarted.promise

View File

@ -3,7 +3,7 @@ import "typings-global";
export let argv = require('yargs');
export import beautylog = require("beautylog");
export let cliff = require("cliff");
export let inquirer = require("inquirer");
export import inquirer = require("inquirer");
export import lik = require("lik");
export let path = require("path");
export import q = require("q");