forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotnet-new.ts
250 lines (243 loc) · 7.37 KB
/
dotnet-new.ts
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
type SearchResultData = {
id: string;
title: string;
description: string;
};
const searchGenerator: Fig.Generator = {
script(context) {
const searchTerm = context[context.length - 1];
return `curl -s -H "Accept: application/json" "https://azuresearch-usnc.nuget.org/query?packageType=Template&q=${searchTerm}"`;
},
postProcess(out) {
const searchResults: SearchResultData[] = JSON.parse(out).data;
return searchResults.map<Fig.Suggestion>((value) => {
return {
name: value.title,
insertValue: value.id,
description: value.description,
};
});
},
};
const commands: Fig.Subcommand[] = [
{
name: "--list",
description:
"The dotnet new --list option lists available templates to use with dotnet new",
options: [
{
name: "--author",
},
{
name: "--columns",
description: "Comma-separated list of columns to display in the output",
args: {
name: "columns",
suggestions: ["language", "tags", "author", "type"],
},
},
{
name: "--columns-all",
description:
"Displays all columns in the output. Available since .NET Core 5.0.300 SDK",
},
{
name: "--tag",
description:
"Filters templates based on template tags. To be selected, a template must have at least one tag that exactly matches the criteria. Available since .NET Core 5.0.300 SDK",
args: {
name: "tag",
},
},
{
name: "--type",
args: {
name: "type",
suggestions: ["project", "item"],
},
},
],
},
{
name: "--search",
description:
"The dotnet new --search option searches for templates supported by dotnet new on NuGet.org",
args: {
name: "template",
description:
"If the argument is specified, only templates containing <TEMPLATE_NAME> in the template name or short name will be shown. The argument is mandatory when --author, --language, --package, --tag or --type options are not specified",
isOptional: true,
},
options: [
{
name: "--author",
description:
"Filters templates based on template author. Partial match is supported",
args: {
name: "author",
},
},
{
name: "--columns",
description: "Comma-separated list of columns to display in the output",
args: {
name: "columns",
suggestions: ["language", "tags", "author", "type"],
},
},
{
name: "--columns-all",
description: "Displays all columns in the output",
},
{
name: ["-lang", "--language"],
description:
"Filters templates based on language supported by the template. The language accepted varies by the template. Not valid for some templates",
args: {
name: "language",
suggestions: ["C#", "F#", "VB"],
},
},
{
name: "--package",
description:
"Filters templates based on NuGet package ID. Partial match is supported",
args: {
name: "package",
},
},
{
name: "--tag",
description:
"Filters templates based on template tags. To be selected, a template must have at least one tag that exactly matches the criteria",
args: {
name: "tag",
},
},
{
name: "--type",
description:
"Filters templates based on template type. Predefined values are project and item",
args: {
name: "type",
suggestions: ["project", "item"],
},
},
],
},
{
name: ["-i", "--install"],
args: {
name: "id",
description:
"The dotnet new --install command installs a template package from the PATH or NUGET_ID provided",
debounce: true,
generators: searchGenerator,
},
options: [
{
name: "--interactive",
description:
"Allows the command to stop and wait for user input or action. For example, to complete authentication. Available since .NET 5.0 SDK",
},
{
name: "--nuget-source",
description:
"By default, dotnet new --install uses the hierarchy of NuGet configuration files from the current directory to determine the NuGet source the package can be installed from. If --nuget-source is specified, the source will be added to the list of sources to be checked",
args: {
name: "source",
},
},
],
},
{
name: ["-u", "--uninstall"],
description:
"The dotnet new --uninstall command uninstalls a template package at the PATH or NUGET_ID provided",
args: {
name: "id",
},
},
{
name: "--update-check",
description:
"The dotnet new --update-check option checks if there are updates available for the template packs that are currently installed",
},
{
name: "--update-apply",
description:
"The dotnet new --update-apply option checks if there are updates available for the template packages that are currently installed and installs them",
},
];
const completionSpec: Fig.Spec = {
name: "new",
description:
"The dotnet new command creates a .NET project or other artifacts based on a template",
args: {
name: "template",
description:
"The template to instantiate when the command is invoked. Each template might have specific options you can pass",
generators: {
script: "dotnet new --list",
postProcess(out) {
const lines = out.split("\n").slice(4);
return lines.map<Fig.Suggestion>((line) => {
const argRegex = /(([a-zA-Z \.\[\]#,/][^ ]{1,})+)/g;
const [templateName, shortName, language, tags] = line
.match(argRegex)
.map((match) => match.trim());
return {
insertValue: shortName,
name: templateName,
description: tags,
};
});
},
},
},
options: [
{
name: "--dry-run",
description:
"Displays a summary of what would happen if the given command were run if it would result in a template creation",
},
{
name: "--force",
description:
"Forces content to be generated even if it would change existing files. This is required when the template chosen would override existing files in the output directory",
},
{
name: ["-?", "-h", "--help"],
description:
"Prints out help for the command. It can be invoked for the dotnet new command itself or for any template. For example, dotnet new mvc --help",
},
{
name: ["-lang", "--language"],
description: "The language of the template to create",
args: {
name: "language",
suggestions: ["C#", "F#", "VB"],
},
},
{
name: ["-n", "--name"],
description:
"The name for the created output. If no name is specified, the name of the current directory is used",
args: {
name: "output_name",
},
},
{
name: ["-o", "--output"],
dependsOn: ["template"],
description:
"Location to place the generated output. The default is the current directory",
args: {
name: "output_directory",
template: "folders",
},
},
],
subcommands: commands,
};
export default completionSpec;