Start restructuring to use a smarter Smartcli class that handles command evaluation for you
This commit is contained in:
29
ts/index.ts
29
ts/index.ts
@@ -1,33 +1,4 @@
|
||||
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";
|
||||
|
||||
import {Smartcli} from "./smartcli.classes.smartcli";
|
||||
export {Smartcli} from "./smartcli.classes.smartcli";
|
||||
|
||||
/* ------------------------------------------------ *
|
||||
* ---------- plugins for direct use -------------- *
|
||||
* ------------------------------------------------ */
|
||||
export let commander = plugins.commander; //commander allows cool chaining of cli actions
|
||||
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;
|
||||
|
@@ -3,28 +3,6 @@ import "typings-global";
|
||||
import "./smartcli.interfaces";
|
||||
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
|
||||
|
@@ -1,5 +1,35 @@
|
||||
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 {
|
||||
|
||||
questionsDone;
|
||||
commands:interfaces.CliCommand[];
|
||||
questions;
|
||||
constructor(){
|
||||
this.questionsDone = plugins.q.defer();
|
||||
}
|
||||
addCommand(definitionArg:{commandName:string}){
|
||||
let done = plugins.q.defer();
|
||||
if (plugins.argv._.indexOf(definitionArg.commandName) == 0) {
|
||||
done.resolve();
|
||||
} else {
|
||||
return done.reject();
|
||||
}
|
||||
return done.promsise;
|
||||
};
|
||||
addQuestion(definitionArg:{questionString:string,questionType:string}){
|
||||
|
||||
};
|
||||
addVersion(versionArg:string){
|
||||
|
||||
}
|
||||
startParse(){
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -4,19 +4,6 @@ import * as interfaces from "./smartcli.interfaces";
|
||||
import plugins = require("./smartcli.plugins");
|
||||
import SmartcliChecks = require("./smartcli.checks");
|
||||
|
||||
/**
|
||||
*
|
||||
* @param commandString
|
||||
* @returns {{specified: boolean, name: any, arguments: CliCommandArgument}}
|
||||
*/
|
||||
export let command = function():interfaces.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
|
||||
|
@@ -15,7 +15,7 @@ export let getAnswer = function(questionString:string, cb) {
|
||||
return null;
|
||||
}
|
||||
//make inquirer compatible question object
|
||||
var question = {
|
||||
let question = {
|
||||
type: "input",
|
||||
name: "userFeedback",
|
||||
message: questionString,
|
||||
@@ -25,7 +25,7 @@ export let getAnswer = function(questionString:string, cb) {
|
||||
};
|
||||
|
||||
plugins.inquirer.prompt([question],function(answers){
|
||||
var answer = answers.userFeedback;
|
||||
let answer = answers.userFeedback;
|
||||
cb(answer);
|
||||
});
|
||||
};
|
||||
@@ -43,7 +43,7 @@ export let getChoice = function(questionString:string, choiceOptions:string[], c
|
||||
}
|
||||
|
||||
//make inquirer compatible question object
|
||||
var question = {
|
||||
let question = {
|
||||
type: "list",
|
||||
name: "userFeedback",
|
||||
message: questionString,
|
||||
@@ -52,7 +52,7 @@ export let getChoice = function(questionString:string, choiceOptions:string[], c
|
||||
};
|
||||
|
||||
plugins.inquirer.prompt(question,function(answers){
|
||||
var answer = answers.userFeedback;
|
||||
let answer = answers.userFeedback;
|
||||
cb(answer);
|
||||
});
|
||||
|
||||
|
@@ -1,5 +1,11 @@
|
||||
import "typings-global";
|
||||
|
||||
export interface CliCommand {
|
||||
specified: boolean;
|
||||
name: string;
|
||||
arguments:CliCommandArgument[];
|
||||
}
|
||||
|
||||
export interface CliOption {
|
||||
name: string;
|
||||
specified:boolean;
|
||||
@@ -10,12 +16,6 @@ export interface Directory {
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface CliCommand {
|
||||
specified: boolean;
|
||||
name: string;
|
||||
arguments:CliCommandArgument[];
|
||||
}
|
||||
|
||||
export interface CliCommandArgument {
|
||||
specified:boolean;
|
||||
name:string;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import "typings-global";
|
||||
|
||||
export let path = require("path");
|
||||
export let argv = require('yargs').argv;
|
||||
export let beautylog = require("beautylog");
|
||||
export let cliff = require("cliff");
|
||||
export let commander = require("commander");
|
||||
export let inquirer = require("inquirer");
|
||||
export let smartparam = require("smartparam");
|
||||
export let argv = require('yargs').argv;
|
||||
export let path = require("path");
|
||||
export let q = require("q");
|
||||
export let smartparam = require("smartparam");
|
Reference in New Issue
Block a user