first version with basic funtionality

This commit is contained in:
Philipp Kunz 2016-06-10 04:13:23 +02:00
parent e1c2de8a40
commit 834a6c2953
4 changed files with 84 additions and 14 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,37 @@
"use strict";
require("typings-test");
var smartcli = require("../dist/index.js");
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFFdEIsSUFBSSxRQUFRLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBQUM7QUFDM0MsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ3JDLElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQyIsImZpbGUiOiJ0ZXN0LmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy10ZXN0XCI7XG5cbmxldCBzbWFydGNsaSA9IHJlcXVpcmUoXCIuLi9kaXN0L2luZGV4LmpzXCIpO1xubGV0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XG5sZXQgc2hvdWxkID0gcmVx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2xpKTtcbiAgICAgICAgfSk7XG4gICAgfSk7XG4gICAgZGVzY3JpYmUoXCIuYWRkQ29tbWFuZFwiLGZ1bmN0aW9uKCl7XG4gICAgICAgIGl0KFwic2hvdWxkIGFkZCBhbiBjb21tYW5kXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgIHNtYXJ0Q2xpVGVzdE9iamVjdC5hZGRDb21tYW5kKHtcbiAgICAgICAgICAgICAgICBjb21tYW5kTmFtZTpcImF3ZXNvbWVcIlxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICBcbiAgICAgICAgfSk7XG4gICAgfSk7XG4gICAgZGVzY3JpYmUoXCIuc3RhbmRhcmRUYXNrXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgaXQoXCJzaG91bGQgc3RhcnQgcGFyc2luZyBhIHN0YW5kYXJkVGFza1wiLGZ1bmN0aW9uKGRvbmUpe1xuICAgICAgICAgICAgc21hcnRDbGlUZXN0T2JqZWN0LnN0YW5kYXJkVGFzaygpXG4gICAgICAgICAgICAgICAgLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhcInRoaXMgaXMgdGhlIHN0YW5kYXJkIFRhc2shXCIpO1xuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgZG9uZSgpO1xuICAgICAgICB9KVxuICAgIH0pXG4gICAgZGVzY3JpYmUoXCIuc3RhcnRQYXJzZVwiLGZ1bmN0aW9uKCl7XG4gICAgICAgIGl0KFwic2hvdWxkIHN0YXJ0IHBhcnNpbmcgdGhlIENMSSBpbnB1dFwiLGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICBzbWFydENsaVRlc3RPYmplY3Quc3RhcnRQYXJzZSgpO1xuICAgICAgICB9KVxuICAgIH0pXG59KTtcbiJdfQ==

View File

@ -1,7 +1,37 @@
import "typings-test";
let smartcli = require("../dist/index.js");
import smartcli = require("../dist/index");
let beautylog = require("beautylog");
let should = require("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();
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();
})
})
});

View File

@ -20,7 +20,7 @@ export class Smartcli {
};
addCommand(definitionArg:{commandName:string}){
let done = plugins.q.defer();
this.parseStarted
this.parseStarted.promise
.then(() => {
if (this.argv._.indexOf(definitionArg.commandName) == 0) {
done.resolve();
@ -35,16 +35,19 @@ export class Smartcli {
};
addVersion(versionArg:string){
this.version = versionArg;
this.parseStarted
this.addAlias("v","version");
this.parseStarted.promise
.then(() => {
if(this.argv.v){
console.log(this.version);
}
})
}
standardTask(){
let done = plugins.q.defer();
this.parseStarted
this.parseStarted.promise
.then(() => {
if(plugins.argv._.length == 0 || this.commands.length == 0){
if(this.argv._.length == 0 || !this.argv.v){
done.resolve();
} else {
done.reject();
@ -53,6 +56,7 @@ export class Smartcli {
return done.promise;
}
startParse(){
this.argv = this.argv.argv;
this.parseStarted.resolve();
}