color-help.mjs
This file
Path
examples/color-help.mjs
41 lines · 1.2 KiB · JavaScript
Last changed by
Split styleItemDescription into option/subcommand/argument (#2283)John Geebefore adoption437e4e3
History of this fileTake it
Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947
lines 1–11why, one step back1import { styleText } from 'node:util'; // from node v20.12.02import { Command } from 'commander';34// Customise colours and styles for help output.56const program = new Command();78program.configureHelp({9 styleTitle: (str) => styleText('bold', str),10 styleCommandText: (str) => styleText('cyan', str),11 styleCommandDescription: (str) => styleText('magenta', str),Split styleItemDescription into option/subcommand/argument (#2283)John Geebefore adoption437e4e3
line 12why, one step back12 styleDescriptionText: (str) => styleText('italic', str),Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947
lines 13–41why, one step back13 styleOptionText: (str) => styleText('green', str),14 styleArgumentText: (str) => styleText('yellow', str),15 styleSubcommandText: (str) => styleText('blue', str),16});1718program.description('program description '.repeat(10));19program20 .option('-s', 'short description')21 .option('--long <number>', 'long description '.repeat(10));2223program.addHelpText(24 'after',25 styleText('italic', '\nThis is additional help text.'),26);2728program.command('esses').description('sssss '.repeat(33));2930program31 .command('print')32 .description('print files')33 .argument('<files...>', 'files to queue for printing')34 .option('--double-sided', 'print on both sides');3536program.parse();3738// Try the following:39// node color-help.mjs --help40// NO_COLOR=1 node color-help.mjs --help41// node color-help.mjs help print