appcenter-cli
Version:
Command line tool for Visual Studio App Center
65 lines (64 loc) • 2.83 kB
JavaScript
;
// logic that reads a command line, extracts the actual command, and loads it.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runner = void 0;
const command_result_1 = require("./command-result");
const Finder = require("./command-finder");
const Loader = require("./command-loader");
const interaction_1 = require("../interaction");
const debug = require("debug")("appcenter-cli:util:commandline:command-runner");
const util_1 = require("util");
function runner(arg) {
let loader;
if (typeof arg === "string") {
loader = Loader.loader(Finder.finder(arg));
}
else {
loader = arg;
}
return function commandRunner(command) {
return __awaiter(this, void 0, void 0, function* () {
let factory;
let newCommand;
let args;
let commandPath;
try {
debug(`Loading command ${command}`);
const result = loader(command);
debug(`Command loading completed, result = ${util_1.inspect(result)}`);
if (result === null) {
return command_result_1.notFound(command.join(" "));
}
({ commandFactory: factory, commandParts: newCommand, args, commandPath } = result);
}
catch (ex) {
debug(`Command loading failed, exception = ${ex}`);
// If we got an exception here, it was an illegal command
return command_result_1.illegal(command.join(" "));
}
try {
const commandObj = new factory({ command: newCommand, args, commandPath });
return yield commandObj.execute();
}
catch (ex) {
if (command_result_1.isCommandFailedResult(ex)) {
return ex;
}
if (interaction_1.isDebug()) {
console.log(`Command Failure at ${ex.stack}`);
}
return command_result_1.exception(command.join(" "), ex);
}
});
};
}
exports.runner = runner;