UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

92 lines (91 loc) 4.28 kB
"use strict"; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCurrentApp = exports.AppCommand = void 0; const command_1 = require("./command"); const commandline_1 = require("../commandline"); const option_decorators_1 = require("./option-decorators"); const profile_1 = require("../profile"); const misc_1 = require("../misc"); const currentAppVar = "MOBILE_CENTER_CURRENT_APP"; class AppCommand extends command_1.Command { constructor(args) { super(args); } // Figure out which application to work on get app() { let result; // Explicit command line if (this.appOption) { result = profile_1.toDefaultApp(this.appOption); if (!result) { throw new Error(`'${this.appOption}' is not a valid application id`); } // Environment variable } else if (process.env[currentAppVar]) { result = profile_1.toDefaultApp(process.env[currentAppVar]); if (!result) { throw new Error(`'${process.env[currentAppVar]}' (read from ${currentAppVar}) is not a valid application id`); } // Default app in profile } else { const profile = profile_1.getUser(); if (profile === null || profile === void 0 ? void 0 : profile.defaultApp) { result = profile.defaultApp; // Couldn't find one, fail. } else { throw new Error(`Could not find application to work on. Specify the '--app' switch, use '${misc_1.scriptName} apps set-current', or set the ${currentAppVar} environment variable.`); } } return result; } get identifier() { return `${this.app.ownerName}/${this.app.appName}`; } } __decorate([ option_decorators_1.shortName("a"), option_decorators_1.longName("app"), option_decorators_1.hasArg, option_decorators_1.help("Specify app in the <ownerName>/<appName> format") ], AppCommand.prototype, "appOption", void 0); exports.AppCommand = AppCommand; function getCurrentApp(optValue) { function fromCommandLineOpt() { if (optValue) { const result = profile_1.toDefaultApp(optValue); if (!result) { return commandline_1.ResultOrValue.fromResult(commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `'${optValue}' is not a valid application id`)); } return commandline_1.ResultOrValue.fromValue(result); } } function fromEnvironment() { if (process.env[currentAppVar]) { const result = profile_1.toDefaultApp(process.env[currentAppVar]); if (!result) { return commandline_1.ResultOrValue.fromResult(commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `'${process.env[currentAppVar]}' (read from environment ${currentAppVar}) is not a valid application id`)); } return commandline_1.ResultOrValue.fromValue(result); } } function fromProfile() { const profile = profile_1.getUser(); if (profile && profile.defaultApp) { return commandline_1.ResultOrValue.fromValue(profile.defaultApp); } } return (fromCommandLineOpt() || fromEnvironment() || fromProfile() || commandline_1.ResultOrValue.fromResult(commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `Could not find application to work on. Specify the '--app' switch, use '${misc_1.scriptName} apps set-current', or set the ${currentAppVar} environment variable.`))); } exports.getCurrentApp = getCurrentApp;