From 834a6c29530de9d7e9cf4171e0d8edb2fc47e713 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Fri, 10 Jun 2016 04:13:23 +0200 Subject: [PATCH] first version with basic funtionality --- dist/smartcli.classes.smartcli.js | 16 ++++++++++----- test/test.js | 34 +++++++++++++++++++++++++++++-- test/test.ts | 34 +++++++++++++++++++++++++++++-- ts/smartcli.classes.smartcli.ts | 14 ++++++++----- 4 files changed, 84 insertions(+), 14 deletions(-) diff --git a/dist/smartcli.classes.smartcli.js b/dist/smartcli.classes.smartcli.js index df8beae..f78c3ae 100644 --- a/dist/smartcli.classes.smartcli.js +++ b/dist/smartcli.classes.smartcli.js @@ -14,7 +14,7 @@ var Smartcli = (function () { Smartcli.prototype.addCommand = function (definitionArg) { var _this = this; var done = plugins.q.defer(); - this.parseStarted + this.parseStarted.promise .then(function () { if (_this.argv._.indexOf(definitionArg.commandName) == 0) { done.resolve(); @@ -30,17 +30,22 @@ var Smartcli = (function () { }; ; Smartcli.prototype.addVersion = function (versionArg) { + var _this = this; this.version = versionArg; - this.parseStarted + this.addAlias("v", "version"); + this.parseStarted.promise .then(function () { + if (_this.argv.v) { + console.log(_this.version); + } }); }; Smartcli.prototype.standardTask = function () { var _this = this; var done = plugins.q.defer(); - this.parseStarted + this.parseStarted.promise .then(function () { - if (plugins.argv._.length == 0 || _this.commands.length == 0) { + if (_this.argv._.length == 0 || !_this.argv.v) { done.resolve(); } else { @@ -51,10 +56,11 @@ var Smartcli = (function () { return done.promise; }; Smartcli.prototype.startParse = function () { + this.argv = this.argv.argv; this.parseStarted.resolve(); }; return Smartcli; }()); exports.Smartcli = Smartcli; -//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4QixJQU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ICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgcmV0dXJuIGRvbmUucHJvbXNpc2U7XG4gICAgfTtcbiAgICBhZGRRdWVzdGlvbihkZWZpbml0aW9uQXJnOntxdWVzdGlvblN0cmluZzpzdHJpbmcscXVlc3Rpb25UeXBlOnN0cmluZ30pe1xuICAgICAgICBcbiAgICB9O1xuICAgIGFkZFZlcnNpb24odmVyc2lvbkFyZzpzdHJpbmcpe1xuICAgICAgICB0aGlzLnZlcnNpb24gPSB2ZXJzaW9uQXJnO1xuICAgICAgICB0aGlzLnBhcnNlU3RhcnRlZFxuICAgICAgICAgICAgLnRoZW4oKCkgPT4ge1xuXG4gICAgICAgICAgICB9KVxuICAgIH1cbiAgICBzdGFuZGFyZFRhc2soKXtcbiAgICAgICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcbiAgICAgICAgdGhpcy5wYXJzZVN0YXJ0ZWRcbiAgICAgICAgICAgIC50aGVuKCgpID0+IHtcbiAgICAgICAgICAgICAgICBpZihwbHVnaW5zLmFyZ3YuXy5sZW5ndGggPT0gMCB8fCB0aGlzLmNvbW1hbmRzLmxlbmd0aCA9PSAwKXtcbiAgICAgICAgICAgICAgICAgICAgZG9uZS5yZXNvbHZlKCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgZG9uZS5yZWplY3QoKTtcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XG4gICAgfVxuICAgIHN0YXJ0UGFyc2UoKXtcbiAgICAgICAgdGhpcy5wYXJzZVN0YXJ0ZWQucmVzb2x2ZSgpO1xuICAgIH1cblxufSJdfQ== +//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW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ICAgfTtcbiAgICBhZGRDb21tYW5kKGRlZmluaXRpb25Bcmc6e2NvbW1hbmROYW1lOnN0cmluZ30pe1xuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xuICAgICAgICB0aGlzLnBhcnNlU3RhcnRlZC5wcm9taXNlXG4gICAgICAgICAgICAudGhlbigoKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuYXJndi5fLmluZGV4T2YoZGVmaW5pdGlvbkFyZy5jb21tYW5kTmFtZSkgPT0gMCkge1xuICAgICAgICAgICAgICAgICAgICBkb25lLnJlc29sdmUoKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZG9uZS5yZWplY3QoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgcmV0dXJuIGRvbmUucHJvbXNpc2U7XG4gICAgfTtcbiAgICBhZGRRdWVzdGlvbihkZWZpbml0aW9uQXJnOntxdWVzdGlvblN0cmluZzpzdHJpbmcscXVlc3Rpb25UeXBlOnN0cmluZ30pe1xuICAgICAgICBcbiAgICB9O1xuICAgIGFkZFZlcnNpb24odmVyc2lvbkFyZzpzdHJpbmcpe1xuICAgICAgICB0aGlzLnZlcnNpb24gPSB2ZXJzaW9uQXJnO1xuICAgICAgICB0aGlzLmFkZEFsaWFzKFwidlwiLFwidmVyc2lvblwiKTtcbiAgICAgICAgdGhpcy5wYXJzZVN0YXJ0ZWQucHJvbWlzZVxuICAgICAgICAgICAgLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgICAgIGlmKHRoaXMuYXJndi52KXtcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2codGhpcy52ZXJzaW9uKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KVxuICAgIH1cbiAgICBzdGFuZGFyZFRhc2soKXtcbiAgICAgICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcbiAgICAgICAgdGhpcy5wYXJzZVN0YXJ0ZWQucHJvbWlzZVxuICAgICAgICAgICAgLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgICAgIGlmKHRoaXMuYXJndi5fLmxlbmd0aCA9PSAwIHx8ICF0aGlzLmFyZ3Yudil7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUucmVzb2x2ZSgpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUucmVqZWN0KCk7XG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xuICAgIH1cbiAgICBzdGFydFBhcnNlKCl7XG4gICAgICAgIHRoaXMuYXJndiA9IHRoaXMuYXJndi5hcmd2O1xuICAgICAgICB0aGlzLnBhcnNlU3RhcnRlZC5yZXNvbHZlKCk7XG4gICAgfVxuXG59Il19 diff --git a/test/test.js b/test/test.js index 6c9da83..0c07917 100644 --- a/test/test.js +++ b/test/test.js @@ -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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMi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AgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhcInRoaXMgaXMgdGhlIHN0YW5kYXJkIFRhc2shXCIpO1xuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgZG9uZSgpO1xuICAgICAgICB9KVxuICAgIH0pXG4gICAgZGVzY3JpYmUoXCIuc3RhcnRQYXJzZVwiLGZ1bmN0aW9uKCl7XG4gICAgICAgIGl0KFwic2hvdWxkIHN0YXJ0IHBhcnNpbmcgdGhlIENMSSBpbnB1dFwiLGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICBzbWFydENsaVRlc3RPYmplY3Quc3RhcnRQYXJzZSgpO1xuICAgICAgICB9KVxuICAgIH0pXG59KTtcbiJdfQ== diff --git a/test/test.ts b/test/test.ts index 0c16521..4c8b63a 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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(); + }) + }) +}); diff --git a/ts/smartcli.classes.smartcli.ts b/ts/smartcli.classes.smartcli.ts index 5653cf2..72bb3cc 100644 --- a/ts/smartcli.classes.smartcli.ts +++ b/ts/smartcli.classes.smartcli.ts @@ -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(); }