Repository navigation
Expand file tree
/
Copy pathcli.ts
More file actions
75 lines (62 loc) · 2.35 KB
/
Copy pathcli.ts
File metadata and controls
75 lines (62 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Argv } from 'yargs';
import { CommandModule, CommandModuleImplementation } from '../../command-builder/command-module';
import { addCommandModuleToYargs } from '../../command-builder/utilities/command';
import { colors } from '../../utilities/color';
import { hasGlobalCliInstall, initializeAutocomplete } from '../../utilities/completion';
import { assertIsError } from '../../utilities/error';
import longDescription from './long-description.md';
export default class CompletionCommandModule
extends CommandModule
implements CommandModuleImplementation
{
command = 'completion';
describe = 'Set up Angular CLI autocompletion for your terminal.';
override longDescription = longDescription;
builder(localYargs: Argv): Argv {
addCommandModuleToYargs(CompletionScriptCommandModule, this.context);
return localYargs;
}
async run(): Promise<number> {
let rcFile: string;
try {
rcFile = await initializeAutocomplete();
} catch (err) {
assertIsError(err);
this.context.logger.error(err.message);
return 1;
}
this.context.logger.info(
`
Appended \`source <(ng completion script)\` to \`${rcFile}\`. Restart your terminal or run the following to autocomplete \`ng\` commands:
${colors.yellow('source <(ng completion script)')}
`.trim(),
);
if ((await hasGlobalCliInstall()) === false) {
this.context.logger.warn(
'Setup completed successfully, but there does not seem to be a global install of the' +
' Angular CLI. For autocompletion to work, the CLI will need to be on your `$PATH`, which' +
' is typically done with the `-g` flag in `npm install -g @angular/cli`.' +
'\n\n' +
'For more information, see https://angular.dev/cli/completion#global-install',
);
}
return 0;
}
}
class CompletionScriptCommandModule extends CommandModule implements CommandModuleImplementation {
command = 'script';
describe = 'Generate a bash and zsh real-time type-ahead autocompletion script.';
builder(localYargs: Argv): Argv {
return localYargs;
}
run(): void {
this.context.yargsInstance.showCompletionScript();
}
}