UNPKG

@sap/cli-core

Version:

Command-Line Interface (CLI) Core Module

69 lines (68 loc) 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addCommands = void 0; const config_1 = require("../../config"); const constants_1 = require("../../constants"); const logger_1 = require("../../logger"); const settings_1 = require("../../settings"); const commands_1 = require("../../utils/commands"); const utils_1 = require("../../utils/utils"); const handler_1 = require("../handler"); const getLogger = () => (0, logger_1.get)("commands.host"); const set = async () => async () => { const config = (0, config_1.get)(); try { // throws if host is not valid (0, utils_1.getInfoFromTenant)(config.arguments.host, config.verbose, false); await (0, settings_1.set)(constants_1.OPTION_HOST.longName, config.arguments.host); } catch (err) { const { debug, output } = getLogger(); debug("failed to set host", err); output(`error: invalid value '${config.arguments.host}' for argument '<host>'`); throw new Error("failed to set host"); } }; const show = async () => async () => { const { output } = getLogger(); const settings = await (0, settings_1.get)(); if (settings[constants_1.OPTION_HOST.longName]) { output(settings[constants_1.OPTION_HOST.longName]); } else { output(`no global host set. use ${(0, utils_1.getBin)()} config host set <host> to set a global host`); throw new Error("no global host set"); } }; const clean = async () => async () => { await (0, settings_1.remove)(constants_1.OPTION_HOST.longName); }; const addCommands = async (program) => { await (0, commands_1.buildCommand)(program, { type: "topCommand", command: "host", description: "configure host properties", subCommands: [ { type: "command", command: "set", description: "set global host", args: [{ argument: "host", description: "global host" }], handler: (0, handler_1.createNextHandler)("command.config.host.set", (0, handler_1.createParseArgumentsHandler)([{ argument: "host" }]), set), }, { type: "command", command: "show", description: "show global host", handler: show, }, { type: "command", command: "clean", description: "clean global host", handler: clean, }, ], }); }; exports.addCommands = addCommands;