2016-06-09 12:03:18 +00:00
|
|
|
"use strict";
|
2016-06-10 01:10:21 +00:00
|
|
|
require("typings-global");
|
|
|
|
var plugins = require("./smartcli.plugins");
|
|
|
|
var Smartcli = (function () {
|
|
|
|
function Smartcli() {
|
2016-06-10 01:48:01 +00:00
|
|
|
this.argv = plugins.argv;
|
2016-06-10 01:10:21 +00:00
|
|
|
this.questionsDone = plugins.q.defer();
|
2016-06-10 01:48:01 +00:00
|
|
|
this.parseStarted = plugins.q.defer();
|
2016-06-09 12:03:18 +00:00
|
|
|
}
|
2016-06-10 01:48:01 +00:00
|
|
|
Smartcli.prototype.addAlias = function (keyArg, aliasArg) {
|
|
|
|
this.argv = this.argv.alias(keyArg, aliasArg);
|
|
|
|
};
|
|
|
|
;
|
2016-06-10 01:10:21 +00:00
|
|
|
Smartcli.prototype.addCommand = function (definitionArg) {
|
2016-06-10 01:48:01 +00:00
|
|
|
var _this = this;
|
2016-06-10 01:10:21 +00:00
|
|
|
var done = plugins.q.defer();
|
2016-06-10 02:13:23 +00:00
|
|
|
this.parseStarted.promise
|
2016-06-10 01:48:01 +00:00
|
|
|
.then(function () {
|
|
|
|
if (_this.argv._.indexOf(definitionArg.commandName) == 0) {
|
2016-06-10 02:32:11 +00:00
|
|
|
done.resolve(_this.argv);
|
2016-06-10 01:48:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-06-16 00:58:45 +00:00
|
|
|
done.reject(_this.argv);
|
2016-06-10 01:48:01 +00:00
|
|
|
}
|
|
|
|
});
|
2016-06-10 01:10:21 +00:00
|
|
|
return done.promsise;
|
|
|
|
};
|
|
|
|
;
|
|
|
|
Smartcli.prototype.addQuestion = function (definitionArg) {
|
|
|
|
};
|
|
|
|
;
|
2016-06-16 00:58:45 +00:00
|
|
|
Smartcli.prototype.addHelp = function () {
|
|
|
|
};
|
2016-06-10 01:10:21 +00:00
|
|
|
Smartcli.prototype.addVersion = function (versionArg) {
|
2016-06-10 02:13:23 +00:00
|
|
|
var _this = this;
|
2016-06-10 01:48:01 +00:00
|
|
|
this.version = versionArg;
|
2016-06-10 02:13:23 +00:00
|
|
|
this.addAlias("v", "version");
|
|
|
|
this.parseStarted.promise
|
2016-06-10 01:48:01 +00:00
|
|
|
.then(function () {
|
2016-06-10 02:13:23 +00:00
|
|
|
if (_this.argv.v) {
|
|
|
|
console.log(_this.version);
|
|
|
|
}
|
2016-06-10 01:48:01 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
Smartcli.prototype.standardTask = function () {
|
|
|
|
var _this = this;
|
|
|
|
var done = plugins.q.defer();
|
2016-06-10 02:13:23 +00:00
|
|
|
this.parseStarted.promise
|
2016-06-10 01:48:01 +00:00
|
|
|
.then(function () {
|
2016-06-10 02:32:11 +00:00
|
|
|
if (_this.argv._.length == 0 && !_this.argv.v) {
|
2016-06-16 00:58:45 +00:00
|
|
|
done.resolve(_this.argv);
|
2016-06-10 01:48:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-06-16 00:58:45 +00:00
|
|
|
done.reject(_this.argv);
|
2016-06-10 01:48:01 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
});
|
|
|
|
return done.promise;
|
2016-06-10 01:10:21 +00:00
|
|
|
};
|
|
|
|
Smartcli.prototype.startParse = function () {
|
2016-06-10 02:13:23 +00:00
|
|
|
this.argv = this.argv.argv;
|
2016-06-10 01:48:01 +00:00
|
|
|
this.parseStarted.resolve();
|
2016-06-10 01:10:21 +00:00
|
|
|
};
|
|
|
|
return Smartcli;
|
2016-06-09 12:03:18 +00:00
|
|
|
}());
|
2016-06-10 01:10:21 +00:00
|
|
|
exports.Smartcli = Smartcli;
|
2016-06-09 12:03:18 +00:00
|
|
|
|
2016-06-16 00:58:45 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ij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