work in progress
This commit is contained in:
parent
8f72b3f2af
commit
7eed737120
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,3 +7,5 @@ docs/
|
||||
|
||||
ts/*.js
|
||||
ts/*.js.map
|
||||
ts/typings/
|
||||
|
||||
|
27
dist/index.js
vendored
Normal file
27
dist/index.js
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
/// <reference path="./smartcli.interfaces.ts" />
|
||||
"use strict";
|
||||
var plugins = require("./smartcli.plugins");
|
||||
var SmartcliChecks = require("./smartcli.checks");
|
||||
var SmartcliGetters = require("./smartcli.getters");
|
||||
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDBDQUEwQztBQUMxQyxpREFBaUQ7O0FBRWpELElBQU8sT0FBTyxXQUFXLG9CQUFvQixDQUFDLENBQUM7QUFDL0MsSUFBTyxjQUFjLFdBQVcsbUJBQW1CLENBQUMsQ0FBQztBQUNyRCxJQUFPLGVBQWUsV0FBVyxvQkFBb0IsQ0FB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VyYWN0aW9uIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICpcbiAqIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqL1xuZXhwb3J0IGxldCBpbnRlcmFjdGlvbiA9IFNtYXJ0Y2xpSW50ZXJhY3Rpb25zO1xuIl0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
|
62
dist/smartcli.checks.js
vendored
Normal file
62
dist/smartcli.checks.js
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
/// <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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNoZWNrcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSwwQ0FBMEM7QUFDMUMsaURBQWlEOztBQUVqRCxJQUFPLE9BQU8sV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBRS9DOzs7O0dBSUc7QUFDUSxlQUFPLEdBQUcsVUFBUyxhQUFvQjtJQUM5QyxFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxPQUFPLENBQUMsYUFBYSxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUM3QyxNQUFNLENBQUMsSUFBSSxDQUFBO0lBQ2YsQ0FBQztJQUNELE1BQU0sQ0FBQyxLQUFLLENBQUM7QUFDakIsQ0FBQyxDQUFDO0FBRUY7OztHQUdHO0FBQ1EsdUJBQWUsR0FBRztJQUN6QixFQUFFLENBQUEsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxNQUFNLEdBQUcsQ0FBQyxDQUFDLENBQUEsQ0FBQztRQUMxQixNQUFNLENBQUMsSUFBSSxDQUFDO0lBQ2hCLENBQUM7SUFDRCxNQUFNLENBQUMsS0FBSyxDQUFDO0FBQ2pCLENBQUMsQ0FBQztBQUVGOzs7O0dBSUc7QUFDUSx1QkFBZSxHQUFHLFVBQVMscUJBQTRCLEVBQUMsS0FBZ0I7SUFBaEIscUJBQWdCLEdBQWhCLFNBQWdCO0lBQy9FLEVBQUUsQ0FBQSxDQUFDLCtCQUF1QixDQUF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bmN0aW9uKCk6Ym9vbGVhbiB7XG4gICAgaWYgKHBsdWdpbnMuYXJndi5pbmRleE9mKCkgIT0gLTEpIHtcbiAgICAgICAgcmV0dXJuIHRydWVcbiAgICB9XG4gICAgcmV0dXJuIGZhbHNlO1xufTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
103
dist/smartcli.getters.js
vendored
Normal file
103
dist/smartcli.getters.js
vendored
Normal file
File diff suppressed because one or more lines are too long
55
dist/smartcli.interaction.js
vendored
Normal file
55
dist/smartcli.interaction.js
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
/// <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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bmV4cG9ydCBsZXQgZ2V0Q2hvaWNlID0gZnVuY3Rpb24ocXVlc3Rpb25TdHJpbmc6c3RyaW5nLCBjaG9pY2VPcHRpb25zOnN0cmluZ1tdLCBjYikge1xuICAgIGlmKCFBcnJheS5pc0FycmF5KGNob2ljZU9wdGlvbnMpKSB7XG4gICAgICAgIHJldHVybiBudWxsO1xuICAgIH1cblxuICAgIC8vbWFrZSBpbnF1aXJlciBjb21wYXRpYmxlIHF1ZXN0aW9uIG9iamVjdFxuICAgIHZhciBxdWVzdGlvbiA9IHtcbiAgICAgICAgdHlwZTogXCJsaXN0XCIsXG4gICAgICAgIG5hbWU6IFwidXNlckZlZWRiYWNrXCIsXG4gICAgICAgIG1lc3NhZ2U6IHF1ZXN0aW9uU3RyaW5nLFxuICAgICAgICBjaG9pY2VzOiBjaG9pY2VPcHRpb25zLFxuICAgICAgICBmaWx0ZXI6IGZ1bmN0aW9uKCB2YWwgKSB7IHJldHVybiB2YWwudG9Mb3dlckNhc2UoKTsgfVxuICAgIH07XG5cbiAgICBwbHVnaW5zLmlucXVpcmVyLnByb21wdChxdWVzdGlvbixmdW5jdGlvbihhbnN3ZXJzKXtcbiAgICAgICAgdmFyIGFuc3dlciA9IGFuc3dlcnMudXNlckZlZWRiYWNrO1xuICAgICAgICBjYihhbnN3ZXIpO1xuICAgIH0pO1xuXG59OyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
3
dist/smartcli.interfaces.js
vendored
Normal file
3
dist/smartcli.interfaces.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJzbWFydGNsaS5pbnRlcmZhY2VzLmpzIiwic291cmNlc0NvbnRlbnQiOltdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
10
dist/smartcli.plugins.js
vendored
Normal file
10
dist/smartcli.plugins.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
"use strict";
|
||||
exports.path = require("path");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.cliff = require("cliff");
|
||||
exports.inquirer = require("inquirer");
|
||||
exports.smartparam = require("smartparam");
|
||||
exports.argv = require('yargs').argv;
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsMENBQTBDOztBQUUvQixZQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLGlCQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLGFBQUssR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7QUFDekIsZ0JBQVEsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDLENBQUM7QUFDL0Isa0JBQVUsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUM7QUFDbkMsWUFBSSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQyxJQUFJLENBQUMiLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCJ0eXBpbmdzL21haW4uZC50c1wiIC8+XG5cbmV4cG9ydCBsZXQgcGF0aCA9IHJlcXVpcmUoXCJwYXRoXCIpO1xuZXhwb3J0IGxldCBiZWF1dHlsb2cgPSByZXF1aXJlKFwiYmVhdXR5bG9nXCIpO1xuZXhwb3J0IGxldCBjbGlmZiA9IHJlcXVpcmUoXCJjbGlmZlwiKTtcbmV4cG9ydCBsZXQgaW5xdWlyZXIgPSByZXF1aXJlKFwiaW5xdWlyZXJcIik7XG5leHBvcnQgbGV0IHNtYXJ0cGFyYW0gPSByZXF1aXJlKFwic21hcnRwYXJhbVwiKTtcbmV4cG9ydCBsZXQgYXJndiA9IHJlcXVpcmUoJ3lhcmdzJykuYXJndjsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
File diff suppressed because one or more lines are too long
48
test/test.ts
48
test/test.ts
@ -1,38 +1,26 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
var smartcli = require("../index.js");
|
||||
var beautylog = require("beautylog");
|
||||
|
||||
var commandsString:string = 'You specified the following commands:';
|
||||
var commands = smartcli.get.commandArray();
|
||||
for (var key in commands) {
|
||||
commandsString = commandsString + ' ' + commands[key];
|
||||
}
|
||||
beautylog.log(commandsString);
|
||||
|
||||
/// <reference path="../ts/typings/main.d.ts" />
|
||||
let smartcli = require("../dist/index.js");
|
||||
let should = req
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* ------------------- CHECKS TESTS --------------------------------- *
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
var checkCommandTest = function() {
|
||||
if (smartcli.check.command('jazz')) {
|
||||
beautylog.success('One of your commands is jazz. It is supposed to be there. Perfect!');
|
||||
} else {
|
||||
beautylog.error('None of your commands is jazz. You need to check this');
|
||||
process.exit(1);
|
||||
}
|
||||
if (!smartcli.check.command('punk')) {
|
||||
beautylog.success('None of your commands is punk. It is not supposed to be there. Perfect!');
|
||||
} else {
|
||||
beautylog.error('One of your commands seems to be punk. Something is wrong here');
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
checkCommandTest();
|
||||
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 checkCommandPresenceTest = function() {
|
||||
|
20
ts/index.ts
20
ts/index.ts
@ -1,10 +1,10 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
/// <reference path="./smartcli.interfaces.ts" />
|
||||
/// <reference path="./smartcli.getters.ts" />
|
||||
/// <reference path="./smartcli.interaction.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 -------------- *
|
||||
@ -14,12 +14,16 @@ export let cliff = plugins.cliff; // formats cli output
|
||||
export let argv = plugins.argv; //argv gets initial cli commands and options.
|
||||
|
||||
/* ------------------------------------------------ *
|
||||
* ---------- checks -------------- *
|
||||
* ---------- checks ------------------------------ *
|
||||
* ------------------------------------------------ */
|
||||
export let check = SmartcliChecks;
|
||||
|
||||
/* ------------------------------------------------ *
|
||||
* ---------- getters ----------------------------- *
|
||||
* ------------------------------------------------ */
|
||||
export let get = SmartcliGetters;
|
||||
|
||||
|
||||
//init checks. Checks return boolean. That means they can be used as question with an answer of yes or no.
|
||||
|
||||
SmartcliGetters.init(); // is defined in smartcli.getters.ts
|
||||
SmartcliInteraction.init(); // is defined in smartcli.interaction.ts
|
||||
/* ------------------------------------------------ *
|
||||
* ---------- interaction ----------------------------- *
|
||||
* ------------------------------------------------ */
|
||||
export let interaction = SmartcliInteractions;
|
||||
|
@ -1,4 +1,5 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
/// <reference path="./smartcli.interfaces.ts" />
|
||||
|
||||
import plugins = require("./smartcli.plugins");
|
||||
|
||||
|
@ -1,110 +1,110 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
module SmartcliGetters {
|
||||
export function init() {
|
||||
smartcli.get = {};
|
||||
/**
|
||||
*
|
||||
* @param commandString
|
||||
* @returns {{specified: boolean, name: any, arguments: CliCommandArgument}}
|
||||
*/
|
||||
smartcli.get.command = function():CliCommand {
|
||||
var cliCommand = {
|
||||
specified: smartcli.check.commandPresence(),
|
||||
name: plugins.argv._[0],
|
||||
arguments: smartcli.get.commandArgs()
|
||||
}
|
||||
return cliCommand;
|
||||
};
|
||||
/// <reference path="./smartcli.interfaces.ts" />
|
||||
|
||||
/**
|
||||
* gets the second or higher value of plugins.argv._ if specified and returns it as commandArgument
|
||||
* @param argumentLevel
|
||||
* @returns {{specified: (boolean|boolean), name}}
|
||||
*/
|
||||
smartcli.get.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(smartcli.check.commandArgumentPresence(argumentLevel)) {
|
||||
commandArgument.specified = true;
|
||||
commandArgument.name = plugins.argv._[argumentLevel];
|
||||
}
|
||||
return commandArgument;
|
||||
};
|
||||
import plugins = require("./smartcli.plugins");
|
||||
import SmartcliChecks = require("./smartcli.checks");
|
||||
|
||||
/**
|
||||
* returns array with commandArgs
|
||||
* @returns {CliCommandArgument[]}
|
||||
*/
|
||||
smartcli.get.commandArgs = function():CliCommandArgument[] {
|
||||
var commandArgs:CliCommandArgument[] = [];
|
||||
var argsArray = smartcli.get.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}
|
||||
*/
|
||||
smartcli.get.commandArray = function ():string[] {
|
||||
var commandArray = plugins.argv._;
|
||||
return commandArray;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* returns a cli option
|
||||
* @param optionName
|
||||
* @returns {CliOption}
|
||||
*/
|
||||
smartcli.get.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;
|
||||
};
|
||||
|
||||
|
||||
smartcli.get.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}}
|
||||
*/
|
||||
smartcli.get.cwd = function():Directory {
|
||||
return {
|
||||
path: process.cwd()
|
||||
}
|
||||
};
|
||||
/**
|
||||
*
|
||||
* @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,61 +1,59 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
module SmartcliInteraction {
|
||||
export function init(){
|
||||
/// <reference path="./smartcli.interfaces.ts" />
|
||||
|
||||
smartcli.interaction = {};
|
||||
/**
|
||||
* executes callback with answer to question as argument
|
||||
* @param questionString the question you want to ask the user
|
||||
* @param cb the function to execute with answer as param
|
||||
* @returns {null}
|
||||
*/
|
||||
smartcli.interaction.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;
|
||||
}
|
||||
};
|
||||
import plugins = require("./smartcli.plugins");
|
||||
|
||||
plugins.inquirer.prompt([question],function(answers){
|
||||
var answer = answers.userFeedback;
|
||||
cb(answer);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param questionString
|
||||
* @param choiceOptions
|
||||
* @param cb
|
||||
* @returns {null}
|
||||
*/
|
||||
smartcli.interaction.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);
|
||||
});
|
||||
|
||||
};
|
||||
/**
|
||||
* 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,5 +1,3 @@
|
||||
/// <reference path="typings/main.d.ts" />
|
||||
|
||||
interface CliOption {
|
||||
name: string;
|
||||
specified:boolean;
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"ambientDependencies": {
|
||||
"mocha": "registry:dt/mocha#2.2.5+20151023103246",
|
||||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts"
|
||||
}
|
||||
}
|
||||
|
3
ts/typings/browser.d.ts
vendored
3
ts/typings/browser.d.ts
vendored
@ -1 +1,2 @@
|
||||
/// <reference path="browser/ambient/node/node.d.ts" />
|
||||
/// <reference path="browser/ambient/mocha/index.d.ts" />
|
||||
/// <reference path="browser/ambient/node/index.d.ts" />
|
||||
|
2180
ts/typings/browser/ambient/node/node.d.ts
vendored
2180
ts/typings/browser/ambient/node/node.d.ts
vendored
File diff suppressed because it is too large
Load Diff
3
ts/typings/main.d.ts
vendored
3
ts/typings/main.d.ts
vendored
@ -1 +1,2 @@
|
||||
/// <reference path="main/ambient/node/node.d.ts" />
|
||||
/// <reference path="main/ambient/mocha/index.d.ts" />
|
||||
/// <reference path="main/ambient/node/index.d.ts" />
|
||||
|
2180
ts/typings/main/ambient/node/node.d.ts
vendored
2180
ts/typings/main/ambient/node/node.d.ts
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user