Compare commits
61 Commits
Author | SHA1 | Date | |
---|---|---|---|
7ca18c4a46 | |||
b98e2a1a62 | |||
e102203422 | |||
92a37cf29b | |||
8408d1f3b5 | |||
d88e05466b | |||
3a789d052c | |||
d76d829e46 | |||
f8157ab8aa | |||
5c67015779 | |||
b67e3c0de1 | |||
c7a647d4ef | |||
9e5fb7a13a | |||
c115d222c0 | |||
643514c64a | |||
19498f7b11 | |||
3afadd9045 | |||
0889423a24 | |||
86b4cf4cc3 | |||
4cb4eabef4 | |||
bad0971f1c | |||
016f03bd8a | |||
63a9da11be | |||
ab18c75b28 | |||
088d4ef11b | |||
5ee866d9c6 | |||
d65061aaaa | |||
506bb0cdaf | |||
834a6c2953 | |||
e1c2de8a40 | |||
9e76f2afb1 | |||
cf78839e12 | |||
8733a601b4 | |||
fdd1761333 | |||
542c77069f | |||
96d82c3a20 | |||
ab8ce876a3 | |||
de4d3bcf3a | |||
75ab5552e1 | |||
eb3d9d722f | |||
c32f41cc23 | |||
cf03c6681b | |||
204c7105e8 | |||
ac0681507a | |||
d17053532b | |||
65d50ab238 | |||
7eed737120 | |||
8f72b3f2af | |||
fea330b8ff | |||
b51bbb00a4 | |||
5bd32f03c5 | |||
68f7e7fc03 | |||
55cdd7f803 | |||
5444f1d3c0 | |||
5611ad03aa | |||
d6cbefce2c | |||
afa6f885ad | |||
b1565dec3e | |||
f6969ecfd5 | |||
9bb85ca666 | |||
9442f738d9 |
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,6 +1,9 @@
|
||||
node_modules/
|
||||
.settings/
|
||||
.idea/
|
||||
coverage/
|
||||
pages/
|
||||
|
||||
|
||||
ts/*.js
|
||||
ts/*.js.map
|
||||
ts/typings/
|
||||
|
||||
|
50
.gitlab-ci.yml
Normal file
50
.gitlab-ci.yml
Normal file
@ -0,0 +1,50 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
- page
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- 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
|
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
0
.koding.yml
Normal file
0
.koding.yml
Normal file
20
.travis.yml
20
.travis.yml
@ -1,20 +0,0 @@
|
||||
language: node_js
|
||||
before_install:
|
||||
- nvm install stable
|
||||
- node -v
|
||||
- npm -v
|
||||
- npm install -g gulp
|
||||
- npm install gulp
|
||||
- npm install gulp-typescript
|
||||
deploy:
|
||||
provider: npm
|
||||
email: npm@smart-coordination.com
|
||||
api_key:
|
||||
secure: XAtA2XHAr96ILKpm1VnB/Nff9hiQv3FUa/NDfGZgvJKimuF/TwU2+kXyAag/LlEQGckZ9/IDx0PTIe8x4wOvg2VyKceYktGt6G5/MHeAXwzkkM253k2CKweVtBgnpZ2doTZXeeV/h7hHuEWZbWRXIVCgM6/inaaNe4cMRGCWqwb1xmw6D8VkLpNo6PiB37gR4GfMokasgVHZEVMg2evWKk0moREGW9XKqoE6PS9TPHPHerdqFqfbmeOq3nNgHrJZkNsAJ3PPESWCe/NGEBwtYDKrPI3QlouvXmxScI9/p2VCQmdFoUxKMDsVzBdRMrCx+XxoS8x81HxubZSpnvzUlzGtznZi7e6OyAlI7xXELIO551AH4V/pNWWUPATX+7vXVDGh7aAZYme/fejisjO5Tk9aqRvohh2jCDml3ED6alHHfI0oX5UvBpOE+XwGTIJ8qpf9RrLP5DC27JWE3fqY/WoqIZX7phoKeKYLl+R7Iln/dfvepbMBgcesnBf4PuMh3Qm2l2G1bElJ/hniV1dgggwjcg50nA0Ee9sCnORPxxjdDIMwJw//NJSe+Aq5Fm1ure9oNiBYOeF0bLVQyfGIC8J8coy1xdqv2klKnGHjMMN44bjNlmDp00SaRpbdDuavyocosQVpzfA+hY2QtGV5TXFv6TLgcMYwf8gNyVNkSGE=
|
||||
on:
|
||||
tags: true
|
||||
repo: pushrocks/smartcli
|
||||
notifications:
|
||||
slack:
|
||||
secure: f5Uss0z9RPl/QcA/DroB8loyE93aOYI6bqCkrsiUscmZtlv/TVQtT4dxqGA6uvcG6iTQDBi3Ul88dQxWkRm4IqbhY35/iMaV2dHW4FVYMAh8GQMbsfL2sALCcufxD9blw47awv3iFcwhV1EeyesscjgL0JIjduk96v/7G/6QIO2838M1lzlgtj+kRUkim8qkaEs1je3gRrhMUIjLuAdscMXyUKYFMjWo9ACSjVUl30R/ZNemb18itIja6i92GotreBgcfEMczvy58ovDC7xdJUsY8LjMI01DwY+WPRnI0tAhsuI8moBwwcdM4e3bAjKjucQRjO33O5bMWRZ6QCiYd0DnCEFyCPQLJ4GSy/tkD00n8ijLHAOSV3AH1zNbdK1EAdSPQXDvlI36KJn/2hyQLoitGHVUPr76ujJWP82ypO2tgIp3XQU0dJVCxDuHnwJO2+hjdI+gCPqxNTpjeujHx3UdkTGNRjuuf9dlZ/D08fApjYxy2fxItTqo3QjP/nrqvBXUOPP8yPHpjIT4H2t5Pr4SJjBGI6X4qhKyFj6s9rA/Xu1rL+45zu1C3uC3z+u3T9UwrbzJ/cZM6r6UQvQmUvIfBNaMlg4I/diQCDIPL+Rhop2nylY3IcHmJnk2itn7kOqj1tohCpFEml5pRuSZy4udWywkdtyBAsHWFLF7oiQ=
|
||||
email: false
|
55
README.md
55
README.md
@ -1,16 +1,47 @@
|
||||
# smartcli
|
||||
nodejs wrapper for CLI related tasks
|
||||
nodejs wrapper for CLI related tasks. TypeScript ready.
|
||||
|
||||
### Buildstatus/Dependencies
|
||||
[](https://travis-ci.org/pushrocks/smartcli)
|
||||
[](https://david-dm.org/pushrocks/smartcli#info=devDependencies)
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/smartcli)
|
||||
[](https://gitlab.com/pushrocks/smartcli)
|
||||
[](https://github.com/pushrocks/smartcli)
|
||||
[](https://pushrocks.gitlab.io/smartcli/docs)
|
||||
|
||||
### Usage
|
||||
This npm package comes with everything you need to start your own gulp plugin.
|
||||
## 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/)
|
||||
|
||||
We recommend modifying the ts/index.ts file,
|
||||
then run `npm install` to install the dev dependencies
|
||||
and use `npm test` to compile the TypeScript file.
|
||||
|
||||
Cheers
|
||||
Phil from Lossless Digital
|
||||
## 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
|
||||
```
|
2
dist/index.d.ts
vendored
Normal file
2
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import "typings-global";
|
||||
export { Smartcli } from "./smartcli.classes.smartcli";
|
5
dist/index.js
vendored
Normal file
5
dist/index.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
var smartcli_classes_smartcli_1 = require("./smartcli.classes.smartcli");
|
||||
exports.Smartcli = smartcli_classes_smartcli_1.Smartcli;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBR3hCLDBDQUF1Qiw2QkFBNkIsQ0FBQztBQUE3Qyx3REFBNkMifQ==
|
32
dist/smartcli.classes.interaction.d.ts
vendored
Normal file
32
dist/smartcli.classes.interaction.d.ts
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
import "typings-global";
|
||||
/**
|
||||
* allows to specify an user interaction during runtime
|
||||
*/
|
||||
export declare type questionType = "input" | "confirm" | "list" | "rawlist" | "expand" | "checkbox" | "password" | "editor";
|
||||
export interface choiceObject {
|
||||
name: string;
|
||||
value: any;
|
||||
}
|
||||
export interface validateFunction {
|
||||
(any: any): boolean;
|
||||
}
|
||||
export declare class Interaction {
|
||||
constructor();
|
||||
askQuestion(optionsArg: {
|
||||
type: questionType;
|
||||
message: string;
|
||||
default: any;
|
||||
choices: string[] | choiceObject[];
|
||||
validate: validateFunction;
|
||||
}): void;
|
||||
askQuestionArray: any;
|
||||
}
|
||||
export declare class QuestionTree {
|
||||
constructor(questionString: string, optionsArray: any);
|
||||
}
|
||||
export declare class QuestionTreeNode {
|
||||
constructor();
|
||||
}
|
||||
export declare class QuestionStorage {
|
||||
constructor();
|
||||
}
|
41
dist/smartcli.classes.interaction.js
vendored
Normal file
41
dist/smartcli.classes.interaction.js
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
const plugins = require("./smartcli.plugins");
|
||||
class Interaction {
|
||||
constructor() {
|
||||
}
|
||||
;
|
||||
askQuestion(optionsArg) {
|
||||
let done = plugins.q.defer();
|
||||
plugins.inquirer.prompt([{
|
||||
type: optionsArg.type,
|
||||
message: optionsArg.message,
|
||||
default: optionsArg.default,
|
||||
choices: optionsArg.choices,
|
||||
validate: optionsArg.validate
|
||||
}]).then(answers => {
|
||||
done.resolve(answers);
|
||||
});
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.Interaction = Interaction;
|
||||
class QuestionTree {
|
||||
constructor(questionString, optionsArray) {
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.QuestionTree = QuestionTree;
|
||||
;
|
||||
class QuestionTreeNode {
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
exports.QuestionTreeNode = QuestionTreeNode;
|
||||
;
|
||||
class QuestionStorage {
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
exports.QuestionStorage = QuestionStorage;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5pbnRlcmFjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuaW50ZXJhY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixNQUFZLE9BQU8sV0FBTSxvQkFBb0IsQ0FBQyxDQUFBO0FBZTlDO0lBQ0k7SUFDQSxDQUFDOztJQUVELFdBQVcsQ0FBQyxVQU1YO1FBQ0csSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUM3QixPQUFPLENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQyxDQUFDO2dCQUNyQixJQUFJLEVBQUUsVUFBVSxDQUFDLElBQUk7Z0JBQ3JCLE9BQU8sRUFBRSxVQUFVLENBQUMsT0FBTztnQkFDM0IsT0FBTyxFQUFFLFVBQVUsQ0FBQyxPQUFPO2dCQUMzQixPQUFPLEVBQUMsVUFBVSxDQUFDLE9BQU87Z0JBQzFCLFFBQVEsRUFBRSxVQUFVLENBQUMsUUFBUTthQUNoQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsT0FBTztZQUNaLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDMUIsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDOztBQUVMLENBQUM7QUF2QlksbUJBQVcsY0F1QnZCLENBQUE7QUFHRDtJQUVJLFlBQVksY0FBc0IsRUFBRSxZQUFZO0lBRWhELENBQUM7O0FBQ0wsQ0FBQztBQUxZLG9CQUFZLGVBS3hCLENBQUE7QUFBQSxDQUFDO0FBRUY7SUFDSTtJQUVBLENBQUM7QUFDTCxDQUFDO0FBSlksd0JBQWdCLG1CQUk1QixDQUFBO0FBQUEsQ0FBQztBQUVGO0lBQ0k7SUFFQSxDQUFDO0FBQ0wsQ0FBQztBQUpZLHVCQUFlLGtCQUkzQixDQUFBIn0=
|
52
dist/smartcli.classes.smartcli.d.ts
vendored
Normal file
52
dist/smartcli.classes.smartcli.d.ts
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/// <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;
|
||||
parseStarted: any;
|
||||
commands: any;
|
||||
questions: any;
|
||||
version: string;
|
||||
allCommandPromises: Objectmap<commandPromiseObject>;
|
||||
constructor();
|
||||
/**
|
||||
* adds an alias, meaning one equals the other in terms of triggering associated commands
|
||||
*/
|
||||
addAlias(keyArg: any, aliasArg: any): void;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
addCommand(definitionArg: {
|
||||
commandName: string;
|
||||
}): plugins.q.Promise<any>;
|
||||
/**
|
||||
* gets a Promise for a command word
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
* 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<any>;
|
||||
/**
|
||||
* start the process of evaluating commands
|
||||
*/
|
||||
startParse(): void;
|
||||
}
|
104
dist/smartcli.classes.smartcli.js
vendored
Normal file
104
dist/smartcli.classes.smartcli.js
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
"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.yargs;
|
||||
this.questionsDone = plugins.q.defer();
|
||||
this.parseStarted = plugins.q.defer();
|
||||
}
|
||||
;
|
||||
/**
|
||||
* adds an alias, meaning one equals the other in terms of triggering associated commands
|
||||
*/
|
||||
addAlias(keyArg, aliasArg) {
|
||||
this.argv = this.argv.alias(keyArg, aliasArg);
|
||||
return;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
addCommand(definitionArg) {
|
||||
let done = plugins.q.defer();
|
||||
this.parseStarted.promise
|
||||
.then(() => {
|
||||
if (this.argv._.indexOf(definitionArg.commandName) == 0) {
|
||||
done.resolve(this.argv);
|
||||
}
|
||||
else {
|
||||
done.reject(this.argv);
|
||||
}
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* gets a Promise for a command word
|
||||
*/
|
||||
getCommandPromiseByName(commandNameArg) {
|
||||
return this.allCommandPromises.find(commandPromiseObjectArg => {
|
||||
return commandPromiseObjectArg.commandName === commandNameArg;
|
||||
}).promise;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* 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");
|
||||
this.parseStarted.promise
|
||||
.then(() => {
|
||||
if (this.argv.v) {
|
||||
console.log(this.version);
|
||||
}
|
||||
});
|
||||
}
|
||||
;
|
||||
/**
|
||||
* returns promise that is resolved when no commands are specified
|
||||
*/
|
||||
standardTask() {
|
||||
let done = plugins.q.defer();
|
||||
this.parseStarted.promise
|
||||
.then(() => {
|
||||
if (this.argv._.length == 0 && !this.argv.v) {
|
||||
done.resolve(this.argv);
|
||||
}
|
||||
else {
|
||||
done.reject(this.argv);
|
||||
}
|
||||
;
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
/**
|
||||
* start the process of evaluating commands
|
||||
*/
|
||||
startParse() {
|
||||
this.argv = this.argv.argv;
|
||||
this.parseStarted.resolve();
|
||||
return;
|
||||
}
|
||||
}
|
||||
exports.Smartcli = Smartcli;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4QixNQUFZLE9BQU8sV0FBTSxvQkFBb0IsQ0FBQyxDQUFBO0FBRzlDLGlCQUFpQjtBQUNqQixzQkFBd0IsS0FBSyxDQUFDLENBQUE7QUFNN0IsQ0FBQztBQUVGO0lBVUk7UUFGQSxPQUFPO1FBQ1AsdUJBQWtCLEdBQUcsSUFBSSxlQUFTLEVBQXdCLENBQUM7UUFFdkQsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsS0FBSyxDQUFDO1FBQzFCLElBQUksQ0FBQyxhQUFhLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUN2QyxJQUFJLENBQUMsWUFBWSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDMUMsQ0FBQzs7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxNQUFNLEVBQUMsUUFBUTtRQUNwQixJQUFJLENBQUMsSUFBSSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLE1BQU0sRU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BQzNCLENBQUM7WUFBQSxDQUFDO1FBQ04sQ0FBQyxDQUFDLENBQUM7UUFDUCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxVQUFVO1FBQ04sSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQztRQUMzQixJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQzVCLE1BQU0sQ0FBQztJQUNYLENBQUM7QUFFTCxDQUFDO0FBdkdZLGdCQUFRLFdBdUdwQixDQUFBIn0=
|
9
dist/smartcli.plugins.d.ts
vendored
Normal file
9
dist/smartcli.plugins.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import "typings-global";
|
||||
export import yargs = require('yargs');
|
||||
export import beautylog = require("beautylog");
|
||||
export import cliff = require("cliff");
|
||||
export import inquirer = require("inquirer");
|
||||
export import lik = require("lik");
|
||||
export import path = require("path");
|
||||
export import q = require("q");
|
||||
export import smartparam = require("smartparam");
|
11
dist/smartcli.plugins.js
vendored
Normal file
11
dist/smartcli.plugins.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.yargs = require('yargs');
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.cliff = require("cliff");
|
||||
exports.inquirer = require("inquirer");
|
||||
exports.lik = require("lik");
|
||||
exports.path = require("path");
|
||||
exports.q = require("q");
|
||||
exports.smartparam = require("smartparam");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUVWLGFBQUssV0FBVyxPQUFPLENBQUMsQ0FBQztBQUN6QixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLGFBQUssV0FBVyxPQUFPLENBQUMsQ0FBQztBQUN6QixnQkFBUSxXQUFXLFVBQVUsQ0FBQyxDQUFDO0FBQy9CLFdBQUcsV0FBVyxLQUFLLENBQUMsQ0FBQztBQUNyQixZQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDdkIsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGtCQUFVLFdBQVcsWUFBWSxDQUFDLENBQUMifQ==
|
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
|
||||
```
|
113
index.js
113
index.js
@ -1,113 +0,0 @@
|
||||
/// <reference path="index.ts" />
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
/// <reference path="./interfaces.ts" />
|
||||
var path = require("path");
|
||||
var beautylog = require("beautylog");
|
||||
var cliff = require("cliff");
|
||||
var inquirer = require("inquirer");
|
||||
var argv = require('yargs').argv;
|
||||
//define the smartcli object
|
||||
var smartcli = {};
|
||||
//add plugins from above for direct use
|
||||
smartcli.inquirer = inquirer;
|
||||
smartcli.cliff = cliff;
|
||||
smartcli.argv = argv;
|
||||
/* ------------------------------------------------------------------------------
|
||||
*----------------------- initial call CLI args -----------------------------
|
||||
*----------------------------------------------------------------------------- */
|
||||
// commands
|
||||
smartcli.checkCommand = function (commandString) {
|
||||
if (argv._.indexOf(commandString) != -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
smartcli.getCommands = function () {
|
||||
return argv._;
|
||||
};
|
||||
// options
|
||||
smartcli.getOption = function (optionName) {
|
||||
if (argv.hasOwnProperty(optionName)) {
|
||||
return {
|
||||
name: optionName,
|
||||
specified: true,
|
||||
value: argv[optionName] //we already know from the "if" above that the value is available.
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: optionName,
|
||||
specified: false,
|
||||
value: false
|
||||
};
|
||||
};
|
||||
smartcli.getOptions = function () {
|
||||
var options = {};
|
||||
for (var key in argv) {
|
||||
if (key != "_") {
|
||||
options['key'] = argv['key'];
|
||||
}
|
||||
}
|
||||
return options;
|
||||
};
|
||||
/**
|
||||
* returns Directory of cwd
|
||||
* @returns {{path: string}}
|
||||
*/
|
||||
smartcli.getCwd = function () {
|
||||
return {
|
||||
path: process.cwd()
|
||||
};
|
||||
};
|
||||
/* ------------------------------------------------------------------------------
|
||||
*----------------------- in program CLI interaction -----------------------------
|
||||
*----------------------------------------------------------------------------- */
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
smartcli.getAnswer = function (questionString, cb) {
|
||||
if (typeof questionString != 'string') {
|
||||
beautylog.error('no question specified');
|
||||
return null;
|
||||
}
|
||||
//make inquirer compatible question object
|
||||
var question = {
|
||||
type: "input",
|
||||
name: "userFeedback",
|
||||
message: questionString,
|
||||
validate: function (value) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
inquirer.prompt([question], function (answers) {
|
||||
var answer = answers.userFeedback;
|
||||
cb(answer);
|
||||
});
|
||||
};
|
||||
/**
|
||||
*
|
||||
* @param questionString
|
||||
* @param choiceOptions
|
||||
* @param cb
|
||||
* @returns {null}
|
||||
*/
|
||||
smartcli.getChoice = function (questionString, choiceOptions, cb) {
|
||||
if (!Array.isArray(choiceOptions)) {
|
||||
return null;
|
||||
}
|
||||
//make inquirer compatible question object
|
||||
var question = {
|
||||
type: "list",
|
||||
name: "userFeedback",
|
||||
message: questionString,
|
||||
choices: choiceOptions,
|
||||
filter: function (val) { return val.toLowerCase(); }
|
||||
};
|
||||
inquirer.prompt(question, function (answers) {
|
||||
var answer = answers.userFeedback;
|
||||
cb(answer);
|
||||
});
|
||||
};
|
||||
module.exports = smartcli;
|
3
npmts.json
Normal file
3
npmts.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"mode":"default"
|
||||
}
|
33
package.json
33
package.json
@ -1,10 +1,12 @@
|
||||
{
|
||||
"name": "smartcli",
|
||||
"version": "0.0.8",
|
||||
"version": "1.0.9",
|
||||
"description": "nodejs wrapper for CLI related tasks",
|
||||
"main": "index.js",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(cd ts/compile && gulp)",
|
||||
"test": "(npmts)",
|
||||
"testm": "(cd ts/compile && gulp) && (node test.js jazz jam --awesome)",
|
||||
"devTest": "(npm test) && (node test.js --test true)",
|
||||
"reinstall": "(rm -r node_modules && npm install)",
|
||||
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
|
||||
@ -12,7 +14,7 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pushrocks/smartcli.git"
|
||||
"url": "https://gitlab.com/pushrocks/smartcli.git"
|
||||
},
|
||||
"keywords": [
|
||||
"json",
|
||||
@ -22,17 +24,26 @@
|
||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pushrocks/smartcli/issues"
|
||||
"url": "https://gitlab.com/pushrocks/smartcli/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/smartcli",
|
||||
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
||||
"dependencies": {
|
||||
"beautylog": "0.0.15",
|
||||
"@types/cliff": "^0.1.3",
|
||||
"@types/inquirer": "0.x.x",
|
||||
"@types/q": "0.x.x",
|
||||
"@types/yargs": "0.x.x",
|
||||
"beautylog": "^5.0.20",
|
||||
"cliff": "^0.1.10",
|
||||
"inquirer": "^0.10.1",
|
||||
"yargs": "^3.26.0"
|
||||
"inquirer": "^1.1.2",
|
||||
"lik": "^1.0.15",
|
||||
"q": "^1.4.1",
|
||||
"smartparam": "0.1.1",
|
||||
"typings-global": "^1.0.6",
|
||||
"yargs": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp": "3.9.0",
|
||||
"gulp-typescript": "2.9.2"
|
||||
"npmts-g": "^5.2.8",
|
||||
"should": "^11.1.0",
|
||||
"typings-test": "^1.0.1"
|
||||
}
|
||||
}
|
||||
|
45
test.js
45
test.js
@ -1,45 +0,0 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var smartcli = require("./index.js");
|
||||
var bl = require("beautylog");
|
||||
bl.log('now starting Test');
|
||||
bl.log('starting with initial CLI commands and options');
|
||||
var commandsString = 'You specified the following commands:';
|
||||
var commands = smartcli.getCommands();
|
||||
for (var key in commands) {
|
||||
commandsString = commandsString + ' ' + commands[key];
|
||||
}
|
||||
bl.log(commandsString);
|
||||
var getCwdTest = function () {
|
||||
console.log('The current directory is: ' + smartcli.getCwd().path);
|
||||
};
|
||||
var checkCommandTest = function () {
|
||||
if (smartcli.checkCommand('jazz')) {
|
||||
bl.log('One of your commands is jazz');
|
||||
}
|
||||
else {
|
||||
bl.log('None of your commands is jazz');
|
||||
}
|
||||
};
|
||||
var getOptionTest = function () {
|
||||
console.log('We now test for option --test');
|
||||
console.log(smartcli.getOption('test'));
|
||||
};
|
||||
var checkOptionTest = function () {
|
||||
};
|
||||
var getAnswerTest = function () {
|
||||
smartcli.getAnswer('How do you feel?', function (answer) {
|
||||
console.log('The answer is: ' + answer);
|
||||
getChoiceTest();
|
||||
});
|
||||
};
|
||||
var getChoiceTest = function () {
|
||||
smartcli.getChoice('What music do you like to hear?', ['Jazz', 'Blues', 'Classical'], function (answer) {
|
||||
console.log('The answer is: ' + answer);
|
||||
});
|
||||
};
|
||||
//starting command tests
|
||||
getCwdTest();
|
||||
checkCommandTest();
|
||||
getOptionTest();
|
||||
//starting first interaction test (the other tests are then started via callbacks)
|
||||
getAnswerTest();
|
1
test/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
import "typings-test";
|
36
test/test.js
Normal file
36
test/test.js
Normal file
@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const smartcli = require("../dist/index");
|
||||
let beautylog = require("beautylog");
|
||||
let should = require("should");
|
||||
describe("smartcli.Smartcli class", function () {
|
||||
let smartCliTestObject;
|
||||
describe("new Smartcli()", function () {
|
||||
it("should create a new Smartcli", function () {
|
||||
smartCliTestObject = new smartcli.Smartcli();
|
||||
smartCliTestObject.should.be.instanceof(smartcli.Smartcli);
|
||||
});
|
||||
});
|
||||
describe(".addCommand", function () {
|
||||
it("should add an command", function () {
|
||||
smartCliTestObject.addCommand({
|
||||
commandName: "awesome"
|
||||
});
|
||||
});
|
||||
});
|
||||
describe(".standardTask", function () {
|
||||
it("should start parsing a standardTask", function (done) {
|
||||
smartCliTestObject.standardTask()
|
||||
.then(() => {
|
||||
console.log("this is the standard Task!");
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe(".startParse", function () {
|
||||
it("should start parsing the CLI input", function () {
|
||||
smartCliTestObject.startParse();
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFFdEIsTUFBTyxRQUFRLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDM0MsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ3JDLElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUUvQixRQUFRLENBQUMseUJBQXlCLEVBQUM7SUFDL0IsSUFBSSxrQkFBb0M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C,CAAC;AACP,CAAC,CAAC;AAIF,IAAI,wBAAwB,GAAG;IAC3B,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,iCAAiC,EAAC,CAAC,MAAM,EAAC,OAAO,EAAC,WAAW,CAAC,EAAC,UAAS,MAAM;QACzG,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,MAAM,CAAC,CAAC;QACxC,QAAQ,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,IAAI,QAAQ,GAAG;IACX,SAAS,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC;IAC/B,SAAS,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF,EAAE,CAAA,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA,CAAC;IACjC,wBAAwB,EAAE,CAAC;AAC/B,CAAC;AAAC,IAAI,CAAC,CAAC;IACJ,SAAS,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAC;IAC3F,QAAQ,EAAE,CAAC;AACf,CAAC;AAAA,CAAC"}
|
37
test/test.ts
Normal file
37
test/test.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import "typings-test";
|
||||
|
||||
import smartcli = require("../dist/index");
|
||||
let beautylog = require("beautylog");
|
||||
let should = require("should");
|
||||
|
||||
describe("smartcli.Smartcli class",function(){
|
||||
let smartCliTestObject:smartcli.Smartcli;
|
||||
describe("new Smartcli()",function(){
|
||||
it("should create a new Smartcli",function(){
|
||||
smartCliTestObject = new smartcli.Smartcli();
|
||||
smartCliTestObject.should.be.instanceof(smartcli.Smartcli);
|
||||
});
|
||||
});
|
||||
describe(".addCommand",function(){
|
||||
it("should add an command",function(){
|
||||
smartCliTestObject.addCommand({
|
||||
commandName:"awesome"
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
describe(".standardTask",function(){
|
||||
it("should start parsing a standardTask",function(done){
|
||||
smartCliTestObject.standardTask()
|
||||
.then(() => {
|
||||
console.log("this is the standard Task!");
|
||||
});
|
||||
done();
|
||||
})
|
||||
})
|
||||
describe(".startParse",function(){
|
||||
it("should start parsing the CLI input",function(){
|
||||
smartCliTestObject.startParse();
|
||||
})
|
||||
})
|
||||
});
|
@ -1,25 +0,0 @@
|
||||
// import gulp
|
||||
var gulp = require("gulp"),
|
||||
gulpTypescript = require("gulp-typescript");
|
||||
|
||||
gulp.task('compileTS', function() {
|
||||
var stream = gulp.src('../index.ts')
|
||||
.pipe(gulpTypescript({
|
||||
out: "index.js"
|
||||
}))
|
||||
.pipe(gulp.dest("../../"));
|
||||
return stream;
|
||||
});
|
||||
|
||||
gulp.task('compileTestTS', function() {
|
||||
var stream = gulp.src('../test.ts')
|
||||
.pipe(gulpTypescript({
|
||||
out: "test.js"
|
||||
}))
|
||||
.pipe(gulp.dest("../../"));
|
||||
return stream;
|
||||
});
|
||||
|
||||
gulp.task('default',['compileTS','compileTestTS'], function() {
|
||||
console.log('Typescript compiled');
|
||||
});
|
@ -1,2 +0,0 @@
|
||||
# How to compile.
|
||||
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.
|
141
ts/index.ts
141
ts/index.ts
@ -1,139 +1,4 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
/// <reference path="./interfaces.ts" />
|
||||
import "typings-global";
|
||||
|
||||
var path = require("path");
|
||||
var beautylog = require("beautylog");
|
||||
var cliff = require("cliff");
|
||||
var inquirer = require("inquirer");
|
||||
var argv = require('yargs').argv;
|
||||
|
||||
//define the smartcli object
|
||||
var smartcli:any = {};
|
||||
|
||||
//add plugins from above for direct use
|
||||
smartcli.inquirer = inquirer;
|
||||
smartcli.cliff = cliff;
|
||||
smartcli.argv = argv;
|
||||
|
||||
/* ------------------------------------------------------------------------------
|
||||
*----------------------- initial call CLI args -----------------------------
|
||||
*----------------------------------------------------------------------------- */
|
||||
|
||||
// commands
|
||||
|
||||
|
||||
smartcli.checkCommand = function(commandString:string):boolean {
|
||||
if (argv._.indexOf(commandString) != -1) {
|
||||
return true
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
smartcli.getCommands = function ():string[] {
|
||||
return argv._;
|
||||
};
|
||||
|
||||
|
||||
// options
|
||||
smartcli.getOption = function(optionName:string):CliOption {
|
||||
if (argv.hasOwnProperty(optionName)) {
|
||||
return {
|
||||
name:optionName,
|
||||
specified: true,
|
||||
value: argv[optionName] //we already know from the "if" above that the value is available.
|
||||
};
|
||||
|
||||
}
|
||||
return {
|
||||
name:optionName,
|
||||
specified: false,
|
||||
value: false
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
smartcli.getOptions = function() {
|
||||
var options = {};
|
||||
for (var key in argv) {
|
||||
if (key != "_") {
|
||||
options['key'] = argv['key'];
|
||||
}
|
||||
}
|
||||
return options;
|
||||
};
|
||||
|
||||
/**
|
||||
* returns Directory of cwd
|
||||
* @returns {{path: string}}
|
||||
*/
|
||||
smartcli.getCwd = function():Directory {
|
||||
return {
|
||||
path: process.cwd()
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------
|
||||
*----------------------- in program CLI interaction -----------------------------
|
||||
*----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
smartcli.getAnswer = function(questionString:string, cb) {
|
||||
if (typeof questionString != 'string') {
|
||||
beautylog.error('no question specified');
|
||||
return null;
|
||||
}
|
||||
//make inquirer compatible question object
|
||||
var question = {
|
||||
type: "input",
|
||||
name: "userFeedback",
|
||||
message: questionString,
|
||||
validate: function( value ) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
inquirer.prompt([question],function(answers){
|
||||
var answer = answers.userFeedback;
|
||||
cb(answer);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param questionString
|
||||
* @param choiceOptions
|
||||
* @param cb
|
||||
* @returns {null}
|
||||
*/
|
||||
smartcli.getChoice = function(questionString:string, choiceOptions:string[], cb) {
|
||||
if(!Array.isArray(choiceOptions)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//make inquirer compatible question object
|
||||
var question = {
|
||||
type: "list",
|
||||
name: "userFeedback",
|
||||
message: questionString,
|
||||
choices: choiceOptions,
|
||||
filter: function( val ) { return val.toLowerCase(); }
|
||||
};
|
||||
|
||||
inquirer.prompt(question,function(answers){
|
||||
var answer = answers.userFeedback;
|
||||
cb(answer);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
module.exports = smartcli;
|
||||
import {Smartcli} from "./smartcli.classes.smartcli";
|
||||
export {Smartcli} from "./smartcli.classes.smartcli";
|
||||
|
@ -1,11 +0,0 @@
|
||||
/// <reference path="index.ts" />
|
||||
interface CliOption {
|
||||
name: string;
|
||||
specified:boolean;
|
||||
value: any;
|
||||
}
|
||||
|
||||
interface Directory {
|
||||
path: string;
|
||||
}
|
||||
|
60
ts/smartcli.classes.interaction.ts
Normal file
60
ts/smartcli.classes.interaction.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./smartcli.plugins";
|
||||
|
||||
/**
|
||||
* allows to specify an user interaction during runtime
|
||||
*/
|
||||
|
||||
export type questionType = "input" | "confirm" | "list" | "rawlist" | "expand" | "checkbox" | "password" | "editor"
|
||||
export interface choiceObject {
|
||||
name: string;
|
||||
value: any
|
||||
}
|
||||
export interface validateFunction {
|
||||
(any):boolean
|
||||
}
|
||||
|
||||
export class Interaction {
|
||||
constructor() {
|
||||
};
|
||||
|
||||
askQuestion(optionsArg: {
|
||||
type: questionType,
|
||||
message: string
|
||||
default: any
|
||||
choices: string[] | choiceObject[];
|
||||
validate: validateFunction
|
||||
}) {
|
||||
let done = plugins.q.defer();
|
||||
plugins.inquirer.prompt([{
|
||||
type: optionsArg.type,
|
||||
message: optionsArg.message,
|
||||
default: optionsArg.default,
|
||||
choices:optionsArg.choices,
|
||||
validate: optionsArg.validate
|
||||
}]).then(answers => {
|
||||
done.resolve(answers);
|
||||
});
|
||||
};
|
||||
askQuestionArray
|
||||
}
|
||||
|
||||
|
||||
export class QuestionTree {
|
||||
|
||||
constructor(questionString: string, optionsArray) {
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
export class QuestionTreeNode {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
export class QuestionStorage {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
118
ts/smartcli.classes.smartcli.ts
Normal file
118
ts/smartcli.classes.smartcli.ts
Normal file
@ -0,0 +1,118 @@
|
||||
import "typings-global";
|
||||
|
||||
import * as plugins from "./smartcli.plugins";
|
||||
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:any;
|
||||
questionsDone;
|
||||
parseStarted;
|
||||
commands;
|
||||
questions;
|
||||
version:string;
|
||||
|
||||
// maps
|
||||
allCommandPromises = new Objectmap<commandPromiseObject>();
|
||||
constructor(){
|
||||
this.argv = plugins.yargs;
|
||||
this.questionsDone = plugins.q.defer();
|
||||
this.parseStarted = plugins.q.defer();
|
||||
};
|
||||
|
||||
/**
|
||||
* adds an alias, meaning one equals the other in terms of triggering associated commands
|
||||
*/
|
||||
addAlias(keyArg,aliasArg):void {
|
||||
this.argv = this.argv.alias(keyArg,aliasArg);
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
addCommand(definitionArg:{commandName:string}):plugins.q.Promise<any>{
|
||||
let done = plugins.q.defer<any>();
|
||||
this.parseStarted.promise
|
||||
.then(() => {
|
||||
if (this.argv._.indexOf(definitionArg.commandName) == 0) {
|
||||
done.resolve(this.argv);
|
||||
} else {
|
||||
done.reject(this.argv);
|
||||
}
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* gets a Promise for a command word
|
||||
*/
|
||||
getCommandPromiseByName(commandNameArg:string){
|
||||
return this.allCommandPromises.find(commandPromiseObjectArg => {
|
||||
return commandPromiseObjectArg.commandName === commandNameArg;
|
||||
}).promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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");
|
||||
this.parseStarted.promise
|
||||
.then(() => {
|
||||
if(this.argv.v){
|
||||
console.log(this.version);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
/**
|
||||
* returns promise that is resolved when no commands are specified
|
||||
*/
|
||||
standardTask():plugins.q.Promise<any>{
|
||||
let done = plugins.q.defer<any>();
|
||||
this.parseStarted.promise
|
||||
.then(() => {
|
||||
if(this.argv._.length == 0 && !this.argv.v){
|
||||
done.resolve(this.argv);
|
||||
} else {
|
||||
done.reject(this.argv);
|
||||
};
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* start the process of evaluating commands
|
||||
*/
|
||||
startParse():void{
|
||||
this.argv = this.argv.argv;
|
||||
this.parseStarted.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
10
ts/smartcli.plugins.ts
Normal file
10
ts/smartcli.plugins.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import "typings-global";
|
||||
|
||||
export import yargs = require('yargs');
|
||||
export import beautylog = require("beautylog");
|
||||
export import cliff = require("cliff");
|
||||
export import inquirer = require("inquirer");
|
||||
export import lik = require("lik");
|
||||
export import path = require("path");
|
||||
export import q = require("q");
|
||||
export import smartparam = require("smartparam");
|
58
ts/test.ts
58
ts/test.ts
@ -1,58 +0,0 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var smartcli = require("./index.js");
|
||||
var bl = require("beautylog");
|
||||
|
||||
bl.log('now starting Test');
|
||||
bl.log('starting with initial CLI commands and options');
|
||||
|
||||
var commandsString:string = 'You specified the following commands:';
|
||||
var commands = smartcli.getCommands();
|
||||
for (var key in commands) {
|
||||
commandsString = commandsString + ' ' + commands[key];
|
||||
}
|
||||
bl.log(commandsString);
|
||||
|
||||
|
||||
var getCwdTest = function(){
|
||||
console.log('The current directory is: ' + smartcli.getCwd().path);
|
||||
};
|
||||
|
||||
var checkCommandTest = function() {
|
||||
if (smartcli.checkCommand('jazz')) {
|
||||
bl.log('One of your commands is jazz');
|
||||
} else {
|
||||
bl.log('None of your commands is jazz');
|
||||
}
|
||||
};
|
||||
|
||||
var getOptionTest = function() {
|
||||
console.log('We now test for option --test')
|
||||
console.log(smartcli.getOption('test'));
|
||||
}
|
||||
|
||||
var checkOptionTest = function() {
|
||||
|
||||
};
|
||||
|
||||
var getAnswerTest = function() {
|
||||
smartcli.getAnswer('How do you feel?',function(answer){
|
||||
console.log('The answer is: ' + answer);
|
||||
getChoiceTest();
|
||||
});
|
||||
};
|
||||
|
||||
var getChoiceTest = function() {
|
||||
smartcli.getChoice('What music do you like to hear?',['Jazz','Blues','Classical'],function(answer){
|
||||
console.log('The answer is: ' + answer);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
//starting command tests
|
||||
getCwdTest();
|
||||
checkCommandTest();
|
||||
getOptionTest();
|
||||
|
||||
//starting first interaction test (the other tests are then started via callbacks)
|
||||
getAnswerTest();
|
12
ts/tsd.json
12
ts/tsd.json
@ -1,12 +0,0 @@
|
||||
{
|
||||
"version": "v4",
|
||||
"repo": "borisyankov/DefinitelyTyped",
|
||||
"ref": "master",
|
||||
"path": "typings",
|
||||
"bundle": "typings/tsd.d.ts",
|
||||
"installed": {
|
||||
"node/node.d.ts": {
|
||||
"commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63"
|
||||
}
|
||||
}
|
||||
}
|
2079
ts/typings/node/node.d.ts
vendored
2079
ts/typings/node/node.d.ts
vendored
File diff suppressed because it is too large
Load Diff
1
ts/typings/tsd.d.ts
vendored
1
ts/typings/tsd.d.ts
vendored
@ -1 +0,0 @@
|
||||
/// <reference path="node/node.d.ts" />
|
Reference in New Issue
Block a user