appcenter-cli
Version:
Command line tool for Visual Studio App Center
96 lines (95 loc) • 5.43 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
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 });
const commandline_1 = require("../../../util/commandline");
const interaction_1 = require("../../../util/interaction");
const util_1 = require("util");
const create_client_1 = require("../../../util/apis/create-client");
const debug = require("debug")("appcenter-cli:commands:distribute:releases:edit");
let EditReleaseCommand = class EditReleaseCommand extends commandline_1.AppCommand {
run(client) {
return __awaiter(this, void 0, void 0, function* () {
const app = this.app;
const releaseId = Number(this.releaseId);
if (!Number.isSafeInteger(releaseId) || releaseId <= 0) {
return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `${this.releaseId} is not a valid release id`);
}
const state = this.state;
if (state !== "enabled" && state !== "disabled") {
return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `"${state}" is not a valid release state. Available states are "enabled" or "disabled".`);
}
let releaseDetails;
let commandFailure;
try {
debug("Loading release details");
releaseDetails = yield interaction_1.out.progress("Loading release details...", client.releases.getLatestByUser(this.releaseId, app.ownerName, app.appName, {
onResponse: (response, _flatResponse, _error) => {
if (response.status >= 400) {
commandFailure =
response.status === 404
? commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `release ${this.releaseId} doesn't exist`)
: commandline_1.failure(commandline_1.ErrorCodes.Exception, "failed to load release details");
}
},
}));
}
catch (error) {
create_client_1.handleHttpError(error, false, "failed to load release details");
}
if (commandFailure) {
return commandFailure;
}
try {
debug(`Updating release state to "${state}"`);
yield interaction_1.out.progress(`${state === "enabled" ? "Enabling" : "Disabling"} the release...`, client.releases.updateDetails(releaseId, app.ownerName, app.appName, {
enabled: state === "enabled",
onResponse: (response, _flatResponse, _error) => {
if (response.status >= 400) {
commandFailure = commandline_1.failure(commandline_1.ErrorCodes.Exception, `failed to ${state === "enabled" ? "enable" : "disable"} the release`);
}
},
}));
}
catch (error) {
debug(`Failed to update the release - ${util_1.inspect(error)}`);
return commandline_1.failure(commandline_1.ErrorCodes.Exception, `failed to ${state === "enabled" ? "enable" : "disable"} the release`);
}
if (commandFailure) {
return commandFailure;
}
interaction_1.out.text(`Release ${releaseDetails.shortVersion} (${releaseDetails.version}) with id: ${this.releaseId} has been ${state}`);
return commandline_1.success();
});
}
};
__decorate([
commandline_1.help("Release ID"),
commandline_1.shortName("r"),
commandline_1.longName("release-id"),
commandline_1.required,
commandline_1.hasArg
], EditReleaseCommand.prototype, "releaseId", void 0);
__decorate([
commandline_1.help("Release state: enabled or disabled"),
commandline_1.name("State"),
commandline_1.position(0),
commandline_1.required
], EditReleaseCommand.prototype, "state", void 0);
EditReleaseCommand = __decorate([
commandline_1.help("Toggles enabling and disabling the specified release")
], EditReleaseCommand);
exports.default = EditReleaseCommand;