appcenter-cli
Version:
Command line tool for Visual Studio App Center
78 lines (77 loc) • 4.24 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) {
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) : new P(function (resolve) { resolve(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 apis_1 = require("../../util/apis");
const debug = require("debug")("appcenter-cli:commands:orgs:create");
const util_1 = require("util");
const portal_helper_1 = require("../../util/portal/portal-helper");
const org_users_helper_1 = require("./lib/org-users-helper");
let OrgCreateCommand = class OrgCreateCommand extends commandline_1.Command {
run(client, portalBaseUrl) {
return __awaiter(this, void 0, void 0, function* () {
let organizationInfo;
try {
const httpResponse = yield interaction_1.out.progress("Creating new organization...", apis_1.clientRequest((cb) => client.organizations.createOrUpdate({
displayName: this.displayName,
name: this.name
}, cb)));
if (httpResponse.response.statusCode < 400) {
organizationInfo = httpResponse.result;
}
else {
throw httpResponse.response;
}
}
catch (error) {
if (error.statusCode === 409) {
return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `organization ${this.name || this.displayName} already exists`);
}
else {
debug(`Failed to create organization - ${util_1.inspect(error)}`);
return commandline_1.failure(commandline_1.ErrorCodes.Exception, "failed to create organization");
}
}
const admins = org_users_helper_1.pickAdmins(yield org_users_helper_1.getOrgUsers(client, organizationInfo.name, debug));
interaction_1.out.text(`Successfully created organization ${organizationInfo.name}`);
interaction_1.out.report([
["Name", "name"],
["Display name", "displayName"],
["URL", "url"],
["Admins", "admins", (adminsArray) => adminsArray.map((admin) => admin.name).join(", ")]
], { name: organizationInfo.name, displayName: organizationInfo.displayName, url: portal_helper_1.getPortalOrgLink(portalBaseUrl, organizationInfo.name), admins });
return commandline_1.success();
});
}
};
__decorate([
commandline_1.help("Display name of the organization"),
commandline_1.shortName("d"),
commandline_1.longName("display-name"),
commandline_1.required,
commandline_1.hasArg
], OrgCreateCommand.prototype, "displayName", void 0);
__decorate([
commandline_1.help("Name of the organization"),
commandline_1.shortName("n"),
commandline_1.longName("name"),
commandline_1.hasArg
], OrgCreateCommand.prototype, "name", void 0);
OrgCreateCommand = __decorate([
commandline_1.help("Create a new organization")
], OrgCreateCommand);
exports.default = OrgCreateCommand;