usage.ts ×17

Frontier kind: Code frontier

unlabeled · c_d9ff668ce363

416 tests · 2342 LOC · 18 files · introduces 0 tests · 142 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
18 ranges142 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
419 ranges2342 lines · 18 files · Browse complete extent
All tests (intent)
416 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: 142 introduced LOC across 18 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

lib/usage.ts 140 introduced LOC · 17 ranges

Open complete file

307 keys = keys.filter(
308 key =>
309 > !(yargs.parsed as DetailedArguments).newAliases[key] && usage.ts
310 > aliasKeys.every(
311 > alias => (options.alias[alias] || []).indexOf(key) === -1
312 )
313 );
325 .filter(groupName => groups[groupName].length > 0)
326 .map(groupName => {
327 > // if we've grouped the key 'f', but 'f' aliases 'foobar', usage.ts
328 > // normalizedKeys should contain only 'foobar'.
329 > const normalizedKeys: string[] = groups[groupName]
330 > .filter(filterHiddenOptions)
331 > .map(key => {
332 > if (aliasKeys.includes(key)) return key;
333 for (
334 let i = 0, aliasKey;
340 }
341 return key;
342 > }); usage.ts
343 >
344 > return {groupName, normalizedKeys};
345 })
346 .filter(({normalizedKeys}) => normalizedKeys.length > 0)
347 .map(({groupName, normalizedKeys}) => {
348 > // actually generate the switches string --foo, -f, --bar. usage.ts
349 > const switches: Dictionary<string | IndentedText> =
350 > normalizedKeys.reduce((acc, key) => {
351 > acc[key] = [key]
352 > .concat(options.alias[key] || [])
353 > .map(sw => {
354 > // for the special positional group don't
355 > // add '--' or '-' prefix.
356 > if (groupName === self.getPositionalGroupName()) return sw;
357 > else {
358 > return (
359 > // matches yargs-parser logic in which single-digits
360 > // aliases declared with a boolean type are now valid
361 > (/^[0-9]$/.test(sw)
362 > ? options.boolean.includes(key)
363 ? '-'
364 : '--'
365 > : sw.length > 1 usage.ts
366 > ? '--'
367 > : '-') + sw
368 > );
369 > }
370 > })
371 > // place short switches first (see #1403)
372 > .sort((sw1, sw2) =>
373 isLongSwitch(sw1) === isLongSwitch(sw2)
374 ? 0
376 ? 1
377 : -1
378 > ) usage.ts
379 > .join(', ');
380 >
381 > return acc;
382 > }, {} as Dictionary<string>);
383 >
384 > return {groupName, normalizedKeys, switches};
385 });
386
390 .some(
391 ({normalizedKeys, switches}) =>
392 > !normalizedKeys.every(key => isLongSwitch(switches[key])) usage.ts
393 );
394
407 // display 'Options:' table along with any custom tables:
408 displayedGroups.forEach(({groupName, normalizedKeys, switches}) => {
409 > ui.div(groupName); usage.ts
410 >
411 > normalizedKeys.forEach(key => {
412 > const kswitch = switches[key];
413 > let desc = descriptions[key] || '';
414 > let type = null;
415 >
416 > if (desc.includes(deferY18nLookupPrefix))
417 > desc = __(desc.substring(deferY18nLookupPrefix.length));
418 >
419 > if (options.boolean.includes(key)) type = `[${__('boolean')}]`;
420 > if (options.count.includes(key)) type = `[${__('count')}]`;
421 > if (options.string.includes(key)) type = `[${__('string')}]`;
422 > if (options.normalize.includes(key)) type = `[${__('string')}]`;
423 > if (options.array.includes(key)) type = `[${__('array')}]`;
424 > if (options.number.includes(key)) type = `[${__('number')}]`;
425 >
426 > const deprecatedExtra = (deprecated?: string | boolean) =>
427 typeof deprecated === 'string'
428 ? `[${__('deprecated: %s', deprecated)}]`
429 > : `[${__('deprecated')}]`; usage.ts
430 >
431 > const extra = [
432 > key in deprecatedOptions
433 > ? deprecatedExtra(deprecatedOptions[key])
434 > : null,
435 > type,
436 > key in demandedOptions ? `[${__('required')}]` : null,
437 > options.choices && options.choices[key]
438 > ? `[${__('choices:')} ${self.stringifiedValues(
439 options.choices[key]
440 )}]`
441 > : null, usage.ts
442 > defaultString(options.default[key], options.defaultDescription[key]),
443 > ]
444 > .filter(Boolean)
445 > .join(' ');
446 >
447 > ui.span(
448 > {
449 > text: getText(kswitch),
450 > padding: [0, 2, 0, 2 + getIndentation(kswitch)],
451 > width: maxWidth(switches, theWrap) + 4,
452 > },
453 > desc
454 > );
455 >
456 > const shouldHideOptionExtras =
457 > yargs.getInternalMethods().getUsageConfiguration()['hide-types'] ===
458 > true;
459 >
460 > if (extra && !shouldHideOptionExtras)
461 > ui.div({text: extra, padding: [0, 0, 0, 2], align: 'right'});
462 else ui.div();
463 > }); usage.ts
464 >
465 > ui.div();
466 });
467
512 // in the left-hand column of a table.
513 function maxWidth(
514 > table: usage.ts
515 > [string | IndentedText, ...any[]][] | Dictionary<string | IndentedText>,
516 > theWrap?: number | null,
517 > modifier?: string
518 > ) {
519 > let width = 0;
520 >
521 > // table might be of the form [leftColumn],
522 > // or {key: leftColumn}
523 > if (!Array.isArray(table)) {
524 > table = Object.values(table).map<[string | IndentedText]>(v => [v]);
525 > }
526 >
527 > table.forEach(v => {
528 > // column might be of the form "text"
529 > // or { text: "text", indent: 4 }
530 > width = Math.max(
531 > shim.stringWidth(
532 > modifier ? `${modifier} ${getText(v[0])}` : getText(v[0])
533 > ) + getIndentation(v[0]),
534 > width
535 > );
536 > });
537 >
538 > // if we've enabled 'wrap' we should limit
539 > // the max-width of the left-column.
540 > if (theWrap)
541 > width = Math.min(width, parseInt((theWrap * 0.5).toString(), 10));
542 >
543 > return width;
544 > }
545
546 // make sure any options set for aliases,
601
602 keys.forEach(key => {
603 > toCheck = [key].concat(aliases[key]); usage.ts
604 > if (!toCheck.some(k => groupedKeys.indexOf(k) !== -1)) {
605 groups[defaultGroup].push(key);
606 }
648 // the right-hand column.
649 function defaultString(value: any, defaultDescription?: string) {
650 > let string = `[${__('default:')} `; usage.ts
651 >
652 > if (value === undefined && !defaultDescription) return null;
653
654 if (defaultDescription) {
814 }
815
816 > function isIndentedText(text: string | IndentedText): text is IndentedText { usage.ts
817 > return typeof text === 'object';
818 > }
819
820 function addIndentation(
827 }
828
829 > function getIndentation(text: string | IndentedText): number { usage.ts
830 > return isIndentedText(text) ? text.indentation : 0;
831 > }
832
833 > function getText(text: string | IndentedText): string { usage.ts
834 > return isIndentedText(text) ? text.text : text;
835 > }
lib/yargs-factory.ts 2 introduced LOC · 1 range

Open complete file

1586 }
1587 [kGetUsageConfiguration](): UsageConfiguration {
1588 > return this.#usageConfig; yargs-factory.ts
1589 > }
1590 [kGuessLocale]() {
1591 if (!this.#detectLocale) return;