Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
120eca42ac | |||
fc289616f6 | |||
e7c1c1c45b | |||
f33c759fa8 | |||
1185df362b | |||
36de8e11f0 | |||
74ffb3aa87 | |||
96a6d01720 | |||
7833bd0be8 | |||
7ca18c4a46 | |||
b98e2a1a62 | |||
e102203422 | |||
92a37cf29b | |||
8408d1f3b5 | |||
d88e05466b | |||
3a789d052c | |||
d76d829e46 | |||
f8157ab8aa | |||
5c67015779 | |||
b67e3c0de1 | |||
c7a647d4ef |
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,8 +1,6 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
.settings/
|
|
||||||
.idea/
|
|
||||||
coverage/
|
coverage/
|
||||||
docs/
|
pages/
|
||||||
|
|
||||||
|
|
||||||
ts/*.js
|
ts/*.js
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmts
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
|
- page
|
||||||
|
|
||||||
testLEGACY:
|
testLEGACY:
|
||||||
stage: test
|
stage: test
|
||||||
@ -35,3 +36,15 @@ release:
|
|||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
|
pages:
|
||||||
|
image: hosttoday/ht-docker-node:npmpage
|
||||||
|
stage: page
|
||||||
|
script:
|
||||||
|
- npmci test stable
|
||||||
|
- npmci command npmpage --host gitlab
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- public
|
54
README.md
54
README.md
@ -1,11 +1,20 @@
|
|||||||
# smartcli
|
# smartcli
|
||||||
nodejs wrapper for CLI related tasks. TypeScript ready.
|
nodejs wrapper for CLI related tasks. TypeScript ready.
|
||||||
|
|
||||||
## Status
|
## Availabililty
|
||||||
[](https://travis-ci.org/pushrocks/smartcli)
|
[](https://www.npmjs.com/package/smartcli)
|
||||||
|
[](https://gitlab.com/pushrocks/smartcli)
|
||||||
|
[](https://github.com/pushrocks/smartcli)
|
||||||
|
[](https://pushrocks.gitlab.io/smartcli/docs)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/smartcli/commits/master)
|
||||||
|
[](https://gitlab.com/pushrocks/smartcli/commits/master)
|
||||||
[](https://david-dm.org/pushrocks/smartcli)
|
[](https://david-dm.org/pushrocks/smartcli)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartcli)
|
[](https://www.bithound.io/github/pushrocks/smartcli/master/dependencies/npm)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartcli)
|
[](https://www.bithound.io/github/pushrocks/smartcli)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
|
||||||
## Install the package
|
## Install the package
|
||||||
npm install smartcli --save
|
npm install smartcli --save
|
||||||
@ -17,38 +26,27 @@ this plugin tries to establish some logic in which CLI tools work.
|
|||||||
take the following commandline input:
|
take the following commandline input:
|
||||||
|
|
||||||
```
|
```
|
||||||
mytool function argument1 argument2 --option1 option1Value --option2 option2Value
|
mytool function 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)
|
* 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)
|
* 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
|
```typescript
|
||||||
import * as smartcli from "smartcli"
|
import {Smartcli} from "smartcli"
|
||||||
|
mySmartcli = new Smartcli();
|
||||||
|
mySmartcli.standardTask()
|
||||||
|
.then(argvArg => {
|
||||||
|
// do something if program is called without an command
|
||||||
|
});
|
||||||
|
|
||||||
/* -------------- Check Functions -------------------*/
|
mySmartcli.addCommand({commandname: 'install'})
|
||||||
smartcli.check.command("jazz"); // check for a special command.
|
.then(argvArg => {
|
||||||
smartcli.check.commandPresence() // check if any command is specified
|
// do something if program is called with command "install"
|
||||||
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'); //
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
||||||
|
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1,2 +1 @@
|
|||||||
import "typings-global";
|
export { Smartcli } from './smartcli.classes.smartcli';
|
||||||
export { Smartcli } from "./smartcli.classes.smartcli";
|
|
||||||
|
3
dist/index.js
vendored
3
dist/index.js
vendored
@ -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
|
4
dist/smartcli.classes.interaction.d.ts
vendored
4
dist/smartcli.classes.interaction.d.ts
vendored
@ -1,4 +0,0 @@
|
|||||||
import "typings-global";
|
|
||||||
export declare class Question {
|
|
||||||
constructor();
|
|
||||||
}
|
|
17
dist/smartcli.classes.interaction.helpers.d.ts
vendored
17
dist/smartcli.classes.interaction.helpers.d.ts
vendored
@ -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;
|
|
54
dist/smartcli.classes.interaction.helpers.js
vendored
54
dist/smartcli.classes.interaction.helpers.js
vendored
@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5pbnRlcmFjdGlvbi5oZWxwZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjbGkuY2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xLQUFLLENBQUMsT0FBTyxDQUFDLGFBQWEsQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUMvQixNQUFNLENBQUMsSUFBSSxDQUFDO0lBQ2hCLENBQUM7SUFFRCwwQ0FBMEM7SUFDMUMsSUFBSSxRQUFRLEdBQUc7UUFDWCxJQUFJLEVBQUUsTUFBTTtRQUNaLElBQUksRUFBRSxjQUFjO1FBQ3BCLE9BQU8sRUFBRSxjQUFjO1FBQ3ZCLE9BQU8sRUFBRSxhQUFhO1FBQ3RCLE1BQU0sRUFBRSxVQUFVLEdBQUcsSUFBSyxNQUFNLENBQUMsR0FBRyxDQUFDLFdBQVcsRUFBRSxDQUFDLENBQUMsQ0FBQztLQUN4RCxDQUFDO0lBRUYsT0FBTyxDQUFDLFFBQVEsQ0FBQyxNQUFNLENBQUMsUUFBUSxFQUFDLFVBQVMsT0FBTztRQUM3QyxJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDO1FBQ2xDLEVBQUUsQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUNmLENBQUMsQ0FBQyxDQUFDO0FBRVAsQ0FBQyxDQUFDIn0=
|
|
8
dist/smartcli.classes.interaction.js
vendored
8
dist/smartcli.classes.interaction.js
vendored
@ -1,8 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-global");
|
|
||||||
class Question {
|
|
||||||
constructor() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.Question = Question;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5pbnRlcmFjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuaW50ZXJhY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUd4QjtJQUNJO0lBRUEsQ0FBQztBQUNMLENBQUM7QUFKWSxnQkFBUSxXQUlwQixDQUFBIn0=
|
|
34
dist/smartcli.classes.smartcli.d.ts
vendored
34
dist/smartcli.classes.smartcli.d.ts
vendored
@ -1,6 +1,10 @@
|
|||||||
/// <reference types="q" />
|
/// <reference types="q" />
|
||||||
import "typings-global";
|
import * as q from 'q';
|
||||||
import * as plugins from "./smartcli.plugins";
|
import { Objectmap } from 'lik';
|
||||||
|
export interface ICommandPromiseObject {
|
||||||
|
commandName: string;
|
||||||
|
promise: q.Promise<any>;
|
||||||
|
}
|
||||||
export declare class Smartcli {
|
export declare class Smartcli {
|
||||||
argv: any;
|
argv: any;
|
||||||
questionsDone: any;
|
questionsDone: any;
|
||||||
@ -8,6 +12,7 @@ export declare class Smartcli {
|
|||||||
commands: any;
|
commands: any;
|
||||||
questions: any;
|
questions: any;
|
||||||
version: string;
|
version: string;
|
||||||
|
allCommandPromises: Objectmap<ICommandPromiseObject>;
|
||||||
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
|
||||||
@ -15,22 +20,31 @@ 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
|
||||||
*/
|
*/
|
||||||
getCommandPromise(commandNameArg: any): void;
|
getCommandPromiseByName(commandNameArg: string): q.Promise<any>;
|
||||||
addQuestion(definitionArg: {
|
/**
|
||||||
questionString: string;
|
* allows to specify help text to be printed above the rest of the help text
|
||||||
questionType: string;
|
*/
|
||||||
|
addHelp(optionsArg: {
|
||||||
|
helpText: string;
|
||||||
}): void;
|
}): void;
|
||||||
addHelp(): void;
|
/**
|
||||||
|
* specify version to be printed for -v --version
|
||||||
|
*/
|
||||||
addVersion(versionArg: string): void;
|
addVersion(versionArg: string): void;
|
||||||
standardTask(): plugins.q.Promise<{}>;
|
/**
|
||||||
|
* returns promise that is resolved when no commands are specified
|
||||||
|
*/
|
||||||
|
standardTask(): q.Promise<any>;
|
||||||
|
/**
|
||||||
|
* start the process of evaluating commands
|
||||||
|
*/
|
||||||
startParse(): void;
|
startParse(): void;
|
||||||
}
|
}
|
||||||
|
59
dist/smartcli.classes.smartcli.js
vendored
59
dist/smartcli.classes.smartcli.js
vendored
@ -1,30 +1,32 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
const q = require("q");
|
||||||
const plugins = require("./smartcli.plugins");
|
const plugins = require("./smartcli.plugins");
|
||||||
|
// import classes
|
||||||
|
const lik_1 = require("lik");
|
||||||
class Smartcli {
|
class Smartcli {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.argv = plugins.argv;
|
// maps
|
||||||
this.questionsDone = plugins.q.defer();
|
this.allCommandPromises = new lik_1.Objectmap();
|
||||||
this.parseStarted = plugins.q.defer();
|
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) {
|
||||||
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.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 {
|
||||||
@ -33,21 +35,30 @@ class Smartcli {
|
|||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
* gets a Promise for a command word
|
* gets a Promise for a command word
|
||||||
*/
|
*/
|
||||||
getCommandPromise(commandNameArg) {
|
getCommandPromiseByName(commandNameArg) {
|
||||||
//TODO
|
return this.allCommandPromises.find(commandPromiseObjectArg => {
|
||||||
|
return commandPromiseObjectArg.commandName === commandNameArg;
|
||||||
|
}).promise;
|
||||||
}
|
}
|
||||||
addQuestion(definitionArg) {
|
/**
|
||||||
}
|
* allows to specify help text to be printed above the rest of the help text
|
||||||
;
|
*/
|
||||||
addHelp() {
|
addHelp(optionsArg) {
|
||||||
|
this.addCommand({
|
||||||
|
commandName: 'help'
|
||||||
|
}).then(argvArg => {
|
||||||
|
plugins.beautylog.log(optionsArg.helpText);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
@ -55,24 +66,30 @@ class Smartcli {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* start the process of evaluating commands
|
||||||
|
*/
|
||||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4Q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QUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUVEOztPQUVHO0lBQ0gsVUFBVTtRQUNOLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUE7UUFDMUIsSUFBSSxDQUFDLFlBQVksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUMzQixNQUFNLENBQUE7SUFDVixDQUFDO0NBRUo7QUF0R0QsNEJBc0dDIn0=
|
16
dist/smartcli.plugins.d.ts
vendored
16
dist/smartcli.plugins.d.ts
vendored
@ -1,9 +1,7 @@
|
|||||||
import "typings-global";
|
import 'typings-global';
|
||||||
export declare let argv: any;
|
import * as yargs from 'yargs';
|
||||||
export import beautylog = require("beautylog");
|
import * as beautylog from 'beautylog';
|
||||||
export declare let cliff: any;
|
import * as lik from 'lik';
|
||||||
export declare let inquirer: any;
|
import * as path from 'path';
|
||||||
export import lik = require("lik");
|
import * as smartparam from 'smartparam';
|
||||||
export declare let path: any;
|
export { yargs, beautylog, lik, path, smartparam };
|
||||||
export import q = require("q");
|
|
||||||
export import smartparam = require("smartparam");
|
|
||||||
|
20
dist/smartcli.plugins.js
vendored
20
dist/smartcli.plugins.js
vendored
@ -1,11 +1,13 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
exports.argv = 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUViLFlBQUksR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7QUFDckIsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNwQyxhQUFLLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0FBQ3pCLGdCQUFRLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0FBQzVCLFdBQUcsV0FBVyxLQUFLLENBQUMsQ0FBQztBQUN4QixZQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQ3BCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNqQixrQkFBVSxXQUFXLFlBQVksQ0FBQyxDQUFDIn0=
|
const smartparam = require("smartparam");
|
||||||
|
exports.smartparam = smartparam;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QjtBQUV4QiwrQkFBOEI7QUFPMUIsc0JBQUs7QUFOVCx1Q0FBc0M7QUFPbEMsOEJBQVM7QUFOYiwyQkFBMEI7QUFPdEIsa0JBQUc7QUFOUCw2QkFBNEI7QUFPeEIsb0JBQUk7QUFOUix5Q0FBd0M7QUFPcEMsZ0NBQVUifQ==
|
15
docs/book.json
Normal file
15
docs/book.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"structure": {
|
||||||
|
"readme": "index.md"
|
||||||
|
},
|
||||||
|
"plugins": [
|
||||||
|
"tonic",
|
||||||
|
"edit-link"
|
||||||
|
],
|
||||||
|
"pluginsConfig": {
|
||||||
|
"edit-link": {
|
||||||
|
"base": "https://gitlab.com/pushrocks/npmts/edit/master/docs/",
|
||||||
|
"label": "Edit on GitLab"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
docs/index.md
Normal file
47
docs/index.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# smartcli
|
||||||
|
nodejs wrapper for CLI related tasks. TypeScript ready.
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
[](https://www.npmjs.com/package/smartcli)
|
||||||
|
[](https://gitlab.com/pushrocks/smartcli)
|
||||||
|
[](https://github.com/pushrocks/smartcli)
|
||||||
|
[](https://pushrocks.gitlab.io/smartcli/docs)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/smartcli/commits/master)
|
||||||
|
[](https://gitlab.com/pushrocks/smartcli/commits/master)
|
||||||
|
[](https://david-dm.org/pushrocks/smartcli)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartcli/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartcli)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
|
||||||
|
## Install the package
|
||||||
|
npm install smartcli --save
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
this plugin tries to establish some logic in which CLI tools work.
|
||||||
|
|
||||||
|
take the following commandline input:
|
||||||
|
|
||||||
|
```
|
||||||
|
mytool function argument1 argument2 --option1 -o2 option2Value
|
||||||
|
```
|
||||||
|
|
||||||
|
* 'mytool' obviously is the tool (like git)
|
||||||
|
* function is the main thing the tool shall do (like commit)
|
||||||
|
* argument1 and argument2 are arguments
|
||||||
|
* option1 is a longform option you can add (like --message for message)
|
||||||
|
* optionValue is the referenced option value (like a commit message)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import {Smartcli} from "smartcli"
|
||||||
|
mySmartcli = new Smartcli();
|
||||||
|
mySmartcli.standardTask()
|
||||||
|
.then(argvArg => {
|
||||||
|
// do something if program is called without an command
|
||||||
|
});
|
||||||
|
|
||||||
|
mySmartcli.question
|
||||||
|
```
|
20
package.json
20
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "smartcli",
|
"name": "smartcli",
|
||||||
"version": "1.0.5",
|
"version": "1.0.13",
|
||||||
"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",
|
||||||
@ -28,19 +28,19 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "0.0.30",
|
"@types/q": "0.x.x",
|
||||||
"beautylog": "^5.0.20",
|
"@types/yargs": "6.x.x",
|
||||||
"cliff": "^0.1.10",
|
"beautylog": "^6.0.0",
|
||||||
"inquirer": "^1.1.2",
|
"lik": "^1.0.24",
|
||||||
"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
2
test/test.d.ts
vendored
@ -1 +1 @@
|
|||||||
import "typings-test";
|
import 'typings-test';
|
||||||
|
29
test/test.js
29
test/test.js
@ -1,36 +1,35 @@
|
|||||||
"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('.startParse', function () {
|
||||||
it("should start parsing the CLI input", function () {
|
it('should start parsing the CLI input', function () {
|
||||||
smartCliTestObject.startParse();
|
smartCliTestObject.startParse();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFFdEIsTUFBTyxRQUFRLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDM0MsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ3JDLElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUUvQixRQUFRLENBQUMseUJBQXlCLEVBQUM7SUFDL0IsSUFBSSxrQkFBb0MsQ0FBQztJQUN6QyxRQUFRLENBQUMsZ0JBQWdCLEVBQUM7UUFDdEIsRUFBRSxDQUFDLDhCQUE4QixFQUFDO1lBQzlCLGtCQUFrQixHQUFHLElBQUksUUFBUSxDQUFDLFFBQVEsRUFBRSxDQUFDO1lBQzdDLGtCQUFrQixDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxRQUFRLENBQUMsQ0FBQztRQUMvRCxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0lBQ0gsUUFBUSxDQUFDLGFBQWEsRUFBQztRQUNuQixFQUFFLENBQUMsdUJBQXVCLEVBQUM7WUFDdkIsa0JBQWtCLENBQUMsVUFBVSxDQUFDO2dCQUMxQixXQUFXLEVBQUMsU0FBUzthQUN4QixDQUFDLENBQUM7UUFFUCxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0lBQ0gsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixFQUFFL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hQUFhLEVBQUM7UUFDbkIsRUFBRSxDQUFDLHVCQUF1QixFQUFDO1lBQ3ZCLGtCQUFrQixDQUFDLFVBQVUsQ0FBQztnQkFDMUIsV0FBVyxFQUFFLFNBQVM7YUFDekIsQ0FBQyxDQUFBO1FBQ04sQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtJQUNGLFFBQVEsQ0FBQyxlQUFlLEVBQUM7UUFDckIsRUFBRSxDQUFDLHFDQUFxQyxFQUFDLFVBQVMsSUFBSTtZQUNsRCxrQkFBa0IsQ0FBQyxZQUFZLEVBQUU7aUJBQzVCLElBQUksQ0FBQztnQkFDRixPQUFPLENBQUMsR0FBRyxDQUFDLDRCQUE0QixDQUFDLENBQUE7WUFDN0MsQ0FBQyxDQUFDLENBQUE7WUFDTixJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7SUFDRixRQUFRLENBQUMsYUFBYSxFQUFDO1FBQ25CLEVBQUUsQ0FBQyxvQ0FBb0MsRUFBQztZQUNwQyxrQkFBa0IsQ0FBQyxVQUFVLEVBQUUsQ0FBQTtRQUNuQyxDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
54
test/test.ts
54
test/test.ts
@ -1,37 +1,35 @@
|
|||||||
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('.startParse',function(){
|
||||||
it("should start parsing the CLI input",function(){
|
it('should start parsing the CLI input',function(){
|
||||||
smartCliTestObject.startParse();
|
smartCliTestObject.startParse()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
|
||||||
|
@ -1,4 +1 @@
|
|||||||
import "typings-global";
|
export { Smartcli } from './smartcli.classes.smartcli'
|
||||||
|
|
||||||
import {Smartcli} from "./smartcli.classes.smartcli";
|
|
||||||
export {Smartcli} from "./smartcli.classes.smartcli";
|
|
||||||
|
@ -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);
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
@ -1,8 +0,0 @@
|
|||||||
import "typings-global";
|
|
||||||
import * as plugins from "./smartcli.plugins";
|
|
||||||
|
|
||||||
export class Question {
|
|
||||||
constructor(){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,83 +1,116 @@
|
|||||||
import "typings-global";
|
import * as q from 'q'
|
||||||
|
|
||||||
import * as plugins from "./smartcli.plugins";
|
import * as plugins from './smartcli.plugins'
|
||||||
import {Question} from "./smartcli.classes.interaction";
|
|
||||||
|
// import classes
|
||||||
|
import {Objectmap} from 'lik'
|
||||||
|
|
||||||
|
// interfaces
|
||||||
|
export interface ICommandPromiseObject {
|
||||||
|
commandName: string
|
||||||
|
promise: q.Promise<any>
|
||||||
|
}
|
||||||
|
|
||||||
export class Smartcli {
|
export class Smartcli {
|
||||||
argv;
|
argv: any
|
||||||
questionsDone;
|
questionsDone
|
||||||
parseStarted;
|
parseStarted
|
||||||
commands;
|
commands
|
||||||
questions;
|
questions
|
||||||
version:string;
|
version: string
|
||||||
|
|
||||||
|
// maps
|
||||||
|
allCommandPromises = new Objectmap<ICommandPromiseObject>()
|
||||||
constructor() {
|
constructor() {
|
||||||
this.argv = plugins.argv;
|
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): 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.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
|
||||||
*/
|
*/
|
||||||
getCommandPromise(commandNameArg){
|
getCommandPromiseByName(commandNameArg: string) {
|
||||||
//TODO
|
return this.allCommandPromises.find(commandPromiseObjectArg => {
|
||||||
|
return commandPromiseObjectArg.commandName === commandNameArg
|
||||||
|
}).promise
|
||||||
}
|
}
|
||||||
addQuestion(definitionArg:{questionString:string,questionType:string}){
|
|
||||||
|
|
||||||
};
|
|
||||||
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) {
|
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
standardTask(){
|
|
||||||
let done = plugins.q.defer();
|
/**
|
||||||
|
* returns promise that is resolved when no commands are specified
|
||||||
|
*/
|
||||||
|
standardTask(): q.Promise<any> {
|
||||||
|
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;
|
|
||||||
}
|
}
|
||||||
startParse(){
|
})
|
||||||
this.argv = this.argv.argv;
|
return done.promise
|
||||||
this.parseStarted.resolve();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* start the process of evaluating commands
|
||||||
|
*/
|
||||||
|
startParse(): void {
|
||||||
|
this.argv = this.argv.argv
|
||||||
|
this.parseStarted.resolve()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,10 +1,15 @@
|
|||||||
import "typings-global";
|
import 'typings-global';
|
||||||
|
|
||||||
export let argv = require('yargs');
|
import * as yargs from 'yargs'
|
||||||
export import beautylog = require("beautylog");
|
import * as beautylog from 'beautylog'
|
||||||
export let cliff = require("cliff");
|
import * as lik from 'lik'
|
||||||
export let inquirer = require("inquirer");
|
import * as path from 'path'
|
||||||
export import lik = require("lik");
|
import * as smartparam from 'smartparam'
|
||||||
export let path = require("path");
|
|
||||||
export import q = require("q");
|
export {
|
||||||
export import smartparam = require("smartparam");
|
yargs,
|
||||||
|
beautylog,
|
||||||
|
lik,
|
||||||
|
path,
|
||||||
|
smartparam
|
||||||
|
}
|
||||||
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "tslint-config-standard"
|
||||||
|
}
|
Reference in New Issue
Block a user