Skip to content
Myr

Add extended conflicts example (#1700)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add extended conflicts example * Trim trailing whitespace

authored by John Gee · committed by GitHub · parent b5d2bb1 · Browse files · 5 files+90 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+90 added−6 removed

  • other:+90 added−6 removed

5 files+90 added−6 removed

added:examples/options-conflicts.js+71 added
modified:examples/options-extra.js+3 added-2 removed
modified:lib/option.js+6 added-1 removed
66 unmodified lines
67 return this;68 }6970 /**71 * Set options name(s) that conflict with this option.71 * Add option name(s) that conflict with this option.72 * An error will be displayed if conflicting options are found during parsing.73 *74 * @example75 * new Option('--rgb').conflicts('cmyk');76 * new Option('--js').conflicts(['ts', 'jsx']);77 *78 * @param {string | string[]} names79 * @return {Option}80 */81
180 unmodified lines
modified:typings/index.d.ts+8 added-1 removed
117 unmodified lines
118 */119 preset(arg: unknown): this;120121 /**122 * Set options name(s) that conflict with this option.122 * Add option name(s) that conflict with this option.123 * An error will be displayed if conflicting options are found during parsing.124 *125 * @example126 * ```ts127 * new Option('--rgb').conflicts('cmyk');128 * new Option('--js').conflicts(['ts', 'jsx']);129 * ```130 */131 conflicts(names: string | string[]): this;132133 /**
722 unmodified lines
modified:Readme.md+2 added-2 removed
387 unmodified lines
388389You can add most options using the `.option()` method, but there are some additional features available390by constructing an `Option` explicitly for less common cases.391392Example files: [options-extra.js](./examples/options-extra.js), [options-env.js](./examples/options-env.js)392Example files: [options-extra.js](./examples/options-extra.js), [options-env.js](./examples/options-env.js), [options-conflicts.js](./examples/options-conflicts.js)393394```js395program396 .addOption(new Option('-s, --secret').hideHelp())397 .addOption(new Option('-t, --timeout <delay>', 'timeout in seconds').default(60, 'one minute'))398 .addOption(new Option('-d, --drink <size>', 'drink size').choices(['small', 'medium', 'large']))399 .addOption(new Option('-p, --port <number>', 'port number').env('PORT'))400 .addOption(new Option('--donate [amount]', 'optional donation in dollars').preset('20').argParser(parseFloat))401 .addOption(new Option('--disable-server', 'disables the server').conflicts(['port'])); // or `.conflicts('port')` for a single conflict401 .addOption(new Option('--disable-server', 'disables the server').conflicts('port'));402```403404```bash405$ extra --help
676 unmodified lines