Compare commits

...

86 Commits

Author SHA1 Message Date
adfda70522 3.0.2 2018-06-28 23:57:41 +02:00
c701e3e04c fix(core): slim down dependencies 2018-06-28 23:57:40 +02:00
7b1de5b31d 3.0.1 2018-05-04 00:19:45 +02:00
7908fd8cfd update 2018-05-04 00:19:41 +02:00
21bd0c9279 3.0.0 2018-05-03 12:10:48 +02:00
9d1108e40d change to an all rxjs Subject architecture 2018-05-03 12:10:39 +02:00
390e0cb491 system change 2018-03-03 13:57:54 +01:00
032fd0c2fd fix(core): cleanup 2018-01-27 18:06:13 +01:00
440881c3d8 remove package-lock since using yarn 2018-01-27 18:05:06 +01:00
f208121e2c 2.0.12 2018-01-27 18:02:05 +01:00
7c4ae84871 fix(improve security CI step): 2018-01-27 18:02:01 +01:00
668f6c3e16 2.0.11 2018-01-27 17:59:08 +01:00
b1e08aad1f fix(core): remove vulnerable paths 2018-01-27 17:59:04 +01:00
f1ab614cdf update ci 2018-01-27 02:27:55 +01:00
995c808512 update ci 2018-01-27 02:26:10 +01:00
28acb867a0 update ci 2018-01-27 02:23:24 +01:00
3148a50d43 update ci 2018-01-27 02:21:53 +01:00
41c99de4d8 2.0.10 2018-01-27 02:20:46 +01:00
a91f56dacf add security step to CI 2018-01-27 02:20:41 +01:00
f60f17f91e 2.0.9 2017-10-12 23:02:03 +02:00
d154cf0d0f ensure compatibility with code assertion library 2017-10-12 23:02:00 +02:00
a6e0fa65e0 2.0.8 2017-10-12 22:44:39 +02:00
c7e940f597 fix tests and add .triggerOnlyOnProcessEnvCliCall() 2017-10-12 22:44:34 +02:00
45d3ce8ffc fix linting issues 2017-10-12 20:38:34 +02:00
ce121b8b7f 2.0.7 2017-05-07 16:01:14 +02:00
ce65b8d7c9 fix promise rejection on standard task 2017-05-07 16:01:10 +02:00
9acdfca460 2.0.6 2017-04-23 15:21:11 +02:00
59bcd8dadf use new tapbundle 2017-04-23 15:21:08 +02:00
b6375fd8fa 2.0.5 2017-04-22 23:16:52 +02:00
8183417c90 comment out one test that makes problems due to tap 2017-04-22 23:16:49 +02:00
5e66d35125 update tests 2017-04-22 22:09:51 +02:00
3ff4c3ff2f 2.0.4 2017-04-22 21:08:07 +02:00
6508b29bfc add npmextra.json 2017-04-22 21:08:01 +02:00
66fd7138ab 2.0.3 2017-04-22 21:05:02 +02:00
f3ce1c1408 update ci 2017-04-22 21:04:59 +02:00
d2b84acc55 2.0.2 2017-04-22 21:04:15 +02:00
ce008da9ad update .gitignore 2017-04-22 21:04:11 +02:00
f0f1f9b86f update to latest standards 2017-04-22 21:03:28 +02:00
089787454a 2.0.1 2016-12-18 20:58:39 +01:00
f8a122b777 fix argvArg for observables 2016-12-18 20:58:37 +01:00
c6db092062 2.0.0 2016-12-18 20:53:53 +01:00
857d31dcb2 introduce triggers 2016-12-18 20:53:50 +01:00
e257a38688 1.0.16 2016-12-18 01:36:24 +01:00
19a5082381 added .triggerCommandByName 2016-12-18 01:36:19 +01:00
00f5539e6b improve README 2016-11-19 17:48:56 +01:00
cacb0221f1 IMprove README 2016-11-19 17:48:07 +01:00
b98b90163d 1.0.15 2016-11-19 17:41:16 +01:00
daa6312aea Update Metadata 2016-11-19 17:41:11 +01:00
7f2dab091f 1.0.14 2016-11-19 15:02:29 +01:00
dd293875c4 improve README 2016-11-19 15:02:24 +01:00
120eca42ac 1.0.13 2016-11-19 13:43:33 +01:00
fc289616f6 1.0.12 2016-11-19 13:43:10 +01:00
e7c1c1c45b cleanup 2016-11-19 13:43:06 +01:00
f33c759fa8 improve README 2016-10-15 02:12:10 +02:00
1185df362b update test file 2016-10-15 01:06:36 +02:00
36de8e11f0 1.0.11 2016-10-15 01:01:25 +02:00
74ffb3aa87 update deps 2016-10-15 01:01:22 +02:00
96a6d01720 1.0.10 2016-10-15 00:56:05 +02:00
7833bd0be8 implement standardJS 2016-10-15 00:56:02 +02:00
7ca18c4a46 1.0.9 2016-09-04 17:50:36 +02:00
b98e2a1a62 improve typings 2016-09-04 17:50:10 +02:00
e102203422 1.0.8 2016-09-04 17:36:19 +02:00
92a37cf29b fix ci 2016-09-04 17:36:07 +02:00
8408d1f3b5 1.0.7 2016-09-04 17:34:34 +02:00
d88e05466b fix base image 2016-09-04 17:34:29 +02:00
3a789d052c 1.0.6 2016-09-04 17:32:31 +02:00
d76d829e46 add page stage 2016-09-04 17:32:26 +02:00
f8157ab8aa improve typings and docs 2016-09-04 17:32:12 +02:00
5c67015779 update smartcli 2016-09-04 17:23:29 +02:00
b67e3c0de1 Add new file 2016-08-28 23:00:00 +00:00
c7a647d4ef start interaction module 2016-08-26 11:52:09 +02:00
9e5fb7a13a 1.0.5 2016-08-26 09:21:53 +02:00
c115d222c0 improve intellisense 2016-08-26 09:21:42 +02:00
643514c64a 1.0.4 2016-06-22 11:55:26 +02:00
19498f7b11 compile fix 2016-06-22 11:55:23 +02:00
3afadd9045 1.0.3 2016-06-22 11:54:19 +02:00
0889423a24 fix 2016-06-22 11:54:12 +02:00
86b4cf4cc3 add getCommandPromise 2016-06-22 01:21:09 +02:00
4cb4eabef4 update deps and transition from npmts to npmts-g 2016-06-22 01:18:04 +02:00
bad0971f1c 1.0.2 2016-06-16 02:58:49 +02:00
016f03bd8a standard tasks now returns argv 2016-06-16 02:58:45 +02:00
63a9da11be some cosmetics 2016-06-13 12:57:24 +02:00
ab18c75b28 introduce new classes 2016-06-13 12:56:42 +02:00
088d4ef11b 1.0.1 2016-06-10 04:32:14 +02:00
5ee866d9c6 fix version return 2016-06-10 04:32:11 +02:00
d65061aaaa return argv to command 2016-06-10 04:21:03 +02:00
25 changed files with 1699 additions and 451 deletions

11
.gitignore vendored
View File

@ -1,11 +1,4 @@
node_modules/
.settings/
.idea/
coverage/
docs/
ts/*.js
ts/*.js.map
ts/typings/
public/
.yarn/

View File

@ -1,37 +1,141 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- security
- test
- release
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- docker
- notpriv
snyk:
stage: security
script:
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLEGACY:
stage: test
script:
- npmci test legacy
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- docker
- notpriv
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- docker
- notpriv
testSTABLE:
stage: test
script:
- npmci test stable
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- docker
- notpriv
release:
stage: release
script:
- npmci publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g npmpage
- npmci command npmpage
tags:
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

View File

@ -1,54 +1,29 @@
# smartcli
nodejs wrapper for CLI related tasks. TypeScript ready.
## Status
[![Build Status](https://travis-ci.org/pushrocks/smartcli.svg?branch=master)](https://travis-ci.org/pushrocks/smartcli)
nodejs wrapper for CLI related tasks
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartcli)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartcli)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartcli)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartcli/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartcli/badges/master/build.svg)](https://GitLab.com/pushrocks/smartcli/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartcli/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartcli/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartcli.svg)](https://www.npmjs.com/package/smartcli)
[![Dependency Status](https://david-dm.org/pushrocks/smartcli.svg)](https://david-dm.org/pushrocks/smartcli)
[![bitHound Overall Score](https://www.bithound.io/github/pushrocks/smartcli/badges/score.svg)](https://www.bithound.io/github/pushrocks/smartcli)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartcli/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartcli/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartcli/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartcli)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Install the package
npm install smartcli --save
For further information read the linked docs at the top of this README.
## Usage
this plugin tries to establish some logic in which CLI tools work.
take the following commandline input:
```
mytool function argument1 argument2 --option1 option1Value --option2 option2Value
```
* 'mytool' obviously is the tool (like git)
* function is the main thing the tool shall do (like commit)
* option is an option you can add (like -m for message)
* optionValue is the referenced option value (like a commit message)
### The inner organization of smartcli
**smartcli** exposes three major groups of functions:
* check functions
* are grouped in **smartcli.checks** object
* get functions
* are grouped in **smartcli.get** object
* async interaction functions
* are grouped in **smartcli.interaction** object
### Methods
The examples are written in TypeScript
```typescript
import * as smartcli from "smartcli"
/* -------------- Check Functions -------------------*/
smartcli.check.command("jazz"); // check for a special command.
smartcli.check.commandPresence() // check if any command is specified
smartcli.check.commandArguemnt("myargument",1) // checks if a special argument is given, second argument is level
smartcli.check.commandArguemntPresence // checks of any Argument is present
smartcli.check.option("someoption") // checks for a specific option
smartcli.check.optionPresence() // checks if any option is specified
smartcli.get.option('myoption'); //
```
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://)

3
dist/index.d.ts vendored
View File

@ -1,2 +1 @@
import "typings-global";
export { Smartcli } from "./smartcli.classes.smartcli";
export { Smartcli } from './smartcli.classes.smartcli';

5
dist/index.js vendored
View File

@ -1,6 +1,5 @@
"use strict";
require("typings-global");
Object.defineProperty(exports, "__esModule", { value: true });
var smartcli_classes_smartcli_1 = require("./smartcli.classes.smartcli");
exports.Smartcli = smartcli_classes_smartcli_1.Smartcli;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFHeEIsMENBQXVCLDZCQUE2QixDQUFDO0FBQTdDLHdEQUE2QyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5cbmltcG9ydCB7U21hcnRjbGl9IGZyb20gXCIuL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGlcIjtcbmV4cG9ydCB7U21hcnRjbGl9IGZyb20gXCIuL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGlcIjtcbiJdfQ==
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHlFQUF1RDtBQUE5QywrQ0FBQSxRQUFRLENBQUEifQ==

View File

@ -1,21 +1,72 @@
import "typings-global";
import * as smartq from 'smartq';
import { Subject } from 'rxjs';
import * as plugins from './smartcli.plugins';
export interface ICommandPromiseObject {
commandName: string;
promise: Promise<void>;
}
export interface ITriggerObservableObject {
triggerName: string;
subject: Subject<any>;
}
/**
* class to create a new instance of Smartcli. Handles parsing of command line arguments.
*/
export declare class Smartcli {
argv: any;
questionsDone: any;
parseStarted: any;
parseStarted: smartq.Deferred<any>;
commands: any;
questions: any;
version: string;
private onlyOnProcessEnvCliCall;
/**
* map of all Trigger/Observable objects to keep track
*/
allTriggerObservablesMap: plugins.lik.Objectmap<ITriggerObservableObject>;
/**
* The constructor of Smartcli
*/
constructor();
addAlias(keyArg: any, aliasArg: any): void;
addCommand(definitionArg: {
commandName: string;
}): any;
addQuestion(definitionArg: {
questionString: string;
questionType: string;
/**
* halts any execution of commands if (process.env.CLI_CALL === false)
*/
onlyTriggerOnProcessEnvCliCall(): void;
/**
* adds an alias, meaning one equals the other in terms of command execution.
*/
addCommandAlias(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(commandNameArg: string): Subject<any>;
/**
* adds a Trigger. Like addCommand(), but returns an subscribable observable
*/
addTrigger(triggerNameArg: string): Subject<any>;
/**
* execute trigger by name
* @param commandNameArg - the name of the command to trigger
*/
trigger(triggerName: string): Subject<any>;
getTriggerSubject(triggerName: string): Subject<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;
standardTask(): any;
/**
* adds a trigger that is called when no command is specified
*/
standardTask(): Subject<any>;
/**
* start the process of evaluating commands
*/
startParse(): void;
}

File diff suppressed because one or more lines are too long

View File

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

View File

@ -1,55 +0,0 @@
"use strict";
require("typings-global");
require("./smartcli.interfaces");
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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmludGVyYWN0aW9uLnRzIl0sIm5h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KSB7XG4gICAgICAgIHJldHVybiBudWxsO1xuICAgIH1cblxuICAgIC8vbWFrZSBpbnF1aXJlciBjb21wYXRpYmxlIHF1ZXN0aW9uIG9iamVjdFxuICAgIGxldCBxdWVzdGlvbiA9IHtcbiAgICAgICAgdHlwZTogXCJsaXN0XCIsXG4gICAgICAgIG5hbWU6IFwidXNlckZlZWRiYWNrXCIsXG4gICAgICAgIG1lc3NhZ2U6IHF1ZXN0aW9uU3RyaW5nLFxuICAgICAgICBjaG9pY2VzOiBjaG9pY2VPcHRpb25zLFxuICAgICAgICBmaWx0ZXI6IGZ1bmN0aW9uKCB2YWwgKSB7IHJldHVybiB2YWwudG9Mb3dlckNhc2UoKTsgfVxuICAgIH07XG5cbiAgICBwbHVnaW5zLmlucXVpcmVyLnByb21wdChxdWVzdGlvbixmdW5jdGlvbihhbnN3ZXJzKXtcbiAgICAgICAgbGV0IGFuc3dlciA9IGFuc3dlcnMudXNlckZlZWRiYWNrO1xuICAgICAgICBjYihhbnN3ZXIpO1xuICAgIH0pO1xuXG59OyJdfQ==

View File

@ -1,8 +1,6 @@
import "typings-global";
export declare let argv: any;
export declare let beautylog: any;
export declare let cliff: any;
export declare let inquirer: any;
export declare let path: any;
export declare let q: any;
export declare let smartparam: any;
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 };

View File

@ -1,11 +1,13 @@
"use strict";
require("typings-global");
exports.argv = require('yargs');
exports.beautylog = require("beautylog");
exports.cliff = require("cliff");
exports.inquirer = require("inquirer");
exports.path = require("path");
exports.q = require("q");
exports.smartparam = require("smartparam");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUViLFlBQUksR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7QUFDeEIsaUJBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFDakMsYUFBSyxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQztBQUN6QixnQkFBUSxHQUFHLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQztBQUMvQixZQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLFNBQUMsR0FBRyxPQUFPLENBQUMsR0FBRyxDQUFDLENBQUM7QUFDakIsa0JBQVUsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUMiLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5cbmV4cG9ydCBsZXQgYXJndiA9IHJlcXVpcmUoJ3lhcmdzJyk7XG5leHBvcnQgbGV0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XG5leHBvcnQgbGV0IGNsaWZmID0gcmVxdWlyZShcImNsaWZmXCIpO1xuZXhwb3J0IGxldCBpbnF1aXJlciA9IHJlcXVpcmUoXCJpbnF1aXJlclwiKTtcbmV4cG9ydCBsZXQgcGF0aCA9IHJlcXVpcmUoXCJwYXRoXCIpO1xuZXhwb3J0IGxldCBxID0gcmVxdWlyZShcInFcIik7XG5leHBvcnQgbGV0IHNtYXJ0cGFyYW0gPSByZXF1aXJlKFwic21hcnRwYXJhbVwiKTsiXX0=
Object.defineProperty(exports, "__esModule", { value: true });
const yargs = require("yargs");
exports.yargs = yargs;
const beautylog = require("beautylog");
exports.beautylog = beautylog;
const lik = require("lik");
exports.lik = lik;
const path = require("path");
exports.path = path;
const smartparam = require("smartparam");
exports.smartparam = smartparam;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwrQkFBK0I7QUFNdEIsc0JBQUs7QUFMZCx1Q0FBdUM7QUFLdkIsOEJBQVM7QUFKekIsMkJBQTJCO0FBSUEsa0JBQUc7QUFIOUIsNkJBQTZCO0FBR0csb0JBQUk7QUFGcEMseUNBQXlDO0FBRUgsZ0NBQVUifQ==

70
docs/index.md Normal file
View File

@ -0,0 +1,70 @@
# smartcli
nodejs wrapper for CLI related tasks
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartcli)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartcli)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartcli)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartcli/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartcli/badges/master/build.svg)](https://GitLab.com/pushrocks/smartcli/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartcli/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartcli/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartcli.svg)](https://www.npmjs.com/package/smartcli)
[![Dependency Status](https://david-dm.org/pushrocks/smartcli.svg)](https://david-dm.org/pushrocks/smartcli)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartcli/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartcli/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartcli/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartcli)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
this plugin tries to establish some logic in which CLI tools work.
take the following commandline input:
```
mytool command argument1 argument2 --option1 -o2 option2Value
```
- `mytool` obviously is the tool (like git)
- `command` 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)
When there is no command and no option specified the standardTask applied.
When there is a option specified but no command, standardTask applies,
except when of the options is -v, --version or --help.
```javascript
import { Smartcli } from 'smartcli';
mySmartcli = new Smartcli();
mySmartcli.standardTask().then(argvArg => {
// do something if program is called without an command
});
mySmartcli.addCommand({ commandname: 'install' }).then(argvArg => {
// do something if program is called with command "install"
});
mySmartcli.addVersion('1.0.0'); // -v and --version options will display the specified version in the terminal
mySmartCli.addHelp({
// is triggered by help command and --help option
helpText: 'some help text to print' // the helpText to display
});
mySmartcli.startParse(); // starts the evaluation and fullfills or rejects promises.
```
For further information read the linked docs at the top of this README.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

9
npmextra.json Normal file
View File

@ -0,0 +1,9 @@
{
"npmci": {
"npmGlobalTools": [
"@gitzone/npmts",
"ts-node"
],
"npmAccesslevel": "public"
}
}

View File

@ -1,3 +0,0 @@
{
"mode":"default"
}

1038
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,44 +1,48 @@
{
"name": "smartcli",
"version": "1.0.0",
"name": "@pushrocks/smartcli",
"private": false,
"version": "3.0.2",
"description": "nodejs wrapper for CLI related tasks",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"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)",
"startdev": "(git checkout master && git pull origin master)"
"test": "(tsrun test/test.ts)",
"build": "(npmts)"
},
"repository": {
"type": "git",
"url": "https://gitlab.com/pushrocks/smartcli.git"
},
"keywords": [
"json",
"jade",
"template"
"cli",
"promise",
"task",
"push.rocks"
],
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/pushrocks/smartcli/issues"
},
"homepage": "https://gitlab.com/pushrocks/smartcli",
"dependencies": {
"beautylog": "^5.0.8",
"cliff": "^0.1.10",
"inquirer": "^1.0.3",
"q": "^1.4.1",
"smartparam": "0.0.7",
"typings-global": "^1.0.3",
"yargs": "^4.7.1"
"@types/yargs": "^11.0.0",
"beautylog": "^6.1.10",
"lik": "^2.0.5",
"rxjs": "^6.2.1",
"smartparam": "1.0.2",
"smartq": "^1.1.8",
"yargs": "^11.0.0"
},
"devDependencies": {
"npmts": "^5.2.5",
"should": "^9.0.1",
"typings-test": "^1.0.1"
"@gitzone/tsrun": "^1.0.7",
"@types/node": "^10.5.0",
"cz-conventional-changelog": "^2.1.0",
"tapbundle": "^2.0.2"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}

1
test/test.d.ts vendored
View File

@ -1 +0,0 @@
import "typings-test";

View File

@ -1,37 +0,0 @@
"use strict";
require("typings-test");
var smartcli = require("../dist/index");
var beautylog = require("beautylog");
var should = require("should");
describe("smartcli.Smartcli class", function () {
var 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(function () {
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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFFdEIsSUFBTyxRQUFRLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDM0MsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ3JDLElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUUvQixRQUFRLENBQUMseUJBQXlCLEVBQUM7SUFDL0IsSUFBSSxrQkFBb0MsQ0FBQztJQUN6QyxRQUFRLENBQUMsZ0JBQWdCLEVBQUM7UUFDdEIsRUFBRSxDQUFDLDhCQUE4QixFQUFDO1lBQzlCLGtCQUFrQixHQUFHLElBQUksUUFBUSxDQUFDLFFBQVEsRUFBRSxDQUFDO1lBQzdDLGtCQUFrQixDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxRQUFRLENBQUMsQ0FBQztRQUMvRCxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0lBQ0gsUUFBUSxDQUFDLGFBQWEsRUFBQztRQUNuQixFQUFFLENBQUMsdUJBQXVCLEVBQUM7WUFDdkIsa0JBQWtCLENBQUMsVUFBVSxDQUFDO2dCQUMxQixXQUFXLEVBQUMsU0FBUzthQUN4QixDQUFDLENBQUM7UUFFUCxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0lBQ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AAwB,EAAE,CAAC;IAC/B,CAAC,CAAC,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"}

View File

@ -1,37 +1,43 @@
import "typings-test";
import { tap, expect } from 'tapbundle';
import { Subject } from 'rxjs';
import smartcli = require("../dist/index");
let beautylog = require("beautylog");
let should = require("should");
import smartcli = require('../ts/index');
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();
})
})
let smartCliTestObject: smartcli.Smartcli;
tap.test('should create a new Smartcli', async () => {
smartCliTestObject = new smartcli.Smartcli();
expect(smartCliTestObject).to.be.instanceof(smartcli.Smartcli);
});
tap.test('should add an command', async () => {
expect(smartCliTestObject.addCommand('awesome')).to.be.instanceOf(Subject);
});
tap.test('should start parsing a standardTask', async () => {
expect(smartCliTestObject.standardTask()).to.be.instanceOf(Subject);
});
let hasExecuted: boolean = false;
tap.test('should accept a command', async () => {
smartCliTestObject.addTrigger('triggerme').subscribe(() => {
hasExecuted = true;
});
});
tap.test('should not have executed yet', async () => {
expect(hasExecuted).to.be.false;
});
tap.test('should execute when triggered', async () => {
smartCliTestObject.trigger('triggerme');
expect(hasExecuted).be.true;
});
tap.test('should start parsing the CLI input', async () => {
smartCliTestObject.startParse();
expect(smartCliTestObject.parseStarted.promise).to.be.instanceOf(Promise);
});
tap.start();

View File

@ -1,4 +1 @@
import "typings-global";
import {Smartcli} from "./smartcli.classes.smartcli";
export {Smartcli} from "./smartcli.classes.smartcli";
export { Smartcli } from './smartcli.classes.smartcli';

View File

@ -1,63 +1,165 @@
import "typings-global";
import * as smartq from 'smartq';
import { Subject } from 'rxjs';
import * as plugins from "./smartcli.plugins"
import * as SmartcliInteractions from "./smartcli.interaction";
import * as plugins from './smartcli.plugins';
// import classes
import { Objectmap } from 'lik';
// interfaces
export interface ICommandPromiseObject {
commandName: string;
promise: Promise<void>;
}
export interface ITriggerObservableObject {
triggerName: string;
subject: Subject<any>;
}
/**
* class to create a new instance of Smartcli. Handles parsing of command line arguments.
*/
export class Smartcli {
argv;
questionsDone;
parseStarted;
commands;
questions;
version:string;
constructor(){
this.argv = plugins.argv;
this.questionsDone = plugins.q.defer();
this.parseStarted = plugins.q.defer();
}
addAlias(keyArg,aliasArg){
this.argv = this.argv.alias(keyArg,aliasArg);
};
addCommand(definitionArg:{commandName:string}){
let done = plugins.q.defer();
this.parseStarted.promise
.then(() => {
if (this.argv._.indexOf(definitionArg.commandName) == 0) {
done.resolve();
} else {
return done.reject();
}
});
return done.promsise;
};
addQuestion(definitionArg:{questionString:string,questionType:string}){
};
addVersion(versionArg:string){
this.version = versionArg;
this.addAlias("v","version");
this.parseStarted.promise
.then(() => {
if(this.argv.v){
console.log(this.version);
}
})
}
standardTask(){
let done = plugins.q.defer();
this.parseStarted.promise
.then(() => {
if(this.argv._.length == 0 || !this.argv.v){
done.resolve();
} else {
done.reject();
};
});
return done.promise;
}
startParse(){
this.argv = this.argv.argv;
this.parseStarted.resolve();
}
argv: any;
questionsDone;
parseStarted: smartq.Deferred<any>;
commands;
questions;
version: string;
private onlyOnProcessEnvCliCall = false;
}
/**
* map of all Trigger/Observable objects to keep track
*/
allTriggerObservablesMap = new Objectmap<ITriggerObservableObject>();
/**
* The constructor of Smartcli
*/
constructor() {
this.argv = plugins.yargs;
this.questionsDone = smartq.defer();
this.parseStarted = smartq.defer();
}
/**
* halts any execution of commands if (process.env.CLI_CALL === false)
*/
onlyTriggerOnProcessEnvCliCall() {
this.onlyOnProcessEnvCliCall = true;
}
/**
* adds an alias, meaning one equals the other in terms of command execution.
*/
addCommandAlias(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(commandNameArg: string): Subject<any> {
let triggerSubject = this.addTrigger(commandNameArg);
this.parseStarted.promise.then(() => {
if (this.argv._.indexOf(commandNameArg) === 0) {
this.trigger(commandNameArg);
}
});
return triggerSubject;
}
/**
* adds a Trigger. Like addCommand(), but returns an subscribable observable
*/
addTrigger(triggerNameArg: string) {
let triggerSubject = new Subject<any>();
if (!this.getTriggerSubject(triggerNameArg)) {
this.allTriggerObservablesMap.add({
triggerName: triggerNameArg,
subject: triggerSubject
});
} else {
throw new Error(`you can't add a trigger twice`);
}
return triggerSubject;
}
/**
* execute trigger by name
* @param commandNameArg - the name of the command to trigger
*/
trigger(triggerName: string) {
let triggerSubject = this.getTriggerSubject(triggerName);
triggerSubject.next(this.argv);
return triggerSubject;
}
getTriggerSubject(triggerName: string) {
const triggerObservableObject = this.allTriggerObservablesMap.find(
triggerObservableObjectArg => {
return triggerObservableObjectArg.triggerName === triggerName;
}
);
if (triggerObservableObject) {
return triggerObservableObject.subject;
} else {
return null;
}
}
/**
* allows to specify help text to be printed above the rest of the help text
*/
addHelp(optionsArg: { helpText: string }) {
this.addCommand('help').subscribe(argvArg => {
plugins.beautylog.log(optionsArg.helpText);
});
}
/**
* specify version to be printed for -v --version
*/
addVersion(versionArg: string) {
this.version = versionArg;
this.addCommandAlias('v', 'version');
this.parseStarted.promise.then(() => {
if (this.argv.v) {
console.log(this.version);
}
});
}
/**
* adds a trigger that is called when no command is specified
*/
standardTask(): Subject<any> {
let standardSubject = this.addTrigger('standardTask');
this.parseStarted.promise.then(() => {
if (this.argv._.length === 0 && !this.argv.v) {
if (this.onlyOnProcessEnvCliCall) {
if (process.env.CLI_CALL === 'true') {
this.trigger('standardTask');
} else {
return;
}
} else {
this.trigger('standardTask');
}
}
});
return standardSubject;
}
/**
* start the process of evaluating commands
*/
startParse(): void {
this.argv = this.argv.argv;
this.parseStarted.resolve();
return;
}
}

View File

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

View File

@ -1,9 +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 let argv = require('yargs');
export let beautylog = require("beautylog");
export let cliff = require("cliff");
export let inquirer = require("inquirer");
export let path = require("path");
export let q = require("q");
export let smartparam = require("smartparam");
export { yargs, beautylog, lik, path, smartparam };

3
tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}