@gmb/bitmark-cli
Version:
Bitmark command line interface
112 lines • 4.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const bitmark_parser_generator_1 = require("@gmb/bitmark-parser-generator");
const superenum_1 = require("@ncoderz/superenum");
const core_1 = require("@oclif/core");
const fs = tslib_1.__importStar(require("fs-extra"));
const path = tslib_1.__importStar(require("path"));
const bitmarkTool = new bitmark_parser_generator_1.BitmarkParserGenerator();
/**
* Info command
*/
// eslint-disable-next-line arca/no-default-export
class Convert extends core_1.Command {
async run() {
var _a, _b;
const { args, flags } = await this.parse(Convert);
const { info } = args;
const { output, format, append, pretty, indent, bit, all, deprecated } = flags;
const prettify = pretty ? Math.max(0, indent !== null && indent !== void 0 ? indent : 2) : undefined;
const outputFormat = (_a = (0, superenum_1.Enum)(bitmark_parser_generator_1.InfoFormat).fromValue(format)) !== null && _a !== void 0 ? _a : bitmark_parser_generator_1.InfoFormat.text;
let type = (_b = (0, superenum_1.Enum)(bitmark_parser_generator_1.InfoType).fromValue(info)) !== null && _b !== void 0 ? _b : bitmark_parser_generator_1.InfoType.list;
if (type === bitmark_parser_generator_1.InfoType.list) {
if (all)
type = bitmark_parser_generator_1.InfoType.all;
else if (deprecated)
type = bitmark_parser_generator_1.InfoType.deprecated;
}
const res = bitmarkTool.info({
type,
bit,
outputFormat,
prettify,
});
if (output) {
// Write JSON to file
const flag = append ? 'a' : 'w';
fs.ensureDirSync(path.dirname(output));
fs.writeFileSync(output, res, {
flag,
});
}
else {
console.log(res);
}
}
}
Convert.description = 'Display information about bitmark';
Convert.examples = [
'<%= config.bin %> <%= command.id %>',
'<%= config.bin %> <%= command.id %> --all',
'<%= config.bin %> <%= command.id %> list --deprecated',
'<%= config.bin %> <%= command.id %> bit --bit=cloze',
'<%= config.bin %> <%= command.id %> -f json -p bit --bit=still-image-film',
];
Convert.flags = {
// General
format: core_1.Flags.string({
char: 'f',
description: `output format. If not specified, the ouput will be text`,
// helpValue: 'FORMAT',
options: ['text', 'json'],
default: 'text',
}),
bit: core_1.Flags.string({
description: 'bit to filter. If not specified, all bits will be returned',
required: false,
exclusive: ['all', 'deprecated'],
}),
deprecated: core_1.Flags.boolean({
description: 'output deprecated bits',
}),
all: core_1.Flags.boolean({
description: 'output all bits including deprecated',
exclusive: ['deprecated'],
}),
// JSON formatting
pretty: core_1.Flags.boolean({
helpGroup: 'JSON Formatting',
char: 'p',
description: 'prettify the JSON output with indent',
}),
indent: core_1.Flags.integer({
helpGroup: 'JSON Formatting',
description: 'prettify indent (default:2)',
helpValue: 'INDENT',
dependsOn: ['pretty'],
}),
// File output
output: core_1.Flags.file({
helpGroup: 'File output',
char: 'o',
description: 'output file. If not specified, output will be to <stdout>',
helpValue: 'FILE',
}),
append: core_1.Flags.boolean({
helpGroup: 'File output',
char: 'a',
description: 'append to the output file (default is to overwrite)',
dependsOn: ['output'],
}),
};
Convert.args = {
info: core_1.Args.string({
description: 'information to return. If not specified, a list of bits will be returned',
required: false,
options: ['list', 'bit'],
default: 'list',
}),
};
exports.default = Convert;
//# sourceMappingURL=info.js.map