Rename columns to helpWidth (#1396)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by John Gee · committed by GitHub · parent 4555881 · Browse files · 6 files·+58 added−58 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+58 added−58 removed
- tests:+37 added−37 removed
- other:+21 added−21 removed
Provenance
- Commit
eac4787- Tree
f766b91- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
4555881
6 files changed+58 added−58 removed
modified:tests/command.configureOutput.test.js+32 added-32 removed
105 unmodified lines106 expect(customWrite).toHaveBeenCalledTimes(1);107 writeSpy.mockRestore();108 });109 110-test('when default getOutColumns then help columns from stdout', () => {110+test('when default getOutHelpWidth then help helpWidth from stdout', () => {111 const expectedColumns = 123;112 const holdIsTTY = process.stdout.isTTY;113 const holdColumns = process.stdout.columns;114- let helpColumns;114+ let helpWidth;115 116 process.stderr.isTTY = true;117 process.stdout.columns = expectedColumns;118 process.stdout.isTTY = true;119 const program = new commander.Command();120 program121 .configureHelp({122 formatHelp: (cmd, helper) => {123- helpColumns = helper.columns;123+ helpWidth = helper.helpWidth;124 return '';125 }126 });127 program.outputHelp();128 129- expect(helpColumns).toBe(expectedColumns);129+ expect(helpWidth).toBe(expectedColumns);130 process.stdout.columns = holdColumns;131 process.stdout.isTTY = holdIsTTY;132 });133 134-test('when custom getOutColumns then help columns custom', () => {134+test('when custom getOutHelpWidth then help helpWidth custom', () => {135 const expectedColumns = 123;136- let helpColumns;136+ let helpWidth;137 138 const program = new commander.Command();139 program140 .configureHelp({141 formatHelp: (cmd, helper) => {142- helpColumns = helper.columns;142+ helpWidth = helper.helpWidth;143 return '';144 }145 }).configureOutput({146- getOutColumns: () => expectedColumns146+ getOutHelpWidth: () => expectedColumns147 });148 program.outputHelp();149 150- expect(helpColumns).toBe(expectedColumns);150+ expect(helpWidth).toBe(expectedColumns);151 });152 153-test('when default getErrColumns then help error columns from stderr', () => {153+test('when default getErrHelpWidth then help error helpWidth from stderr', () => {154 const expectedColumns = 123;155 const holdIsTTY = process.stderr.isTTY;156 const holdColumns = process.stderr.columns;157- let helpColumns;157+ let helpWidth;158 159 process.stderr.isTTY = true;160 process.stderr.columns = expectedColumns;161 const program = new commander.Command();162 program163 .configureHelp({164 formatHelp: (cmd, helper) => {165- helpColumns = helper.columns;165+ helpWidth = helper.helpWidth;166 return '';167 }168 });169 program.outputHelp({ error: true });170 171- expect(helpColumns).toBe(expectedColumns);171+ expect(helpWidth).toBe(expectedColumns);172 process.stderr.isTTY = holdIsTTY;173 process.stderr.columns = holdColumns;174 });175 176-test('when custom getErrColumns then help error columns custom', () => {176+test('when custom getErrHelpWidth then help error helpWidth custom', () => {177 const expectedColumns = 123;178- let helpColumns;178+ let helpWidth;179 180 const program = new commander.Command();181 program182 .configureHelp({183 formatHelp: (cmd, helper) => {184- helpColumns = helper.columns;184+ helpWidth = helper.helpWidth;185 return '';186 }187 }).configureOutput({188- getErrColumns: () => expectedColumns188+ getErrHelpWidth: () => expectedColumns189 });190 program.outputHelp({ error: true });191 192- expect(helpColumns).toBe(expectedColumns);192+ expect(helpWidth).toBe(expectedColumns);193 });194 195-test('when custom getOutColumns and configureHelp:columns then help columns from configureHelp', () => {195+test('when custom getOutHelpWidth and configureHelp:helpWidth then help helpWidth from configureHelp', () => {196 const expectedColumns = 123;197- let helpColumns;197+ let helpWidth;198 199 const program = new commander.Command();200 program201 .configureHelp({202 formatHelp: (cmd, helper) => {203- helpColumns = helper.columns;203+ helpWidth = helper.helpWidth;204 return '';205 },206- columns: expectedColumns206+ helpWidth: expectedColumns207 }).configureOutput({208- getOutColumns: () => 999208+ getOutHelpWidth: () => 999209 });210 program.outputHelp();211 212- expect(helpColumns).toBe(expectedColumns);212+ expect(helpWidth).toBe(expectedColumns);213 });214 215-test('when custom getErrColumns and configureHelp:columns then help error columns from configureHelp', () => {215+test('when custom getErrHelpWidth and configureHelp:helpWidth then help error helpWidth from configureHelp', () => {216 const expectedColumns = 123;217- let helpColumns;217+ let helpWidth;218 219 const program = new commander.Command();220 program221 .configureHelp({222 formatHelp: (cmd, helper) => {223- helpColumns = helper.columns;223+ helpWidth = helper.helpWidth;224 return '';225 },226- columns: expectedColumns226+ helpWidth: expectedColumns227 }).configureOutput({228- getErrColumns: () => 999228+ getErrHelpWidth: () => 999229 });230 program.outputHelp({ error: true });231 232- expect(helpColumns).toBe(expectedColumns);232+ expect(helpWidth).toBe(expectedColumns);233 });234 235 test('when set configureOutput then get configureOutput', () => {236 const outputOptions = {237 writeOut: jest.fn(),238 writeErr: jest.fn(),239- getOutColumns: jest.fn(),240- getErrColumns: jest.fn(),239+ getOutHelpWidth: jest.fn(),240+ getErrHelpWidth: jest.fn(),241 outputError: jest.fn()242 };243 const program = new commander.Command();244 program.configureOutput(outputOptions);31 unmodified linesmodified:tests/help.wrap.test.js+5 added-5 removed
54 unmodified lines5556575859596061626310 unmodified lines747576777878798081829 unmodified lines92939495969697989910016 unmodified lines11711811912012112112212312412513 unmodified lines13914014114214314314414514614717 unmodified lines54 unmodified lines
test('when long option description then wrap and indent', () => { const program = new commander.Command(); program .configureHelp({ columns: 80 }) .configureHelp({ helpWidth: 80 }) .option('-x --extra-long-option-switch', 'kjsahdkajshkahd kajhsd akhds kashd kajhs dkha dkh aksd ka dkha kdh kasd ka kahs dkh sdkh askdh aksd kashdk ahsd kahs dkha skdh');
const expectedOutput =`Usage: [options]10 unmodified lines
test('when long option description and default then wrap and indent', () => { const program = new commander.Command(); program .configureHelp({ columns: 80 }) .configureHelp({ helpWidth: 80 }) .option('-x --extra-long-option <value>', 'kjsahdkajshkahd kajhsd akhds', 'aaa bbb ccc ddd eee fff ggg');
const expectedOutput =`Usage: [options]9 unmodified lines
test('when long command description then wrap and indent', () => { const program = new commander.Command(); program .configureHelp({ columns: 80 }) .configureHelp({ helpWidth: 80 }) .option('-x --extra-long-option-switch', 'x') .command('alpha', 'Lorem mollit quis dolor ex do eu quis ad insa a commodo esse.');
const expectedOutput =16 unmodified lines // Not wrapping if less than 40 columns available for wrapping. const program = new commander.Command(); const commandDescription = 'description text of very long command which should not be automatically be wrapped. Do fugiat eiusmod ipsum laboris excepteur pariatur sint ullamco tempor labore eu.'; program .configureHelp({ columns: 60 }) .configureHelp({ helpWidth: 60 }) .command('1234567801234567890x', commandDescription);
const expectedOutput =`Usage: [options] [command]13 unmodified lines // #396: leave custom format alone, apart from space-space indent const optionSpec = '-t, --time <HH:MM>'; const program = new commander.Command(); program .configureHelp({ columns: 80 }) .configureHelp({ helpWidth: 80 }) .option(optionSpec, `select time
Time can also be specified using special values: "dawn" - From night to sunrise.17 unmodified linesmodified:typings/commander-tests.ts+3 added-3 removed
268 unmodified lines269 270 program.configureOutput({271 writeOut: (str: string) => { },272 writeErr: (str: string) => { },273- getOutColumns: () => 80,274- getErrColumns: () => 80,273+ getOutHelpWidth: () => 80,274+ getErrHelpWidth: () => 80,275 outputError: (str: string, write: (str: string) => void) => { }276 });277 278 // Help279 const helper = new commander.Help();280 const helperCommand = new commander.Command();281 const helperOption = new commander.Option('-a, --all');282 283-helper.columns = 3;283+helper.helpWidth = 3;284 helper.sortSubcommands = true;285 helper.sortOptions = false;286 287 const subcommandTermStr: string = helper.subcommandTerm(helperCommand);53 unmodified linesmodified:typings/index.d.ts+7 added-7 removed
74 unmodified lines75 }76 type OptionConstructor = new (flags: string, description?: string) => Option;77 78 interface Help {79- /** output columns, long lines are wrapped to fit */80- columns?: number;79+ /** output helpWidth, long lines are wrapped to fit */80+ helpWidth?: number;81 sortSubcommands: boolean;82 sortOptions: boolean;83 84 /** Get the command term to show in the list of subcommands. */50 unmodified lines135 }136 interface OutputConfiguration {137 writeOut?(str: string): void;138 writeErr?(str: string): void;139- getOutColumns?(): number;140- getErrColumns?(): number;139+ getOutHelpWidth?(): number;140+ getErrHelpWidth?(): number;141 outputError?(str: string, write: (str: string) => void): void;142 143 }144 119 unmodified lines264 *265 * // functions to change where being written, stdout and stderr266 * writeOut(str)267 * writeErr(str)268- * // matching functions to specify columns for wrapping help269- * getOutColumns()270- * getErrColumns()268+ * // matching functions to specify width for wrapping help269+ * getOutHelpWidth()270+ * getErrHelpWidth()271 * // functions based on what is being written out272 * outputError(str, write) // used for displaying errors, and not used for displaying help273 */274 configureOutput(configuration: OutputConfiguration): this;314 unmodified linesmodified:index.js+10 added-10 removed
10 unmodified lines11 12 // Although this is a class, methods are static in style to allow override using subclass or just functions.13 class Help {14 constructor() {15- this.columns = undefined;15+ this.helpWidth = undefined;16 this.sortSubcommands = false;17 this.sortOptions = false;18 }19 222 unmodified lines242 */243 244 formatHelp(cmd, helper) {245 const termWidth = helper.padWidth(cmd, helper);246- const columns = helper.columns || 80;246+ const helpWidth = helper.helpWidth || 80;247 const itemIndentWidth = 2;248 const itemSeparatorWidth = 2; // between term and description249 function formatItem(term, description) {250 if (description) {251 const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;252- return helper.wrap(fullText, columns - itemIndentWidth, termWidth + itemSeparatorWidth);252+ return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);253 }254 return term;255 };256 function formatList(textArray) {292 unmodified lines549 // see .configureOutput() for docs550 this._outputConfiguration = {551 writeOut: (str) => process.stdout.write(str),552 writeErr: (str) => process.stderr.write(str),553- getOutColumns: () => process.stdout.isTTY ? process.stdout.columns : undefined,554- getErrColumns: () => process.stderr.isTTY ? process.stderr.columns : undefined,553+ getOutHelpWidth: () => process.stdout.isTTY ? process.stdout.columns : undefined,554+ getErrHelpWidth: () => process.stderr.isTTY ? process.stderr.columns : undefined,555 outputError: (str, write) => write(str)556 };557 558 this._hidden = false;124 unmodified lines683 *684 * // functions to change where being written, stdout and stderr685 * writeOut(str)686 * writeErr(str)687- * // matching functions to specify columns for wrapping help688- * getOutColumns()689- * getErrColumns()687+ * // matching functions to specify width for wrapping help688+ * getOutHelpWidth()689+ * getErrHelpWidth()690 * // functions based on what is being written out691 * outputError(str, write) // used for displaying errors, and not used for displaying help692 *693 * @param {Object} [configuration] - configuration options1194 unmodified lines1888 */1889 1890 helpInformation(contextOptions) {1891 const helper = this.createHelp();1892- if (helper.columns === undefined) {1893- helper.columns = (contextOptions && contextOptions.error) ? this._outputConfiguration.getErrColumns() : this._outputConfiguration.getOutColumns();1892+ if (helper.helpWidth === undefined) {1893+ helper.helpWidth = (contextOptions && contextOptions.error) ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();1894 }1895 return helper.formatHelp(this, helper);1896 };1897 265 unmodified linesmodified:Readme.md+1 added-1 removed
630 unmodified lines631 You can configure the Help behaviour by modifying data properties and methods using `.configureHelp()`, or by subclassing using `.createHelp()` if you prefer.632 633 The data properties are:634 635-- `columns`: specify the wrap width, useful for unit tests635+- `helpWidth`: specify the wrap width, useful for unit tests636 - `sortSubcommands`: sort the subcommands alphabetically637 - `sortOptions`: sort the options alphabetically638 639 There are methods getting the visible lists of arguments, options, and subcommands. There are methods for formatting the items in the lists, with each item having a _term_ and _description_. Take a look at `.formatHelp()` to see how they are used.235 unmodified lines