Compare commits
51 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 | |||
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 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,8 +1,6 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
.settings/
|
|
||||||
.idea/
|
|
||||||
coverage/
|
coverage/
|
||||||
docs/
|
pages/
|
||||||
|
|
||||||
|
|
||||||
ts/*.js
|
ts/*.js
|
||||||
|
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>
|
|
17
.travis.yml
17
.travis.yml
@ -1,17 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- "4.2.2"
|
|
||||||
before_install:
|
|
||||||
- npm install -g tsd
|
|
||||||
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
|
|
60
README.md
60
README.md
@ -1,11 +1,20 @@
|
|||||||
# smartcli
|
# smartcli
|
||||||
nodejs wrapper for CLI related tasks
|
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,40 +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)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import {Smartcli} from "smartcli"
|
||||||
|
mySmartcli = new Smartcli();
|
||||||
|
mySmartcli.standardTask()
|
||||||
|
.then(argvArg => {
|
||||||
|
// do something if program is called without an command
|
||||||
|
});
|
||||||
|
|
||||||
### The inner organization of smartcli
|
mySmartcli.addCommand({commandname: 'install'})
|
||||||
**smartcli** exposes three major groups of functions:
|
.then(argvArg => {
|
||||||
|
// do something if program is called with command "install"
|
||||||
* 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
|
|
||||||
|
|
||||||
```js
|
|
||||||
var smartcli = require("smartcli");
|
|
||||||
|
|
||||||
/* -------------- Check Functions -------------------*/
|
|
||||||
//returns true for terminal command "node myjs.js jazz"
|
|
||||||
smartcli.check.command('jazz');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns an object for terminal command "node myjs.js --myoption something" like so
|
|
||||||
* {
|
|
||||||
* name: 'myoption',
|
|
||||||
* specified: true,
|
|
||||||
* value: 'something'
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
smartcli.get.option('myoption');
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
||||||
|
1
dist/index.d.ts
vendored
Normal file
1
dist/index.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { Smartcli } from './smartcli.classes.smartcli';
|
29
dist/index.js
vendored
29
dist/index.js
vendored
@ -1,27 +1,4 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
/// <reference path="./smartcli.interfaces.ts" />
|
|
||||||
"use strict";
|
"use strict";
|
||||||
var plugins = require("./smartcli.plugins");
|
var smartcli_classes_smartcli_1 = require("./smartcli.classes.smartcli");
|
||||||
var SmartcliChecks = require("./smartcli.checks");
|
exports.Smartcli = smartcli_classes_smartcli_1.Smartcli;
|
||||||
var SmartcliGetters = require("./smartcli.getters");
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEseUVBQXNEO0FBQTdDLCtDQUFBLFFBQVEsQ0FBQSJ9
|
||||||
var SmartcliInteractions = require("./smartcli.interaction");
|
|
||||||
/* ------------------------------------------------ *
|
|
||||||
* ---------- plugins for direct use -------------- *
|
|
||||||
* ------------------------------------------------ */
|
|
||||||
exports.inquirer = plugins.inquirer; //inquirer is for asking questions
|
|
||||||
exports.cliff = plugins.cliff; // formats cli output
|
|
||||||
exports.argv = plugins.argv; //argv gets initial cli commands and options.
|
|
||||||
/* ------------------------------------------------ *
|
|
||||||
* ---------- checks ------------------------------ *
|
|
||||||
* ------------------------------------------------ */
|
|
||||||
exports.check = SmartcliChecks;
|
|
||||||
/* ------------------------------------------------ *
|
|
||||||
* ---------- getters ----------------------------- *
|
|
||||||
* ------------------------------------------------ */
|
|
||||||
exports.get = SmartcliGetters;
|
|
||||||
/* ------------------------------------------------ *
|
|
||||||
* ---------- interaction ----------------------------- *
|
|
||||||
* ------------------------------------------------ */
|
|
||||||
exports.interaction = SmartcliInteractions;
|
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDB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S0tLS0tLS0tLS0tLSAqL1xuZXhwb3J0IGxldCBnZXQgPSBTbWFydGNsaUdldHRlcnM7XG5cbi8qIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqXG4gKiAtLS0tLS0tLS0tIGludGVyYWN0aW9uIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICpcbiAqIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqL1xuZXhwb3J0IGxldCBpbnRlcmFjdGlvbiA9IFNtYXJ0Y2xpSW50ZXJhY3Rpb25zO1xuIl0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
|
|
62
dist/smartcli.checks.js
vendored
62
dist/smartcli.checks.js
vendored
@ -1,62 +0,0 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
/// <reference path="./smartcli.interfaces.ts" />
|
|
||||||
"use strict";
|
|
||||||
var plugins = require("./smartcli.plugins");
|
|
||||||
/**
|
|
||||||
* checks for a special command string and returns true if found.
|
|
||||||
* @param commandString
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
exports.command = function (commandString) {
|
|
||||||
if (plugins.argv._.indexOf(commandString) == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* checks if a command is present, returns true if yes, false if no.
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
exports.commandPresence = function () {
|
|
||||||
if (plugins.argv._.length > 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* checks for an special command argument at a certain position, returns true if matches, returns false if not
|
|
||||||
* @param level
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
exports.commandArgument = function (commandArgumentString, level) {
|
|
||||||
if (level === void 0) { level = 1; }
|
|
||||||
if (exports.commandArgumentPresence(level) && (plugins.argv._[level] == commandArgumentString)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
exports.commandArgumentPresence = function (level) {
|
|
||||||
if (level === void 0) { level = 1; }
|
|
||||||
if (plugins.argv._.length >= (level + 1)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* checks for a specific option string, returns true if yes, returns false if no
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
exports.option = function (optionString) {
|
|
||||||
if (plugins.smartparam.exists(plugins.argv, optionString)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
exports.optionPresence = function () {
|
|
||||||
if (plugins.argv.indexOf() != -1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNoZWNrcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSwwQ0FBMEM7QUFDMUMsaURBQWlEOztBQUVqRCxJQUFPLE9BQU8sV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBRS9DOzs7O0dBSUc7QUFDUSxlQUFPLEdBQUcsVUFBUyxhQUFvQjtJQUM5QyxFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxPQUFPLENBQUMsYUFBYSxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUM3QyxNQUFNLENBQUMsSUFBSSxDQUFBO0lBQ2YsQ0FBQztJQUNELE1BQU0sQ0FBQyxLQUFLLENBQUM7QUFDakIsQ0FBQyxDQUFDO0FBRUY7OztHQUdHO0FBQ1EsdUJBQWUsR0FBRztJQUN6QixFQ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cmV0dXJucyB0cnVlIGlmIHllcywgcmV0dXJucyBmYWxzZSBpZiBub1xuICogQHJldHVybnMge2Jvb2xlYW59XG4gKi9cbmV4cG9ydCBsZXQgb3B0aW9uID0gZnVuY3Rpb24ob3B0aW9uU3RyaW5nKTpib29sZWFuIHtcbiAgICBpZihwbHVnaW5zLnNtYXJ0cGFyYW0uZXhpc3RzKHBsdWdpbnMuYXJndiwgb3B0aW9uU3RyaW5nKSkge1xuICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICB9XG4gICAgcmV0dXJuIGZhbHNlO1xufTtcblxuZXhwb3J0IGxldCBvcHRpb25QcmVzZW5jZSA9IGZ1bmN0aW9uKCk6Ym9vbGVhbiB7XG4gICAgaWYgKHBsdWdpbnMuYXJndi5pbmRleE9mKCkgIT0gLTEpIHtcbiAgICAgICAgcmV0dXJuIHRydWVcbiAgICB9XG4gICAgcmV0dXJuIGZhbHNlO1xufTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
|
50
dist/smartcli.classes.smartcli.d.ts
vendored
Normal file
50
dist/smartcli.classes.smartcli.d.ts
vendored
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/// <reference types="q" />
|
||||||
|
import * as q from 'q';
|
||||||
|
import { Objectmap } from 'lik';
|
||||||
|
export interface ICommandPromiseObject {
|
||||||
|
commandName: string;
|
||||||
|
promise: q.Promise<any>;
|
||||||
|
}
|
||||||
|
export declare class Smartcli {
|
||||||
|
argv: any;
|
||||||
|
questionsDone: any;
|
||||||
|
parseStarted: any;
|
||||||
|
commands: any;
|
||||||
|
questions: any;
|
||||||
|
version: string;
|
||||||
|
allCommandPromises: Objectmap<ICommandPromiseObject>;
|
||||||
|
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;
|
||||||
|
}): q.Promise<any>;
|
||||||
|
/**
|
||||||
|
* gets a Promise for a command word
|
||||||
|
*/
|
||||||
|
getCommandPromiseByName(commandNameArg: string): 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(): q.Promise<any>;
|
||||||
|
/**
|
||||||
|
* start the process of evaluating commands
|
||||||
|
*/
|
||||||
|
startParse(): void;
|
||||||
|
}
|
95
dist/smartcli.classes.smartcli.js
vendored
Normal file
95
dist/smartcli.classes.smartcli.js
vendored
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
"use strict";
|
||||||
|
const q = require("q");
|
||||||
|
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 = q.defer();
|
||||||
|
this.parseStarted = 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 = 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 = 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHVCQUFzQjtBQUV0Qiw4Q0FBNkM7QUFFN0MsaUJBQWlCO0FBQ2pCLDZCQUE2QjtBQVE3QjtJQVVJO1FBRkEsT0FBTztRQUNQLHVCQUFrQixHQUFHLElBQUksZUFBUyxFQUF5QixDQUFBO1FBRXZELElBQUksQ0FBQyxJQUFJLEdBQUcsT0FBTyxDQUFDLEtBQUssQ0FBQTtRQUN6QixJQUFJLENBQUMsYUFBYSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUM5QixJQUFJLENBQUMsWUFBWSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUNqQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxRQUFRLENBQUMsTUFBTSxFQUFDLFFBQVE7UUFDcEIsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxNQUFNLEVBQUMsUUFBUSxDQUFDLENBQUE7UUFDNUMsTUFBTSxDQUFBO0lBQ1YsQ0FBQztJQUVEOzs7T0FHRztJQUNILFVBQVUsQ0FBQyxhQUFvQztRQUMzQyxJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFPLENBQUE7UUFDekIsSUFBSSxDQUFDLFlBQVksQ0FB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QyxPQUFPLEVBQUUsQ0FBQTtRQUMzQixNQUFNLENBQUE7SUFDVixDQUFDO0NBRUo7QUF0R0QsNEJBc0dDIn0=
|
103
dist/smartcli.getters.js
vendored
103
dist/smartcli.getters.js
vendored
File diff suppressed because one or more lines are too long
55
dist/smartcli.interaction.js
vendored
55
dist/smartcli.interaction.js
vendored
@ -1,55 +0,0 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
/// <reference path="./smartcli.interfaces.ts" />
|
|
||||||
"use strict";
|
|
||||||
var 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
|
|
||||||
var question = {
|
|
||||||
type: "input",
|
|
||||||
name: "userFeedback",
|
|
||||||
message: questionString,
|
|
||||||
validate: function (value) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
plugins.inquirer.prompt([question], function (answers) {
|
|
||||||
var 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
|
|
||||||
var question = {
|
|
||||||
type: "list",
|
|
||||||
name: "userFeedback",
|
|
||||||
message: questionString,
|
|
||||||
choices: choiceOptions,
|
|
||||||
filter: function (val) { return val.toLowerCase(); }
|
|
||||||
};
|
|
||||||
plugins.inquirer.prompt(question, function (answers) {
|
|
||||||
var answer = answers.userFeedback;
|
|
||||||
cb(answer);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmludGVyYWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDBDQUEwQztBQUMxQyxpREFBaUQ7O0FBRWpELElBQU8sT0FBTyxXQUFXLG9CQUFvQixDQUFDLENBQUM7QUFFL0M7Ozs7O0dBS0c7QUFDUSxpQkFBUyxHQUFHLFVBQVMsY0FBcUIsRUFBRSxFQUFFO0lBQ3JELEVBQUUsQ0FBQyxDQUFDLE9BQU8sY0FBYyxJQUFJLFFBQVEsQ0FBQyxDQUFDLENBQUM7UUFDcEMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxLQUFLLENBQUMsdUJBQXVCLENBQUMsQ0FBQztRQUNqRCxNQUFNLENBQUMsSUFBSSxDQUFDO0lBQ2hCLENBQUM7SUFDRCwwQ0FBMEM7SUFDMUMsSUFBSSxRQUFRLEdBQUc7UUFDWCxJQUFJLEVBQUUsT0FBTztRQUNiLElBQUksRUFBRSxjQUFjO1FBQ3BCLE9BQU8sRUFBRSxjQUFjO1FBQ3ZCLFFBQVEsRUFBRSxVQUFVLEtBQUs7WUFDckIsTUFBTSxDQUFDLElBQUksQ0FBQztRQUNoQixDQUFDO0tBQ0osQ0FBQztJQUVGLE9BQU8sQ0FBQyxRQUFRLENBQUMsTUFBTSxDQUFDLENBQUMsUUFBUSxDQUFDLEVBQUMsVUFBUyxPQUFPO1FBQy9DLElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUM7UUFDbEMsRUFBRSxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBQ2YsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUM7QUFFR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GlvbnNcbiAqIEBwYXJhbSBjYlxuICogQHJldHVybnMge251bGx9XG4gKi9cbmV4cG9ydCBsZXQgZ2V0Q2hvaWNlID0gZnVuY3Rpb24ocXVlc3Rpb25TdHJpbmc6c3RyaW5nLCBjaG9pY2VPcHRpb25zOnN0cmluZ1tdLCBjYikge1xuICAgIGlmKCFBcnJheS5pc0FycmF5KGNob2ljZU9wdGlvbnMpKSB7XG4gICAgICAgIHJldHVybiBudWxsO1xuICAgIH1cblxuICAgIC8vbWFrZSBpbnF1aXJlciBjb21wYXRpYmxlIHF1ZXN0aW9uIG9iamVjdFxuICAgIHZhciBxdWVzdGlvbiA9IHtcbiAgICAgICAgdHlwZTogXCJsaXN0XCIsXG4gICAgICAgIG5hbWU6IFwidXNlckZlZWRiYWNrXCIsXG4gICAgICAgIG1lc3NhZ2U6IHF1ZXN0aW9uU3RyaW5nLFxuICAgICAgICBjaG9pY2VzOiBjaG9pY2VPcHRpb25zLFxuICAgICAgICBmaWx0ZXI6IGZ1bmN0aW9uKCB2YWwgKSB7IHJldHVybiB2YWwudG9Mb3dlckNhc2UoKTsgfVxuICAgIH07XG5cbiAgICBwbHVnaW5zLmlucXVpcmVyLnByb21wdChxdWVzdGlvbixmdW5jdGlvbihhbnN3ZXJzKXtcbiAgICAgICAgdmFyIGFuc3dlciA9IGFuc3dlcnMudXNlckZlZWRiYWNrO1xuICAgICAgICBjYihhbnN3ZXIpO1xuICAgIH0pO1xuXG59OyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
|
3
dist/smartcli.interfaces.js
vendored
3
dist/smartcli.interfaces.js
vendored
@ -1,3 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJzbWFydGNsaS5pbnRlcmZhY2VzLmpzIiwic291cmNlc0NvbnRlbnQiOltdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
|
7
dist/smartcli.plugins.d.ts
vendored
Normal file
7
dist/smartcli.plugins.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import 'typings-global';
|
||||||
|
import * as yargs from 'yargs';
|
||||||
|
import * as beautylog from 'beautylog';
|
||||||
|
import * as lik from 'lik';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as smartparam from 'smartparam';
|
||||||
|
export { yargs, beautylog, lik, path, smartparam };
|
21
dist/smartcli.plugins.js
vendored
21
dist/smartcli.plugins.js
vendored
@ -1,10 +1,13 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
"use strict";
|
"use strict";
|
||||||
exports.path = require("path");
|
require("typings-global");
|
||||||
exports.beautylog = require("beautylog");
|
const yargs = require("yargs");
|
||||||
exports.cliff = require("cliff");
|
exports.yargs = yargs;
|
||||||
exports.inquirer = require("inquirer");
|
const beautylog = require("beautylog");
|
||||||
exports.smartparam = require("smartparam");
|
exports.beautylog = beautylog;
|
||||||
exports.argv = require('yargs').argv;
|
const lik = require("lik");
|
||||||
|
exports.lik = lik;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsMENBQTBDOztBQUUvQixZQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLGlCQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLGFBQUssR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7QUFDekIsZ0JBQVEsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDLENBQUM7QUFDL0Isa0JBQVUsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUM7QUFDbkMsWUFBSSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQyxJQUFJLENBQUMiLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCJ0eXBpbmdzL21haW4uZC50c1wiIC8+XG5cbmV4cG9ydCBsZXQgcGF0aCA9IHJlcXVpcmUoXCJwYXRoXCIpO1xuZXhwb3J0IGxldCBiZWF1dHlsb2cgPSByZXF1aXJlKFwiYmVhdXR5bG9nXCIpO1xuZXhwb3J0IGxldCBjbGlmZiA9IHJlcXVpcmUoXCJjbGlmZlwiKTtcbmV4cG9ydCBsZXQgaW5xdWlyZXIgPSByZXF1aXJlKFwiaW5xdWlyZXJcIik7XG5leHBvcnQgbGV0IHNtYXJ0cGFyYW0gPSByZXF1aXJlKFwic21hcnRwYXJhbVwiKTtcbmV4cG9ydCBsZXQgYXJndiA9IHJlcXVpcmUoJ3lhcmdzJykuYXJndjsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
const path = require("path");
|
||||||
|
exports.path = path;
|
||||||
|
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
|
||||||
|
```
|
3
npmts.json
Normal file
3
npmts.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"mode":"default"
|
||||||
|
}
|
29
package.json
29
package.json
@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "smartcli",
|
"name": "smartcli",
|
||||||
"version": "0.0.13",
|
"version": "1.0.13",
|
||||||
"description": "nodejs wrapper for CLI related tasks",
|
"description": "nodejs wrapper for CLI related tasks",
|
||||||
"main": "index.js",
|
"main": "dist/index.js",
|
||||||
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)",
|
"test": "(npmts)",
|
||||||
"testm": "(cd ts/compile && gulp) && (node test.js jazz jam --awesome)",
|
"testm": "(cd ts/compile && gulp) && (node test.js jazz jam --awesome)",
|
||||||
@ -13,7 +14,7 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/pushrocks/smartcli.git"
|
"url": "https://gitlab.com/pushrocks/smartcli.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"json",
|
"json",
|
||||||
@ -23,17 +24,23 @@
|
|||||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"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": {
|
"dependencies": {
|
||||||
"beautylog": "4.1.2",
|
"@types/q": "0.x.x",
|
||||||
"cliff": "^0.1.10",
|
"@types/yargs": "6.x.x",
|
||||||
"inquirer": "^0.12.0",
|
"beautylog": "^6.0.0",
|
||||||
"smartparam": "0.0.7",
|
"lik": "^1.0.24",
|
||||||
"yargs": "^4.3.2"
|
"q": "^1.4.1",
|
||||||
|
"smartparam": "0.1.1",
|
||||||
|
"typings-global": "^1.0.14",
|
||||||
|
"yargs": "^6.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts": "^5.0.3"
|
"@types/should": "^8.1.30",
|
||||||
|
"npmts-g": "^5.2.8",
|
||||||
|
"should": "^11.1.1",
|
||||||
|
"typings-test": "^1.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
test/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import 'typings-test';
|
175
test/test.js
175
test/test.js
@ -1,150 +1,35 @@
|
|||||||
/// <reference path="../ts/typings/main.d.ts" />
|
"use strict";
|
||||||
var smartcli = require("../dist/index.js");
|
require("typings-test");
|
||||||
var should = req;
|
const smartcli = require("../dist/index");
|
||||||
/* ------------------------------------------------------------------ *
|
const should = require("should");
|
||||||
* ------------------- CHECKS TESTS --------------------------------- *
|
describe('smartcli.Smartcli class', function () {
|
||||||
* ------------------------------------------------------------------ */
|
let smartCliTestObject;
|
||||||
describe("smartcli", function () {
|
describe('new Smartcli()', function () {
|
||||||
describe(".check", function () {
|
it('should create a new Smartcli', function () {
|
||||||
describe(".command", function () {
|
smartCliTestObject = new smartcli.Smartcli();
|
||||||
it("should return true when specified command is found", function () {
|
should(smartCliTestObject).be.instanceof(smartcli.Smartcli);
|
||||||
smartcli.check.command("jazz").should.be.true();
|
});
|
||||||
});
|
});
|
||||||
it("should return false when specified command is NOT found", function () {
|
describe('.addCommand', function () {
|
||||||
smartcli.check.command("rock").should.be.false();
|
it('should add an command', function () {
|
||||||
|
smartCliTestObject.addCommand({
|
||||||
|
commandName: 'awesome'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe(".commandPresence", function () {
|
});
|
||||||
|
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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var checkCommandArgumentTest = function () {
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQiwwQ0FBMEM7QUFDMUMsaUNBQWdDO0FBRWhDLFFBQVEsQ0FBQyx5QkFBeUIsRUFBQztJQUMvQixJQUFJLGtCQUFxQyxDQUFBO0lBQ3pDLFFBQVEsQ0FBQyxnQkFBZ0IsRUFBQztRQUN0QixFQUFFLENBQUMsOEJBQThCLEVBQUM7WUFDOUIsa0JBQWtCLEdBQUcsSUFBSSxRQUFRLENBQUMsUUFBUSxFQUFFLENBQUE7WUFDNUMsTUFBTSxDQUFDLGtCQUFrQixDQUFDLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxRQUFRLENBQUMsUUFBUSxDQUFDLENBQUE7UUFDL0QsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtJQUNGLFFBQVEsQ0FBQyxhQUFhLEVBQUM7UUFDbkIsRUFBRSxDQUFDLHVCQUF1QixFQUFDO1lBQ3ZCLGtCQUFrQixDQUFDLFVBQVUsQ0FBQztnQkFDMUIsV0FBVyxFQUFFLFNBQVM7YUFDekIsQ0FBQyxDQUFBO1FBQ04sQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtJQUNGLFFBQVEsQ0FBQyxlQUFlLEVBQUM7UUFDckIsRUFBRSxDQUFDLHFDQUFxQyxFQUFDLFVBQVMsSUFBSTtZQUNsRCxrQkFBa0IsQ0FBQyxZQUFZLEVBQUU7aUJBQzVCLElBQUksQ0FBQztnQkFDRixPQUFPLENBQUMsR0FBRyxDQUFDLDRCQUE0QixDQUFDLENBQUE7WUFDN0MsQ0FBQyxDQUFDLENBQUE7WUFDTixJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7SUFDRixRQUFRLENBQUMsYUFBYSxFQUFDO1FBQ25CLEVBQUUsQ0FBQyxvQ0FBb0MsRUFBQztZQUNwQyxrQkFBa0IsQ0FBQyxVQUFVLEVBQUUsQ0FBQTtRQUNuQyxDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
||||||
if (smartcli.check.commandArgument("jam", 1)) {
|
|
||||||
beautylog.success('There is a level 1 argument! Perfect!');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error('There seems to be no level 1 argument... This is wrong');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
if (!smartcli.check.commandArgument("session", 2)) {
|
|
||||||
beautylog.success('There is no level 2 argument with the name of "session"! Perfect!');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error('There seems to be a level 2 argument with the name of "session"! This is wrong');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
checkCommandArgumentTest();
|
|
||||||
var checkCommandArgumentPresenceTest = function () {
|
|
||||||
if (smartcli.check.commandArgumentPresence(1)) {
|
|
||||||
beautylog.success('There is a level 1 argument! Perfect!');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error('There seems to be no level 1 argument... This is wrong');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
if (!smartcli.check.commandArgumentPresence(2)) {
|
|
||||||
beautylog.success('There is no level 2 argument! Perfect!');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error('There seems to be a level 2 argument... This is wrong');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
checkCommandArgumentPresenceTest();
|
|
||||||
/* ------------------------------------------------------------------ *
|
|
||||||
* ------------------- GETTERS TESTS -------------------------------- *
|
|
||||||
* ------------------------------------------------------------------ */
|
|
||||||
var getCommandTest = function () {
|
|
||||||
var cliCommand = smartcli.get.command();
|
|
||||||
if (cliCommand.name == "jazz") {
|
|
||||||
beautylog.success('The specified command name is "jazz". Perfect!');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error('The specified command name is not "jazz". Something is wrong!');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
getCommandTest();
|
|
||||||
var getCommandArgumentTest = function () {
|
|
||||||
var cliArgument = smartcli.get.commandArgument(1);
|
|
||||||
var cliArgument2 = smartcli.get.commandArgument(2);
|
|
||||||
if (cliArgument.name == "jam") {
|
|
||||||
beautylog.success('The first specified command argument name is "jam". Perfect!');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error('The first specified command argument name is not "jam". Something is wrong!');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
if (cliArgument2.name == "undefined") {
|
|
||||||
beautylog.success('The second specified command argument name is "undefined". Perfect!');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error('The second specified command argument name is not "undefined". Something is wrong!');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
getCommandArgumentTest();
|
|
||||||
var getCommandArgsTest = function () {
|
|
||||||
var commandArgs = smartcli.get.commandArgs();
|
|
||||||
if (commandArgs[0].name == "jam") {
|
|
||||||
beautylog.success("first command argument is 'jam'. Perfect!");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error("first command argument is not 'jam'. Something is wromg!");
|
|
||||||
console.log(commandArgs[0].name);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
getCommandArgsTest();
|
|
||||||
var getOptionTest = function () {
|
|
||||||
var cliOption = smartcli.get.option("awesome");
|
|
||||||
var cliOption2 = smartcli.get.option("terrific");
|
|
||||||
if (cliOption.specified) {
|
|
||||||
beautylog.success("awesome is specified. Perfect!");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error("awesome is not specified. Somehthing is wrong");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
if (!cliOption2.specified) {
|
|
||||||
beautylog.success("terrific is not specified. Perfect!");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.error("terrific is specified. Somehthing is wrong");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
getOptionTest();
|
|
||||||
var getCwdTest = function () {
|
|
||||||
beautylog.info('The current directory is: ' + smartcli.get.cwd().path);
|
|
||||||
};
|
|
||||||
getCwdTest();
|
|
||||||
/* ------------------------------------------------------------------ *
|
|
||||||
* ------------------- INTERACTION TESTS ---------------------------- *
|
|
||||||
* ------------------------------------------------------------------ */
|
|
||||||
var interactionGetAnswerTest = function () {
|
|
||||||
smartcli.interaction.getAnswer('How do you feel?', function (answer) {
|
|
||||||
console.log('The answer is: ' + answer);
|
|
||||||
interactionGetChoiceTest();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var interactionGetChoiceTest = function () {
|
|
||||||
smartcli.interaction.getChoice('What music do you like to hear?', ['Jazz', 'Blues', 'Classical'], function (answer) {
|
|
||||||
console.log('The answer is: ' + answer);
|
|
||||||
endTests();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var endTests = function () {
|
|
||||||
beautylog.ok("No more tests!");
|
|
||||||
beautylog.success("Tests completed successfully!");
|
|
||||||
};
|
|
||||||
if (!smartcli.check.option("silent")) {
|
|
||||||
interactionGetAnswerTest();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
beautylog.info("--silent option is specified, thus we are not running interaction tests.");
|
|
||||||
endTests();
|
|
||||||
}
|
|
||||||
;
|
|
||||||
//# sourceMappingURL=test.js.map
|
|
195
test/test.ts
195
test/test.ts
@ -1,164 +1,35 @@
|
|||||||
/// <reference path="../ts/typings/main.d.ts" />
|
import 'typings-test'
|
||||||
let smartcli = require("../dist/index.js");
|
|
||||||
let should = req
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ *
|
|
||||||
* ------------------- CHECKS TESTS --------------------------------- *
|
|
||||||
* ------------------------------------------------------------------ */
|
|
||||||
|
|
||||||
describe("smartcli",function(){
|
|
||||||
describe(".check",function(){
|
|
||||||
describe(".command",function(){
|
|
||||||
it("should return true when specified command is found",function(){
|
|
||||||
smartcli.check.command("jazz").should.be.true();
|
|
||||||
});
|
|
||||||
it("should return false when specified command is NOT found",function(){
|
|
||||||
smartcli.check.command("rock").should.be.false();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe(".commandPresence",function(){
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var checkCommandArgumentTest = function() {
|
|
||||||
if (smartcli.check.commandArgument("jam",1)) {
|
|
||||||
beautylog.success('There is a level 1 argument! Perfect!');
|
|
||||||
} else {
|
|
||||||
beautylog.error('There seems to be no level 1 argument... This is wrong');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
if (!smartcli.check.commandArgument("session",2)) {
|
|
||||||
beautylog.success('There is no level 2 argument with the name of "session"! Perfect!');
|
|
||||||
} else {
|
|
||||||
beautylog.error('There seems to be a level 2 argument with the name of "session"! This is wrong');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
checkCommandArgumentTest();
|
|
||||||
|
|
||||||
var checkCommandArgumentPresenceTest = function() {
|
|
||||||
if (smartcli.check.commandArgumentPresence(1)) {
|
|
||||||
beautylog.success('There is a level 1 argument! Perfect!');
|
|
||||||
} else {
|
|
||||||
beautylog.error('There seems to be no level 1 argument... This is wrong');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
if (!smartcli.check.commandArgumentPresence(2)) {
|
|
||||||
beautylog.success('There is no level 2 argument! Perfect!');
|
|
||||||
} else {
|
|
||||||
beautylog.error('There seems to be a level 2 argument... This is wrong');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
checkCommandArgumentPresenceTest();
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ *
|
|
||||||
* ------------------- GETTERS TESTS -------------------------------- *
|
|
||||||
* ------------------------------------------------------------------ */
|
|
||||||
var getCommandTest = function(){
|
|
||||||
var cliCommand = smartcli.get.command();
|
|
||||||
if(cliCommand.name == "jazz") {
|
|
||||||
beautylog.success('The specified command name is "jazz". Perfect!');
|
|
||||||
} else {
|
|
||||||
beautylog.error('The specified command name is not "jazz". Something is wrong!');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
getCommandTest();
|
|
||||||
|
|
||||||
var getCommandArgumentTest = function() {
|
|
||||||
var cliArgument = smartcli.get.commandArgument(1);
|
|
||||||
var cliArgument2 = smartcli.get.commandArgument(2);
|
|
||||||
if(cliArgument.name == "jam") {
|
|
||||||
beautylog.success('The first specified command argument name is "jam". Perfect!');
|
|
||||||
} else {
|
|
||||||
beautylog.error('The first specified command argument name is not "jam". Something is wrong!');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cliArgument2.name == "undefined") {
|
|
||||||
beautylog.success('The second specified command argument name is "undefined". Perfect!');
|
|
||||||
} else {
|
|
||||||
beautylog.error('The second specified command argument name is not "undefined". Something is wrong!');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
getCommandArgumentTest();
|
|
||||||
|
|
||||||
var getCommandArgsTest = function() {
|
|
||||||
var commandArgs = smartcli.get.commandArgs();
|
|
||||||
if(commandArgs[0].name == "jam") {
|
|
||||||
beautylog.success("first command argument is 'jam'. Perfect!");
|
|
||||||
} else {
|
|
||||||
beautylog.error("first command argument is not 'jam'. Something is wromg!");
|
|
||||||
console.log(commandArgs[0].name);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
getCommandArgsTest();
|
|
||||||
|
|
||||||
var getOptionTest = function() {
|
|
||||||
var cliOption = smartcli.get.option("awesome");
|
|
||||||
var cliOption2 = smartcli.get.option("terrific");
|
|
||||||
if(cliOption.specified){
|
|
||||||
beautylog.success("awesome is specified. Perfect!")
|
|
||||||
} else {
|
|
||||||
beautylog.error("awesome is not specified. Somehthing is wrong");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
if(!cliOption2.specified){
|
|
||||||
beautylog.success("terrific is not specified. Perfect!")
|
|
||||||
} else {
|
|
||||||
beautylog.error("terrific is specified. Somehthing is wrong");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
getOptionTest();
|
|
||||||
|
|
||||||
var getCwdTest = function(){
|
|
||||||
beautylog.info('The current directory is: ' + smartcli.get.cwd().path);
|
|
||||||
};
|
|
||||||
getCwdTest();
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ *
|
|
||||||
* ------------------- INTERACTION TESTS ---------------------------- *
|
|
||||||
* ------------------------------------------------------------------ */
|
|
||||||
|
|
||||||
|
|
||||||
var interactionGetAnswerTest = function() {
|
|
||||||
smartcli.interaction.getAnswer('How do you feel?',function(answer){
|
|
||||||
console.log('The answer is: ' + answer);
|
|
||||||
interactionGetChoiceTest();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var interactionGetChoiceTest = function() {
|
|
||||||
smartcli.interaction.getChoice('What music do you like to hear?',['Jazz','Blues','Classical'],function(answer){
|
|
||||||
console.log('The answer is: ' + answer);
|
|
||||||
endTests();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var endTests = function() {
|
|
||||||
beautylog.ok("No more tests!");
|
|
||||||
beautylog.success("Tests completed successfully!");
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!smartcli.check.option("silent")){
|
|
||||||
interactionGetAnswerTest();
|
|
||||||
} else {
|
|
||||||
beautylog.info("--silent option is specified, thus we are not running interaction tests.");
|
|
||||||
endTests();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
import smartcli = require('../dist/index')
|
||||||
|
import * as should from '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()
|
||||||
|
should(smartCliTestObject).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()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
30
ts/index.ts
30
ts/index.ts
@ -1,29 +1 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
export { Smartcli } from './smartcli.classes.smartcli'
|
||||||
/// <reference path="./smartcli.interfaces.ts" />
|
|
||||||
|
|
||||||
import plugins = require("./smartcli.plugins");
|
|
||||||
import SmartcliChecks = require("./smartcli.checks");
|
|
||||||
import SmartcliGetters = require("./smartcli.getters");
|
|
||||||
import SmartcliInteractions = require("./smartcli.interaction");
|
|
||||||
|
|
||||||
/* ------------------------------------------------ *
|
|
||||||
* ---------- plugins for direct use -------------- *
|
|
||||||
* ------------------------------------------------ */
|
|
||||||
export let inquirer = plugins.inquirer; //inquirer is for asking questions
|
|
||||||
export let cliff = plugins.cliff; // formats cli output
|
|
||||||
export let argv = plugins.argv; //argv gets initial cli commands and options.
|
|
||||||
|
|
||||||
/* ------------------------------------------------ *
|
|
||||||
* ---------- checks ------------------------------ *
|
|
||||||
* ------------------------------------------------ */
|
|
||||||
export let check = SmartcliChecks;
|
|
||||||
|
|
||||||
/* ------------------------------------------------ *
|
|
||||||
* ---------- getters ----------------------------- *
|
|
||||||
* ------------------------------------------------ */
|
|
||||||
export let get = SmartcliGetters;
|
|
||||||
|
|
||||||
/* ------------------------------------------------ *
|
|
||||||
* ---------- interaction ----------------------------- *
|
|
||||||
* ------------------------------------------------ */
|
|
||||||
export let interaction = SmartcliInteractions;
|
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
/// <reference path="./smartcli.interfaces.ts" />
|
|
||||||
|
|
||||||
import plugins = require("./smartcli.plugins");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* checks for a special command string and returns true if found.
|
|
||||||
* @param commandString
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
export let command = function(commandString:string):boolean {
|
|
||||||
if (plugins.argv._.indexOf(commandString) == 0) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* checks if a command is present, returns true if yes, false if no.
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
export let commandPresence = function():boolean {
|
|
||||||
if(plugins.argv._.length > 0){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* checks for an special command argument at a certain position, returns true if matches, returns false if not
|
|
||||||
* @param level
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
export let commandArgument = function(commandArgumentString:string,level:number = 1):boolean {
|
|
||||||
if(commandArgumentPresence(level) && (plugins.argv._[level] == commandArgumentString )) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
export let commandArgumentPresence = function(level:number = 1) {
|
|
||||||
if(plugins.argv._.length >= (level + 1)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* checks for a specific option string, returns true if yes, returns false if no
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
export let option = function(optionString):boolean {
|
|
||||||
if(plugins.smartparam.exists(plugins.argv, optionString)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
export let optionPresence = function():boolean {
|
|
||||||
if (plugins.argv.indexOf() != -1) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
116
ts/smartcli.classes.smartcli.ts
Normal file
116
ts/smartcli.classes.smartcli.ts
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
import * as q from 'q'
|
||||||
|
|
||||||
|
import * as plugins from './smartcli.plugins'
|
||||||
|
|
||||||
|
// import classes
|
||||||
|
import {Objectmap} from 'lik'
|
||||||
|
|
||||||
|
// interfaces
|
||||||
|
export interface ICommandPromiseObject {
|
||||||
|
commandName: string
|
||||||
|
promise: q.Promise<any>
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Smartcli {
|
||||||
|
argv: any
|
||||||
|
questionsDone
|
||||||
|
parseStarted
|
||||||
|
commands
|
||||||
|
questions
|
||||||
|
version: string
|
||||||
|
|
||||||
|
// maps
|
||||||
|
allCommandPromises = new Objectmap<ICommandPromiseObject>()
|
||||||
|
constructor() {
|
||||||
|
this.argv = plugins.yargs
|
||||||
|
this.questionsDone = q.defer()
|
||||||
|
this.parseStarted = q.defer()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* adds an alias, meaning one equals the other in terms of triggering associated commands
|
||||||
|
*/
|
||||||
|
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}): q.Promise<any> {
|
||||||
|
let done = 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(): q.Promise<any> {
|
||||||
|
let done = 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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,110 +0,0 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
/// <reference path="./smartcli.interfaces.ts" />
|
|
||||||
|
|
||||||
import plugins = require("./smartcli.plugins");
|
|
||||||
import SmartcliChecks = require("./smartcli.checks");
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param commandString
|
|
||||||
* @returns {{specified: boolean, name: any, arguments: CliCommandArgument}}
|
|
||||||
*/
|
|
||||||
export let command = function():CliCommand {
|
|
||||||
var cliCommand = {
|
|
||||||
specified: SmartcliChecks.commandPresence(),
|
|
||||||
name: plugins.argv._[0],
|
|
||||||
arguments: commandArgs()
|
|
||||||
}
|
|
||||||
return cliCommand;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets the second or higher value of plugins.argv._ if specified and returns it as commandArgument
|
|
||||||
* @param argumentLevel
|
|
||||||
* @returns {{specified: (boolean|boolean), name}}
|
|
||||||
*/
|
|
||||||
export let commandArgument = function(argumentLevel):CliCommandArgument {
|
|
||||||
var commandArgument:CliCommandArgument = {
|
|
||||||
specified: false,
|
|
||||||
name: "undefined",
|
|
||||||
level:argumentLevel
|
|
||||||
};
|
|
||||||
if(argumentLevel < 1) {
|
|
||||||
plugins.beautylog.error("smartcli.get.argument cannot be invoked with an argumentLevel smaller than 1");
|
|
||||||
return commandArgument;
|
|
||||||
}
|
|
||||||
if(SmartcliChecks.commandArgumentPresence(argumentLevel)) {
|
|
||||||
commandArgument.specified = true;
|
|
||||||
commandArgument.name = plugins.argv._[argumentLevel];
|
|
||||||
}
|
|
||||||
return commandArgument;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns array with commandArgs
|
|
||||||
* @returns {CliCommandArgument[]}
|
|
||||||
*/
|
|
||||||
export let commandArgs = function():CliCommandArgument[] {
|
|
||||||
var commandArgs:CliCommandArgument[] = [];
|
|
||||||
var argsArray = commandArray().slice(0);
|
|
||||||
argsArray.shift();
|
|
||||||
for (var item in argsArray){
|
|
||||||
var commandArgument:CliCommandArgument = {
|
|
||||||
specified:true,
|
|
||||||
name:argsArray[item],
|
|
||||||
level: item + 1
|
|
||||||
}
|
|
||||||
commandArgs.push(commandArgument);
|
|
||||||
}
|
|
||||||
return commandArgs;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns complete command array
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
export let commandArray = function ():string[] {
|
|
||||||
var commandArray = plugins.argv._;
|
|
||||||
return commandArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns a cli option
|
|
||||||
* @param optionName
|
|
||||||
* @returns {CliOption}
|
|
||||||
*/
|
|
||||||
export let option = function(optionName:string):CliOption {
|
|
||||||
var cliOption:CliOption = {
|
|
||||||
name:optionName,
|
|
||||||
specified: false,
|
|
||||||
value: false
|
|
||||||
};
|
|
||||||
if (plugins.smartparam.exists(plugins.argv,optionName)) {
|
|
||||||
cliOption.name = optionName;
|
|
||||||
cliOption.specified = true;
|
|
||||||
cliOption.value = plugins.argv[optionName] //we already know from the "if" above that the value is available.
|
|
||||||
}
|
|
||||||
return cliOption;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
export let options = function() {
|
|
||||||
var options = {};
|
|
||||||
for (var key in plugins.argv) {
|
|
||||||
if (key != "_") {
|
|
||||||
options['key'] = plugins.argv['key'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return options;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns Directory of cwd
|
|
||||||
* @returns {{path: string}}
|
|
||||||
*/
|
|
||||||
export let cwd = function():Directory {
|
|
||||||
return {
|
|
||||||
path: process.cwd()
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,59 +0,0 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
/// <reference path="./smartcli.interfaces.ts" />
|
|
||||||
|
|
||||||
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
|
|
||||||
var question = {
|
|
||||||
type: "input",
|
|
||||||
name: "userFeedback",
|
|
||||||
message: questionString,
|
|
||||||
validate: function( value ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
plugins.inquirer.prompt([question],function(answers){
|
|
||||||
var 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
|
|
||||||
var question = {
|
|
||||||
type: "list",
|
|
||||||
name: "userFeedback",
|
|
||||||
message: questionString,
|
|
||||||
choices: choiceOptions,
|
|
||||||
filter: function( val ) { return val.toLowerCase(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
plugins.inquirer.prompt(question,function(answers){
|
|
||||||
var answer = answers.userFeedback;
|
|
||||||
cb(answer);
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
@ -1,22 +0,0 @@
|
|||||||
interface CliOption {
|
|
||||||
name: string;
|
|
||||||
specified:boolean;
|
|
||||||
value: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Directory {
|
|
||||||
path: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CliCommand {
|
|
||||||
specified: boolean;
|
|
||||||
name: string;
|
|
||||||
arguments:CliCommandArgument[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CliCommandArgument {
|
|
||||||
specified:boolean;
|
|
||||||
name:string;
|
|
||||||
level:number;
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +1,15 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
import 'typings-global';
|
||||||
|
|
||||||
export let path = require("path");
|
import * as yargs from 'yargs'
|
||||||
export let 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 let smartparam = require("smartparam");
|
import * as smartparam from 'smartparam'
|
||||||
export let argv = require('yargs').argv;
|
|
||||||
|
export {
|
||||||
|
yargs,
|
||||||
|
beautylog,
|
||||||
|
lik,
|
||||||
|
path,
|
||||||
|
smartparam
|
||||||
|
}
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"ambientDependencies": {
|
|
||||||
"mocha": "registry:dt/mocha#2.2.5+20151023103246",
|
|
||||||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts"
|
|
||||||
}
|
|
||||||
}
|
|
2
ts/typings/browser.d.ts
vendored
2
ts/typings/browser.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
/// <reference path="browser/ambient/mocha/index.d.ts" />
|
|
||||||
/// <reference path="browser/ambient/node/index.d.ts" />
|
|
2
ts/typings/main.d.ts
vendored
2
ts/typings/main.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
/// <reference path="main/ambient/mocha/index.d.ts" />
|
|
||||||
/// <reference path="main/ambient/node/index.d.ts" />
|
|
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