smartcli/dist/smartcli.classes.smartcli.js
2016-06-10 04:32:11 +02:00

67 lines
6.8 KiB
JavaScript

"use strict";
require("typings-global");
var plugins = require("./smartcli.plugins");
var Smartcli = (function () {
function Smartcli() {
this.argv = plugins.argv;
this.questionsDone = plugins.q.defer();
this.parseStarted = plugins.q.defer();
}
Smartcli.prototype.addAlias = function (keyArg, aliasArg) {
this.argv = this.argv.alias(keyArg, aliasArg);
};
;
Smartcli.prototype.addCommand = function (definitionArg) {
var _this = this;
var done = plugins.q.defer();
this.parseStarted.promise
.then(function () {
if (_this.argv._.indexOf(definitionArg.commandName) == 0) {
done.resolve(_this.argv);
}
else {
return done.reject();
}
});
return done.promsise;
};
;
Smartcli.prototype.addQuestion = function (definitionArg) {
};
;
Smartcli.prototype.addVersion = function (versionArg) {
var _this = this;
this.version = versionArg;
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.promise
.then(function () {
if (_this.argv._.length == 0 && !_this.argv.v) {
done.resolve();
}
else {
done.reject();
}
;
});
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4QixJQUFZLE9BQU8sV0FBTSxvQkFDekIsQ0FBQyxDQUQ0QztBQUc3QztJQU9JO1FBQ0ksSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDO1FBQ3pCLElBQUksQ0FBQyxhQUFhLEdBQUcsT0FBTyxDQUFDLENBQUMsQ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ICAgICAgICAgICBpZiAodGhpcy5hcmd2Ll8uaW5kZXhPZihkZWZpbml0aW9uQXJnLmNvbW1hbmROYW1lKSA9PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUucmVzb2x2ZSh0aGlzLmFyZ3YpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBkb25lLnJlamVjdCgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICByZXR1cm4gZG9uZS5wcm9tc2lzZTtcbiAgICB9O1xuICAgIGFkZFF1ZXN0aW9uKGRlZmluaXRpb25Bcmc6e3F1ZXN0aW9uU3RyaW5nOnN0cmluZyxxdWVzdGlvblR5cGU6c3RyaW5nfSl7XG4gICAgICAgIFxuICAgIH07XG4gICAgYWRkVmVyc2lvbih2ZXJzaW9uQXJnOnN0cmluZyl7XG4gICAgICAgIHRoaXMudmVyc2lvbiA9IHZlcnNpb25Bcmc7XG4gICAgICAgIHRoaXMuYWRkQWxpYXMoXCJ2XCIsXCJ2ZXJzaW9uXCIpO1xuICAgICAgICB0aGlzLnBhcnNlU3RhcnRlZC5wcm9taXNlXG4gICAgICAgICAgICAudGhlbigoKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYodGhpcy5hcmd2LnYpe1xuICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyh0aGlzLnZlcnNpb24pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pXG4gICAgfVxuICAgIHN0YW5kYXJkVGFzaygpe1xuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xuICAgICAgICB0aGlzLnBhcnNlU3RhcnRlZC5wcm9taXNlXG4gICAgICAgICAgICAudGhlbigoKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYodGhpcy5hcmd2Ll8ubGVuZ3RoID09IDAgJiYgIXRoaXMuYXJndi52KXtcbiAgICAgICAgICAgICAgICAgICAgZG9uZS5yZXNvbHZlKCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgZG9uZS5yZWplY3QoKTtcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XG4gICAgfVxuICAgIHN0YXJ0UGFyc2UoKXtcbiAgICAgICAgdGhpcy5hcmd2ID0gdGhpcy5hcmd2LmFyZ3Y7XG4gICAgICAgIHRoaXMucGFyc2VTdGFydGVkLnJlc29sdmUoKTtcbiAgICB9XG5cbn0iXX0=