usage.ts ×19

Frontier kind: Code frontier

unlabeled · c_7861ea091a3e

417 tests · 2190 LOC · 18 files · introduces 0 tests · 125 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
20 ranges125 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
398 ranges2190 lines · 18 files · Browse complete extent
All tests (intent)
417 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 125 introduced LOC across 20 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

lib/usage.ts 122 introduced LOC · 19 ranges

Open complete file

168 return null;
169 }
170 > if (!wrapSet) { usage.ts
171 wrap = windowWidth();
172 wrapSet = true;
173 }
174 > usage.ts
175 > return wrap;
176 };
177
180
181 self.help = function help() {
182 > if (cachedHelpMessage) return cachedHelpMessage; usage.ts
183 > normalizeAliases();
184 >
185 > // handle old demanded API
186 > const base$0 = yargs.customScriptName
187 > ? yargs.$0
188 > : shim.path.basename(yargs.$0);
189 > const demandedOptions = yargs.getDemandedOptions();
190 > const demandedCommands = yargs.getDemandedCommands();
191 > const deprecatedOptions = yargs.getDeprecatedOptions();
192 > const groups = yargs.getGroups();
193 > const options = yargs.getOptions();
194 >
195 > let keys: string[] = [];
196 > keys = keys.concat(Object.keys(descriptions));
197 > keys = keys.concat(Object.keys(demandedOptions));
198 > keys = keys.concat(Object.keys(demandedCommands));
199 > keys = keys.concat(Object.keys(options.default));
200 > keys = keys.filter(filterHiddenOptions);
201 > keys = Object.keys(
202 > keys.reduce((acc, key) => {
203 > if (key !== '_') acc[key] = true;
204 > return acc;
205 > }, {} as Dictionary<boolean>)
206 > );
207 >
208 > const theWrap = self.getWrap();
209 > const ui = shim.cliui({
210 > width: theWrap,
211 > wrap: !!theWrap,
212 > });
213 >
214 > // the usage string.
215 > if (!usageDisabled) {
216 if (usages.length) {
217 // user-defined usage.
234 }
235 }
236 > usage.ts
237 > // your application's commands, i.e., non-option
238 > // arguments populated in '_'.
239 > //
240 > // If there's only a single command, and it's the default command
241 > // (represented by commands[0][2]) don't show command stanza:
242 > //
243 > // TODO(@bcoe): why isn't commands[0][2] an object with a named property?
244 > if (commands.length > 1 || (commands.length === 1 && !commands[0][2])) {
245 ui.div(__('Commands:'));
246
298 ui.div();
299 }
300 > usage.ts
301 > // perform some cleanup on the keys array, making it
302 > // only include top-level keys not their aliases.
303 > const aliasKeys = (Object.keys(options.alias) || []).concat(
304 > Object.keys((yargs.parsed as DetailedArguments).newAliases) || []
305 > );
306 >
307 > keys = keys.filter(
308 > key =>
309 !(yargs.parsed as DetailedArguments).newAliases[key] &&
310 aliasKeys.every(
311 alias => (options.alias[alias] || []).indexOf(key) === -1
312 > ) usage.ts
313 > );
314 >
315 > // populate 'Options:' group with any keys that have not
316 > // explicitly had a group set.
317 > const defaultGroup = __('Options:');
318 > if (!groups[defaultGroup]) groups[defaultGroup] = [];
319 > addUngroupedKeys(keys, options.alias, groups, defaultGroup);
320 >
321 > const isLongSwitch = (sw: string | IndentedText) => /^--/.test(getText(sw));
322 >
323 > // prepare 'Options:' tables display
324 > const displayedGroups = Object.keys(groups)
325 > .filter(groupName => groups[groupName].length > 0)
326 > .map(groupName => {
327 // if we've grouped the key 'f', but 'f' aliases 'foobar',
328 // normalizedKeys should contain only 'foobar'.
343
344 return {groupName, normalizedKeys};
345 > }) usage.ts
346 > .filter(({normalizedKeys}) => normalizedKeys.length > 0)
347 > .map(({groupName, normalizedKeys}) => {
348 // actually generate the switches string --foo, -f, --bar.
349 const switches: Dictionary<string | IndentedText> =
383
384 return {groupName, normalizedKeys, switches};
385 > }); usage.ts
386 >
387 > // if some options use short switches, indent long-switches only options (see #1403)
388 > const shortSwitchesUsed = displayedGroups
389 > .filter(({groupName}) => groupName !== self.getPositionalGroupName())
390 > .some(
391 > ({normalizedKeys, switches}) =>
392 !normalizedKeys.every(key => isLongSwitch(switches[key]))
393 > ); usage.ts
394 >
395 > if (shortSwitchesUsed) {
396 displayedGroups
397 .filter(({groupName}) => groupName !== self.getPositionalGroupName())
404 });
405 }
406 > usage.ts
407 > // display 'Options:' table along with any custom tables:
408 > displayedGroups.forEach(({groupName, normalizedKeys, switches}) => {
409 ui.div(groupName);
410
464
465 ui.div();
466 > }); usage.ts
467 >
468 > // describe some common use-cases for your application.
469 > if (examples.length) {
470 ui.div(__('Examples:'));
471
496 ui.div();
497 }
498 > usage.ts
499 > // the usage string.
500 > if (epilogs.length > 0) {
501 const e = epilogs
502 .map(epilog => epilog.replace(/\$0/g, base$0))
504 ui.div(`${e}\n`);
505 }
506 > usage.ts
507 > // Remove the trailing white spaces
508 > return ui.toString().replace(/\s*$/, '');
509 };
510
547 // are copied to the keys being aliased.
548 function normalizeAliases() {
549 > // handle old demanded API usage.ts
550 > const demandedOptions = yargs.getDemandedOptions();
551 > const options = yargs.getOptions();
552 >
553 > (Object.keys(options.alias) || []).forEach(key => {
554 options.alias[key].forEach(alias => {
555 // copy descriptions.
566 if (options.number.includes(alias)) yargs.number(key);
567 });
568 > }); usage.ts
569 > }
570
571 // if yargs is executing an async handler, we take a snapshot of the
589 // ungrouped under the 'Options:' grouping.
590 function addUngroupedKeys(
591 > keys: string[], usage.ts
592 > aliases: Dictionary<string[]>,
593 > groups: Dictionary<string[]>,
594 > defaultGroup: string
595 > ) {
596 > let groupedKeys = [] as string[];
597 > let toCheck = null;
598 > Object.keys(groups).forEach(group => {
599 > groupedKeys = groupedKeys.concat(groups[group]);
600 > });
601 >
602 > keys.forEach(key => {
603 toCheck = [key].concat(aliases[key]);
604 if (!toCheck.some(k => groupedKeys.indexOf(k) !== -1)) {
605 groups[defaultGroup].push(key);
606 }
607 > }); usage.ts
608 > return groupedKeys;
609 > }
610
611 function filterHiddenOptions(key: string) {
612 > return ( usage.ts
613 > yargs.getOptions().hiddenOptions.indexOf(key) < 0 ||
614 (yargs.parsed as DetailedArguments).argv[yargs.getOptions().showHiddenOpt]
615 > ); usage.ts
616 > }
617
618 self.showHelp = (level: 'error' | 'log' | ((message: string) => void)) => {
lib/yargs-factory.ts 3 introduced LOC · 1 range

Open complete file

779 }
780 getDeprecatedOptions() {
781 > argsert([], 0); yargs-factory.ts
782 > return this.#options.deprecatedOptions;
783 > }
784 getDetectLocale(): boolean {
785 return this.#detectLocale;