2016-06-09 12:03:18 +00:00
|
|
|
"use strict";
|
2016-06-10 01:10:21 +00:00
|
|
|
require("typings-global");
|
2016-08-26 07:21:42 +00:00
|
|
|
const plugins = require("./smartcli.plugins");
|
|
|
|
class Smartcli {
|
|
|
|
constructor() {
|
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-08-26 07:21:42 +00:00
|
|
|
;
|
|
|
|
/**
|
|
|
|
* adds an alias, meaning one equals the other in terms of triggering associated commands
|
|
|
|
*/
|
|
|
|
addAlias(keyArg, aliasArg) {
|
2016-06-10 01:48:01 +00:00
|
|
|
this.argv = this.argv.alias(keyArg, aliasArg);
|
2016-08-26 07:21:42 +00:00
|
|
|
}
|
2016-06-10 01:48:01 +00:00
|
|
|
;
|
2016-08-26 07:21:42 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
2016-06-10 02:13:23 +00:00
|
|
|
this.parseStarted.promise
|
2016-08-26 07:21:42 +00:00
|
|
|
.then(() => {
|
|
|
|
if (this.argv._.indexOf(definitionArg.commandName) == 0) {
|
|
|
|
done.resolve(this.argv);
|
2016-06-10 01:48:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-08-26 07:21:42 +00:00
|
|
|
done.reject(this.argv);
|
2016-06-10 01:48:01 +00:00
|
|
|
}
|
|
|
|
});
|
2016-06-22 09:55:23 +00:00
|
|
|
return done.promise;
|
2016-08-26 07:21:42 +00:00
|
|
|
}
|
2016-06-10 01:10:21 +00:00
|
|
|
;
|
2016-08-26 07:21:42 +00:00
|
|
|
/**
|
|
|
|
* gets a Promise for a command word
|
|
|
|
*/
|
|
|
|
getCommandPromise(commandNameArg) {
|
2016-06-22 09:55:23 +00:00
|
|
|
//TODO
|
2016-08-26 07:21:42 +00:00
|
|
|
}
|
|
|
|
addQuestion(definitionArg) {
|
|
|
|
}
|
2016-06-10 01:10:21 +00:00
|
|
|
;
|
2016-08-26 07:21:42 +00:00
|
|
|
addHelp() {
|
|
|
|
}
|
|
|
|
addVersion(versionArg) {
|
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-08-26 07:21:42 +00:00
|
|
|
.then(() => {
|
|
|
|
if (this.argv.v) {
|
|
|
|
console.log(this.version);
|
2016-06-10 02:13:23 +00:00
|
|
|
}
|
2016-06-10 01:48:01 +00:00
|
|
|
});
|
2016-08-26 07:21:42 +00:00
|
|
|
}
|
|
|
|
standardTask() {
|
|
|
|
let done = plugins.q.defer();
|
2016-06-10 02:13:23 +00:00
|
|
|
this.parseStarted.promise
|
2016-08-26 07:21:42 +00:00
|
|
|
.then(() => {
|
|
|
|
if (this.argv._.length == 0 && !this.argv.v) {
|
|
|
|
done.resolve(this.argv);
|
2016-06-10 01:48:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-08-26 07:21:42 +00:00
|
|
|
done.reject(this.argv);
|
2016-06-10 01:48:01 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
});
|
|
|
|
return done.promise;
|
2016-08-26 07:21:42 +00:00
|
|
|
}
|
|
|
|
startParse() {
|
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-08-26 07:21:42 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-10 01:10:21 +00:00
|
|
|
exports.Smartcli = Smartcli;
|
2016-08-26 07:21:42 +00:00
|
|
|
//# sourceMapping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