UNPKG

azure-cli

Version:

Microsoft Azure Cross Platform Command Line tool

238 lines (89 loc) 13.6 kB
/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__tryCatch=__rt.__tryCatch; var util = require("util"); var batchUtil = require("./batch.util"); var batchShowUtil = require("./batch.showUtil"); var utils = require("../../util/utils"); var startProgress = batchUtil.startProgress; var endProgress = batchUtil.endProgress; var fs = require("fs"); var url = require("url"); var storage = require("azure-storage"); var $ = utils.getLocaleString; exports.init = function(cli) { batchUtil.init(cli); var batch = cli.category("batch").description($("Commands to manage your Batch objects")); var logger = cli.output; var interaction = cli.interaction; var application = batch.category("application").description($("Commands to manage your Batch Application")); var applicationPkg = application.category("package").description($("Commands to manage your Batch Application Package")); applicationPkg.command("create [resource-group] [account-name] [application-id] [version] [package-file]").description($("Creates an application package record")).option("--account-name <account-name>", $("the name of the Batch account")).option("--application-id <application-id>", $("the id of the application")).option("--version <version>", $("the version of the application")).option("--package-file <package-file>", $("the application package in zip format")).appendSubscriptionAndResourceGroupOption().execute(addApplicationPkg); applicationPkg.command("delete [resource-group] [account-name] [application-id] [version]").description($("Deletes an application package record")).option("--account-name <account-name>", $("the name of the Batch account")).option("--application-id <application-id>", $("the id of the application")).option("--version <version>", $("the version of the application to delete")).option("-q, --quiet", $("delete the specified application package without confirmation")).appendSubscriptionAndResourceGroupOption().execute(deleteApplicationPkg); applicationPkg.command("show [resource-group] [account-name] [application-id] [version]").description($("Show details of the Batch application package")).option("--account-name <account-name>", $("the name of the Batch account")).option("--application-id <application-id>", $("the id of the application")).option("--version <version>", $("the version of the application to show")).appendSubscriptionAndResourceGroupOption().execute(showApplicationPkg); applicationPkg.command("activate [resource-group] [account-name] [application-id] [version] [format]").description($("Activate an application package")).option("--account-name <account-name>", $("the name of the Batch account")).option("--application-id <application-id>", $("the id of the application")).option("--version <version>", $("the version of the application to activate")).option("--format <format>", $("the format of the application package binary file")).appendSubscriptionAndResourceGroupOption().execute(activateApplicationPkg); function validateResourceGroupAndAccountName(resourceGroup, accountName, options, _) { var __frame = { name: "validateResourceGroupAndAccountName", line: 93 }; return __func(_, this, arguments, validateResourceGroupAndAccountName, 3, __frame, function __$validateResourceGroupAndAccountName() { if (resourceGroup) { options.resourceGroup = resourceGroup; } ; return cli.interaction.promptIfNotGiven($("Resource group name: "), options.resourceGroup, __cb(_, __frame, 4, 44, function ___(__0, __1) { options.resourceGroup = __1; if (accountName) { options.accountName = accountName; } ; return cli.interaction.promptIfNotGiven($("Account name: "), options.accountName, __cb(_, __frame, 9, 42, function ___(__0, __2) { options.accountName = __2; _(); }, true)); }, true)); }); }; function validateResourceGroupAccountApplication(resourceGroup, accountName, applicationId, options, _) { var __frame = { name: "validateResourceGroupAccountApplication", line: 105 }; return __func(_, this, arguments, validateResourceGroupAccountApplication, 4, __frame, function __$validateResourceGroupAccountApplication() { return validateResourceGroupAndAccountName(resourceGroup, accountName, options, __cb(_, __frame, 1, 4, function __$validateResourceGroupAccountApplication() { if (applicationId) { options.applicationId = applicationId; } ; return cli.interaction.promptIfNotGiven($("Application Id: "), options.applicationId, __cb(_, __frame, 6, 44, function ___(__0, __1) { options.applicationId = __1; _(); }, true)); }, true)); }); }; function validateAll(resourceGroup, accountName, applicationId, version, options, _) { var __frame = { name: "validateAll", line: 114 }; return __func(_, this, arguments, validateAll, 5, __frame, function __$validateAll() { return validateResourceGroupAccountApplication(resourceGroup, accountName, applicationId, options, __cb(_, __frame, 1, 4, function __$validateAll() { if (version) { options.version = version; } ; return cli.interaction.promptIfNotGiven($("Version: "), options.version, __cb(_, __frame, 6, 38, function ___(__0, __1) { options.version = __1; _(); }, true)); }, true)); }); }; function uploadAzureBlob(file, urlStr, _) { var uri, blobService, specifiedContainerName, specifiedBlobName, specifiedFileName, fsStatus; var __frame = { name: "uploadAzureBlob", line: 123 }; return __func(_, this, arguments, uploadAzureBlob, 2, __frame, function __$uploadAzureBlob() { uri = url.parse(urlStr); blobService = storage.createBlobServiceWithSas(uri.hostname, uri.query); specifiedContainerName = uri.pathname.split("/")[1]; specifiedBlobName = uri.pathname.slice((2 + specifiedContainerName.length)); specifiedFileName = file; return utils.fileExists(specifiedFileName, __cb(_, __frame, 8, 15, function ___(__0, __2) { var __1 = !__2; return (function __$uploadAzureBlob(__then) { if (__1) { return _(new Error(util.format($("Local file %s doesn't exist"), specifiedFileName))); } else { __then(); } ; })(function __$uploadAzureBlob() { return fs.stat(specifiedFileName, __cb(_, __frame, 11, 22, function ___(__0, __3) { fsStatus = __3; if (!fsStatus.isFile()) { return _(new Error(util.format($("%s is not a file"), specifiedFileName))); } ; return blobService.createBlockBlobFromLocalFile(specifiedContainerName, specifiedBlobName, specifiedFileName, __cb(_, __frame, 16, 16, function __$uploadAzureBlob() { _(); }, true)); }, true)); }); }, true)); }); }; function addApplicationPkg(resourcegroup, accountName, applicationId, version, packageFile, options, _) { var service, tips, response; var __frame = { name: "addApplicationPkg", line: 147 }; return __func(_, this, arguments, addApplicationPkg, 6, __frame, function __$addApplicationPkg() { service = batchUtil.createBatchManagementClient(options.subscription); return validateAll(resourcegroup, accountName, applicationId, version, options, __cb(_, __frame, 3, 4, function __$addApplicationPkg() { tips = util.format($("Adding version %s to application %s"), version, applicationId); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$addApplicationPkg() { startProgress(tips); return service.applicationPackageOperations.create(options.resourceGroup, options.accountName, options.applicationId, options.version, __cb(_, __frame, 9, 58, function ___(__0, __1) { response = __1; return uploadAzureBlob(packageFile, response.storageUrl, __cb(_, __frame, 10, 6, function __$addApplicationPkg() { _(null, null, true); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$addApplicationPkg() { endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$addApplicationPkg() { logger.verbose(util.format($("Version %s has been added to application %s successfully"), version, applicationId)); _(); }); }); }, true)); }); }; function activateApplicationPkg(resourcegroup, accountName, applicationId, version, format, options, _) { var service, tips; var __frame = { name: "activateApplicationPkg", line: 170 }; return __func(_, this, arguments, activateApplicationPkg, 6, __frame, function __$activateApplicationPkg() { service = batchUtil.createBatchManagementClient(options.subscription); return validateAll(resourcegroup, accountName, applicationId, version, options, __cb(_, __frame, 3, 4, function __$activateApplicationPkg() { if (!format) { format = options.options; } ; return cli.interaction.promptIfNotGiven($("Format: "), format, __cb(_, __frame, 7, 29, function ___(__0, __1) { format = __1; tips = util.format($("Activate application version %s"), version); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$activateApplicationPkg() { startProgress(tips); return service.applicationPackageOperations.activate(options.resourceGroup, options.accountName, options.applicationId, options.version, format, __cb(_, __frame, 13, 43, function __$activateApplicationPkg() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$activateApplicationPkg() { endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$activateApplicationPkg() { logger.verbose(util.format($("Version %s has been activated at application %s successfully"), version, applicationId)); _(); }); }); }, true)); }, true)); }); }; function deleteApplicationPkg(resourcegroup, accountName, applicationId, version, options, _) { var service, tips; var __frame = { name: "deleteApplicationPkg", line: 196 }; return __func(_, this, arguments, deleteApplicationPkg, 5, __frame, function __$deleteApplicationPkg() { service = batchUtil.createBatchManagementClient(options.subscription); return validateAll(resourcegroup, accountName, applicationId, version, options, __cb(_, __frame, 3, 4, function __$deleteApplicationPkg() { return (function __$deleteApplicationPkg(__then) { if (!options.quiet) { return interaction.confirm(util.format($("Do you want to delete application version %s? "), version), __cb(_, __frame, 6, 23, function ___(__0, __2) { var __1 = !__2; return (function __$deleteApplicationPkg(__then) { if (__1) { return _(null); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$deleteApplicationPkg() { tips = util.format($("Deleting application version %s"), version); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteApplicationPkg() { startProgress(tips); return service.applicationPackageOperations.deleteMethod(options.resourceGroup, options.accountName, options.applicationId, options.version, __cb(_, __frame, 14, 43, function __$deleteApplicationPkg() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deleteApplicationPkg() { endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$deleteApplicationPkg() { logger.verbose(util.format($("Version %s has been deleted from application %s successfully"), version, applicationId)); _(); }); }); }); }, true)); }); }; function showApplicationPkg(resourcegroup, accountName, applicationId, version, options, _) { var service, tips, application; var __frame = { name: "showApplicationPkg", line: 223 }; return __func(_, this, arguments, showApplicationPkg, 5, __frame, function __$showApplicationPkg() { service = batchUtil.createBatchManagementClient(options.subscription); return validateAll(resourcegroup, accountName, applicationId, version, options, __cb(_, __frame, 3, 4, function __$showApplicationPkg() { tips = $("Getting Batch application package information"); application = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$showApplicationPkg() { startProgress(tips); return service.applicationPackageOperations.get(options.resourceGroup, options.accountName, options.applicationId, options.version, __cb(_, __frame, 9, 57, function ___(__0, __1) { application = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$showApplicationPkg() { endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$showApplicationPkg() { batchShowUtil.showAppPackage(application, cli.output); _(); }); }); }, true)); }); };};