remove bulk and add some features to Smartcli class

This commit is contained in:
2016-06-10 03:48:01 +02:00
parent 9e76f2afb1
commit e1c2de8a40
14 changed files with 80 additions and 382 deletions

View File

@ -1,42 +0,0 @@
import "typings-global";
import "./smartcli.interfaces";
import plugins = require("./smartcli.plugins");
/**
* 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;
};

View File

@ -1,35 +1,59 @@
import "typings-global";
import * as interfaces from "./smartcli.interfaces"
import * as plugins from "./smartcli.plugins"
import * as SmartcliChecks from "./smartcli.checks";
import * as SmartcliGetters from "./smartcli.getters";
import * as SmartcliInteractions from "./smartcli.interaction";
export class Smartcli {
argv;
questionsDone;
commands:interfaces.CliCommand[];
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();
if (plugins.argv._.indexOf(definitionArg.commandName) == 0) {
done.resolve();
} else {
return done.reject();
}
this.parseStarted
.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.parseStarted
.then(() => {
})
}
standardTask(){
let done = plugins.q.defer();
this.parseStarted
.then(() => {
if(plugins.argv._.length == 0 || this.commands.length == 0){
done.resolve();
} else {
done.reject();
};
});
return done.promise;
}
startParse(){
this.parseStarted.resolve();
}
}

View File

@ -1,97 +0,0 @@
import "typings-global";
import * as interfaces from "./smartcli.interfaces";
import plugins = require("./smartcli.plugins");
import SmartcliChecks = require("./smartcli.checks");
/**
* 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):interfaces.CliCommandArgument {
var commandArgument:interfaces.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():interfaces.CliCommandArgument[] {
var commandArgs:interfaces.CliCommandArgument[] = [];
var argsArray = commandArray().slice(0);
argsArray.shift();
for (let item in argsArray){
let commandArgument:interfaces.CliCommandArgument = {
specified:true,
name:argsArray[item],
level: parseInt(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):interfaces.CliOption {
var cliOption:interfaces.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():interfaces.Directory {
return {
path: process.cwd()
}
};

View File

@ -1,23 +0,0 @@
import "typings-global";
export interface CliCommand {
specified: boolean;
name: string;
arguments:CliCommandArgument[];
}
export interface CliOption {
name: string;
specified:boolean;
value: any;
}
export interface Directory {
path: string;
}
export interface CliCommandArgument {
specified:boolean;
name:string;
level:number;
}

View File

@ -1,6 +1,6 @@
import "typings-global";
export let argv = require('yargs').argv;
export let argv = require('yargs');
export let beautylog = require("beautylog");
export let cliff = require("cliff");
export let inquirer = require("inquirer");