smartcli/dist/smartcli.classes.smartcli.js

67 lines
6.7 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();
}
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4QixJQUFZLE9BQU8sV0FBTSxvQkFDekIsQ0FBQyxDQUQ0QztBQUc3QztJQU9JO1FBQ0ksSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDO1FBQ3pCLElBQUksQ0FBQyxhQUFhLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FB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dGlvbkFyZy5jb21tYW5kTmFtZSkgPT0gMCkge1xuICAgICAgICAgICAgICAgICAgICBkb25lLnJlc29sdmUoKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZG9uZS5yZWplY3QoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgcmV0dXJuIGRvbmUucHJvbXNpc2U7XG4gICAgfTtcbiAgICBhZGRRdWVzdGlvbihkZWZpbml0aW9uQXJnOntxdWVzdGlvblN0cmluZzpzdHJpbmcscXVlc3Rpb25UeXBlOnN0cmluZ30pe1xuICAgICAgICBcbiAgICB9O1xuICAgIGFkZFZlcnNpb24odmVyc2lvbkFyZzpzdHJpbmcpe1xuICAgICAgICB0aGlzLnZlcnNpb24gPSB2ZXJzaW9uQXJnO1xuICAgICAgICB0aGlzLmFkZEFsaWFzKFwidlwiLFwidmVyc2lvblwiKTtcbiAgICAgICAgdGhpcy5wYXJzZVN0YXJ0ZWQucHJvbWlzZVxuICAgICAgICAgICAgLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgICAgIGlmKHRoaXMuYXJndi52KXtcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2codGhpcy52ZXJzaW9uKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KVxuICAgIH1cbiAgICBzdGFuZGFyZFRhc2soKXtcbiAgICAgICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcbiAgICAgICAgdGhpcy5wYXJzZVN0YXJ0ZWQucHJvbWlzZVxuICAgICAgICAgICAgLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgICAgIGlmKHRoaXMuYXJndi5fLmxlbmd0aCA9PSAwIHx8ICF0aGlzLmFyZ3Yudil7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUucmVzb2x2ZSgpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUucmVqZWN0KCk7XG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xuICAgIH1cbiAgICBzdGFydFBhcnNlKCl7XG4gICAgICAgIHRoaXMuYXJndiA9IHRoaXMuYXJndi5hcmd2O1xuICAgICAgICB0aGlzLnBhcnNlU3RhcnRlZC5yZXNvbHZlKCk7XG4gICAgfVxuXG59Il19