@oblique/cli
Version:
Command Line Interface to manage Oblique projects
55 lines (51 loc) • 2.82 kB
JavaScript
/**
* @file Oblique, The front-end framework for your Swiss branded UI.
* @copyright 2020 - 2025 Federal Office of Information Technology, Systems and Telecommunication FOITT {@link https://www.bit.admin.ch}
* @version 14.1.2 (released on 2025-12-01, supported at least until 2026-09-30)
* @author Oblique team, FOITT, BS-BSC-EN4 <oblique@bit.admin.ch>
* @license MIT {@link https://github.com/oblique-bit/oblique/blob/master/LICENSE}
* @see https://oblique.bit.admin.ch
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleAction = handleAction;
exports.getMaxCommandLength = getMaxCommandLength;
const tslib_1 = require("tslib");
const extra_typings_1 = require("@commander-js/extra-typings");
const cliPackage = tslib_1.__importStar(require("../package.json"));
const ob_new_1 = require("./new/ob-new");
const cli_utils_1 = require("./utils/cli-utils");
const ob_update_1 = require("./update/ob-update");
extra_typings_1.program
.name('ob')
.description(cliPackage.description)
.version(cliPackage.version, cli_utils_1.optionDescriptions.ob.version.flags, cli_utils_1.optionDescriptions.ob.version.description)
.helpOption(cli_utils_1.optionDescriptions.ob.help.flags, cli_utils_1.optionDescriptions.ob.help.description)
.usage((0, cli_utils_1.commandUsageText)('<command>'))
.addHelpText('beforeAll', (0, cli_utils_1.titleText)(`How to use the ${cli_utils_1.obTitle}`.toUpperCase(), ''))
.addHelpText('after', (0, cli_utils_1.createAdditionalHelpText)('\nExample usages:\n', cli_utils_1.obExamples, getMaxCommandLength(cli_utils_1.obExamples)))
.action(handleAction)
.showSuggestionAfterError(true)
.showHelpAfterError('(Add --help for additional information)');
const obNewCommandConfigured = (0, ob_new_1.createObNewCommand)();
const obUpdateCommandConfigured = (0, ob_update_1.createObUpdateCommand)();
extra_typings_1.program.addCommand(obNewCommandConfigured);
extra_typings_1.program.addCommand(obUpdateCommandConfigured);
const { commandName } = (0, cli_utils_1.parseCommandArguments)();
const availableCommands = extra_typings_1.program.commands.map(cmd => cmd.name());
if (!commandName) {
extra_typings_1.program.help();
}
if (!commandName.startsWith('-') && !availableCommands.includes(commandName)) {
console.error(`Unknown command: "${commandName}"`);
console.error('\nTo see a list of supported oblique cli commands, run:\n ob --help');
process.exit(1);
}
extra_typings_1.program.parse();
function handleAction(options) {
(0, cli_utils_1.startObCommand)(cli_utils_1.runObCommand, 'Oblique CLI completed in', options);
}
function getMaxCommandLength(examples) {
return examples.map(entry => entry.command.length).reduce((max, length) => (length > max ? length : max), 0);
}