69 lines
7.0 KiB
JavaScript
69 lines
7.0 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 {
|
|
done.reject(_this.argv);
|
|
}
|
|
});
|
|
return done.promsise;
|
|
};
|
|
;
|
|
Smartcli.prototype.addQuestion = function (definitionArg) {
|
|
};
|
|
;
|
|
Smartcli.prototype.addHelp = function () {
|
|
};
|
|
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(_this.argv);
|
|
}
|
|
else {
|
|
done.reject(_this.argv);
|
|
}
|
|
;
|
|
});
|
|
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNt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hcnRlZC5wcm9taXNlXG4gICAgICAgICAgICAudGhlbigoKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYodGhpcy5hcmd2LnYpe1xuICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyh0aGlzLnZlcnNpb24pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pXG4gICAgfVxuICAgIHN0YW5kYXJkVGFzaygpe1xuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xuICAgICAgICB0aGlzLnBhcnNlU3RhcnRlZC5wcm9taXNlXG4gICAgICAgICAgICAudGhlbigoKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYodGhpcy5hcmd2Ll8ubGVuZ3RoID09IDAgJiYgIXRoaXMuYXJndi52KXtcbiAgICAgICAgICAgICAgICAgICAgZG9uZS5yZXNvbHZlKHRoaXMuYXJndik7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgZG9uZS5yZWplY3QodGhpcy5hcmd2KTtcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XG4gICAgfVxuICAgIHN0YXJ0UGFyc2UoKXtcbiAgICAgICAgdGhpcy5hcmd2ID0gdGhpcy5hcmd2LmFyZ3Y7XG4gICAgICAgIHRoaXMucGFyc2VTdGFydGVkLnJlc29sdmUoKTtcbiAgICB9XG5cbn0iXX0=
|