completion.ts ×19

Frontier kind: Code frontier

unlabeled · c_b2a1d7be80d7

78 tests · 2283 LOC · 18 files · introduces 0 tests · 75 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges75 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
415 ranges2283 lines · 18 files · Browse complete extent
All tests (intent)
78 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.

1 file ranked by introduced lines: 75 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

lib/completion.ts 75 introduced LOC · 19 ranges

Open complete file

49
50 private defaultCompletion(
51 > args: string[], completion.ts
52 > argv: Arguments,
53 > current: string,
54 > done: CompletionCallback
55 > ): Arguments | void {
56 > const handlers = this.command.getCommandHandlers();
57 > for (let i = 0, ii = args.length; i < ii; ++i) {
58 if (handlers[args[i]] && handlers[args[i]].builder) {
59 const builder = handlers[args[i]].builder;
66 }
67 }
69 > const completions: string[] = [];
70 >
71 > this.commandCompletions(completions, args, current);
72 > this.optionCompletions(completions, args, argv, current);
73 > this.choicesFromOptionsCompletions(completions, args, argv, current);
74 > this.choicesFromPositionalsCompletions(completions, args, argv, current);
75 > done(null, completions);
76 > }
77
78 // Default completions for commands
79 private commandCompletions(
80 > completions: string[], completion.ts
81 > args: string[],
82 > current: string
83 > ) {
84 > const parentCommands = this.yargs
85 > .getInternalMethods()
86 > .getContext().commands;
87 > if (
88 > !current.match(/^-/) &&
89 > parentCommands[parentCommands.length - 1] !== current &&
90 !this.previousArgHasChoices(args)
91 > ) { completion.ts
92 this.usage.getCommands().forEach(usageCommand => {
93 const commandName = parseCommand(usageCommand[0]).cmd;
102 });
103 }
104 > } completion.ts
105
106 // Default completions for - and -- options
107 private optionCompletions(
108 > completions: string[], completion.ts
109 > args: string[],
110 > argv: Arguments,
111 > current: string
112 > ) {
113 > if (
114 > (current.match(/^-/) || (current === '' && completions.length === 0)) &&
115 !this.previousArgHasChoices(args)
116 > ) { completion.ts
117 const options = this.yargs.getOptions();
118 const positionalKeys =
140 });
141 }
142 > } completion.ts
143
144 private choicesFromOptionsCompletions(
145 > completions: string[], completion.ts
146 > args: string[],
147 > argv: Arguments,
148 > current: string
149 > ) {
150 > if (this.previousArgHasChoices(args)) {
151 const choices = this.getPreviousArgChoices(args);
152 if (choices && choices.length > 0) {
154 }
155 }
156 > } completion.ts
157
158 private choicesFromPositionalsCompletions(
159 > completions: string[], completion.ts
160 > args: string[],
161 > argv: Arguments,
162 > current: string
163 > ) {
164 > if (
165 > current === '' &&
166 > completions.length > 0 &&
167 this.previousArgHasChoices(args)
168 > ) { completion.ts
169 return;
170 }
171
172 const positionalKeys =
173 > this.yargs.getGroups()[this.usage.getPositionalGroupName()] || []; completion.ts
174 > const offset = Math.max(
175 > this.indexAfterLastReset,
176 > this.yargs.getInternalMethods().getContext().commands.length +
177 > /* name of the script is first param */ 1
178 > );
179 >
180 > const positionalKey = positionalKeys[argv._.length - offset - 1];
181 > if (!positionalKey) {
182 return;
183 }
184
185 > const choices = this.yargs.getOptions().choices[positionalKey] || []; completion.ts
186 > for (const choice of choices) {
187 if (choice.startsWith(current)) {
188 completions.push(choice.replace(/:/g, '\\:'));
192
193 private getPreviousArgChoices(args: string[]): string[] | void {
194 > if (args.length < 1) return; // no args completion.ts
195 let previousArg = args[args.length - 1];
196 let filter = '';
197 // use second to last argument if the last one is not an option starting with --
198 > if (!previousArg.startsWith('-') && args.length > 1) { completion.ts
199 filter = previousArg; // use last arg as filter for choices
200 previousArg = args[args.length - 2];
207 const possibleAliases = [
208 previousArgKey,
209 > ...(this.yargs.getAliases()[previousArgKey] || []), completion.ts
210 > ];
211 > let choices: string[] | undefined;
212 > // Find choices across all possible aliases
213 > for (const possibleAlias of possibleAliases) {
214 if (
215 Object.prototype.hasOwnProperty.call(options.key, possibleAlias) &&
224 return choices.filter(choice => !filter || choice.startsWith(filter));
225 }
226 > } completion.ts
227
228 private previousArgHasChoices(args: string[]): boolean {
229 > const choices = this.getPreviousArgChoices(args); completion.ts
230 > return choices !== undefined && choices.length > 0;
231 > }
232
233 private argsContainKey(