smartcli/dist/smartcli.classes.smartcli.js
2016-08-26 09:21:42 +02:00

78 lines
4.6 KiB
JavaScript

"use strict";
require("typings-global");
const plugins = require("./smartcli.plugins");
class Smartcli {
constructor() {
this.argv = plugins.argv;
this.questionsDone = plugins.q.defer();
this.parseStarted = plugins.q.defer();
}
;
/**
* adds an alias, meaning one equals the other in terms of triggering associated commands
*/
addAlias(keyArg, aliasArg) {
this.argv = this.argv.alias(keyArg, aliasArg);
}
;
/**
* adds a Command by returning a Promise that reacts to the specific commandString given.
*
* Note: in e.g. "npm install something" the "install" is considered the command.
*/
addCommand(definitionArg) {
let done = plugins.q.defer();
this.parseStarted.promise
.then(() => {
if (this.argv._.indexOf(definitionArg.commandName) == 0) {
done.resolve(this.argv);
}
else {
done.reject(this.argv);
}
});
return done.promise;
}
;
/**
* gets a Promise for a command word
*/
getCommandPromise(commandNameArg) {
//TODO
}
addQuestion(definitionArg) {
}
;
addHelp() {
}
addVersion(versionArg) {
this.version = versionArg;
this.addAlias("v", "version");
this.parseStarted.promise
.then(() => {
if (this.argv.v) {
console.log(this.version);
}
});
}
standardTask() {
let done = plugins.q.defer();
this.parseStarted.promise
.then(() => {
if (this.argv._.length == 0 && !this.argv.v) {
done.resolve(this.argv);
}
else {
done.reject(this.argv);
}
;
});
return done.promise;
}
startParse() {
this.argv = this.argv.argv;
this.parseStarted.resolve();
}
}
exports.Smartcli = Smartcli;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4QixNQUFZLE9BQU8sV0FBTSxvQkFBb0IsQ0FBQyxDQUFBO0FBRzlDO0lBT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