UNPKG

zcatalyst-cli

Version:

Command Line Tool for CATALYST

66 lines (65 loc) 3.33 kB
"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = __importDefault(require("../../internal/command")); const endpoints_1 = require("../../endpoints"); const scopes_js_1 = __importDefault(require("../../authentication/constants/scopes.js")); const index_js_1 = __importDefault(require("../../error/index.js")); const ansi_colors_1 = require("ansi-colors"); const prompt_1 = __importDefault(require("../../prompt")); const common_1 = require("../../fn-utils/lib/common"); exports.default = new command_1.default('functions:config [function_name_or_id]') .description('Perform advanced configurations such as memory allocation on a function in your project') .option('--memory <value>', 'use this option to configure the memory for the function. ex: --memory 128') .needs('auth', [scopes_js_1.default.functions]) .needs('config') .needs('rc') .action((targetFn) => __awaiter(void 0, void 0, void 0, function* () { const fnApi = yield (0, endpoints_1.functionsAPI)(); const allRemoteFn = (yield fnApi.getAllFunctions()); if (allRemoteFn.length === 0) { throw new index_js_1.default('No Functions present in the Catalyst remote console', { exit: 0, errorId: 'CONF-1' }); } let remoteTarget = undefined; if (targetFn === undefined) { const fnChoices = allRemoteFn.map((remoteFn) => prompt_1.default.choice(`${(0, ansi_colors_1.bold)(remoteFn.name)} -- ${remoteFn.id}`, { value: remoteFn, short: remoteFn.name })); const fnPrompt = yield prompt_1.default.ask(prompt_1.default.question('function', 'Please select any one of the functions to proceed:', { type: 'list', choices: fnChoices })); remoteTarget = fnPrompt.function; } else { remoteTarget = parseInt(targetFn, 10) ? allRemoteFn.find((fn) => fn.id + '' === targetFn) : allRemoteFn.find((fn) => fn.name === targetFn); if (remoteTarget === undefined) { throw new index_js_1.default('function not present in remote console', { exit: 1, errorId: 'CONF-2', arg: [ (0, ansi_colors_1.bold)(targetFn), (0, ansi_colors_1.bold)(allRemoteFn.map((fn) => `* ${fn.name} (${fn.id})`).join('\n')) ] }); } } return (0, common_1.updateFnConfig)(remoteTarget); }));