@holographxyz/cli
Version:
Holograph operator CLI
73 lines (72 loc) • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const yaml_1 = tslib_1.__importDefault(require("yaml"));
const path = tslib_1.__importStar(require("node:path"));
const core_1 = require("@oclif/core");
const config_1 = require("../../utils/config");
const utils_1 = require("../../utils/utils");
const output_format_1 = require("../../utils/output-format");
class ConfigView extends core_1.Command {
static description = 'View the current config state of the Holograph CLI.';
static examples = [
'$ <%= config.bin %> <%= command.id %>',
'$ <%= config.bin %> <%= command.id %> --output json',
'$ <%= config.bin %> <%= command.id %> --output yaml',
'$ <%= config.bin %> <%= command.id %> --output clean',
];
static flags = {
output: core_1.Flags.string({
description: 'Output format',
options: output_format_1.supportedFormats,
}),
};
yaml;
configJson;
configPath;
/**
* Command Entry Point
*/
async run() {
const { flags } = await this.parse(ConfigView);
await this.setup();
switch (flags.output) {
case 'json':
this.log(JSON.stringify(this.config, null, 2));
break;
case 'yaml':
this.yaml.contents = this.config;
this.log(this.yaml.toString());
break;
case 'clean':
default:
this.serializeClean(this.configJson, '');
break;
}
this.exit();
}
async setup() {
this.configPath = path.join(this.config.configDir, config_1.CONFIG_FILE_NAME);
await (0, config_1.ensureConfigFileIsValid)(this.configPath, undefined, false);
this.config = await (0, config_1.readConfig)(this.configPath);
if (!this.config) {
this.error('No config file found');
}
this.debug(`Configuration path ${this.configPath}`);
this.yaml = new yaml_1.default.Document();
this.configJson = JSON.parse(JSON.stringify(this.config));
}
serializeClean(obj, tabCursor) {
for (const key of Object.keys(obj)) {
if (typeof obj[key] === 'object') {
tabCursor = ' ';
this.log(`${(0, utils_1.capitalize)(key)}:`);
this.serializeClean(obj[key], tabCursor);
}
else {
this.log(`${tabCursor}${(0, utils_1.capitalize)(key)}: ${obj[key]}`);
}
}
}
}
exports.default = ConfigView;