UNPKG

@adpt/cli

Version:
76 lines 3.17 kB
"use strict"; /* * Copyright 2020 Unbounded Systems, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("@adpt/utils"); const command_1 = require("@oclif/command"); const cli_ux_1 = require("cli-ux"); const base_1 = require("../../base"); const config_1 = require("../../config"); const load_1 = require("../../config/load"); // Table lines are made up of: // - Optional bold start and bold end // - Optional trailing whitespace (before the bold end) // - Possibly empty text const printLineRe = /^(\u001b\[1m)?(.*?) *(\u001b\[22m)?$/; // Function used to replace the default cli.table printLine // This fixes two warts with cli.table: // - Table lines always have trailing spaces // - Header text always contains ANSI bold sequences, even for non-tty output function printLine(line) { const m = printLineRe.exec(line); if (!m) { throw new utils_1.InternalError(`Output line should have matched regular expression (line=${line})`); } line = process.stdout.isTTY ? (m[1] || "") + m[2] + (m[3] || "") : m[2]; process.stdout.write(line + "\n"); } class ConfigListCommand extends base_1.AdaptBase { async run() { const f = this.parse(ConfigListCommand).flags; const { userConfigFile } = await config_1.config(); const items = (await load_1.loadUserConfig(userConfigFile)).details; const data = Object.entries(items) .filter(hasDetails) .filter(([_name, item]) => f.all || item.sourceType !== "Default") .filter(([_name, item]) => item.valid) .map(([name, item]) => ({ name, source: item.sourceType === "File" ? item.source : item.sourceType, value: item.store, })); const cols = { name: {}, value: {}, }; if (f.source) cols.source = {}; // tslint:disable-next-line: no-console cli_ux_1.cli.table(data, cols, Object.assign({}, f, { printLine, "no-header": f.quiet })); } } ConfigListCommand.description = "Shows Adapt configuration settings"; ConfigListCommand.flags = Object.assign({ all: command_1.flags.boolean({ description: "Show all configuration items, including defaults", }), source: command_1.flags.boolean({ description: "Show the source of each configuration item's value", }) }, cli_ux_1.cli.table.flags({ only: ["no-truncate"] }), base_1.AdaptBase.flags); exports.default = ConfigListCommand; function hasDetails(entry) { return entry[1] != null; } //# sourceMappingURL=list.js.map