Skip to content

Commit 38cd140

Browse files
committed
(GH-691) Add PDK Defined Type Command
Add `pdk new defined_type` as an available command in VS Code. This also surfaces it as a command in the command palatte as well as the context menus.
1 parent 70d2152 commit 38cd140

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

package.json

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@
163163
"category": "Puppet",
164164
"title": "PDK New Task"
165165
},
166+
{
167+
"command": "extension.pdkNewDefinedType",
168+
"category": "Puppet",
169+
"title": "PDK New Defined type"
170+
},
166171
{
167172
"command": "extension.puppetResource",
168173
"category": "Puppet",
@@ -267,6 +272,9 @@
267272
{
268273
"command": "extension.pdkNewTask"
269274
},
275+
{
276+
"command": "extension.pdkNewDefinedType"
277+
},
270278
{
271279
"command": "extension.puppetResource",
272280
"when": "editorLangId == 'puppet'"
@@ -292,15 +300,20 @@
292300
"command": "extension.pdkNewTask",
293301
"group": "pdk@3"
294302
},
303+
{
304+
"when": "editorLangId == 'puppet'",
305+
"command": "extension.pdkNewDefinedType",
306+
"group": "pdk@4"
307+
},
295308
{
296309
"when": "editorLangId == 'puppet' ",
297310
"command": "extension.pdkValidate",
298-
"group": "pdk@4"
311+
"group": "pdk@5"
299312
},
300313
{
301314
"when": "editorLangId == 'puppet'",
302315
"command": "extension.pdkTestUnit",
303-
"group": "pdk@5"
316+
"group": "pdk@6"
304317
},
305318
{
306319
"when": "editorLangId == 'puppet'",
@@ -326,14 +339,19 @@
326339
},
327340
{
328341
"when": "editorLangId == 'puppet'",
329-
"command": "extension.pdkValidate",
342+
"command": "extension.pdkNewDefinedType",
330343
"group": "pdk@3"
331344
},
332345
{
333346
"when": "editorLangId == 'puppet'",
334-
"command": "extension.pdkTestUnit",
347+
"command": "extension.pdkValidate",
335348
"group": "pdk@4"
336349
},
350+
{
351+
"when": "editorLangId == 'puppet'",
352+
"command": "extension.pdkTestUnit",
353+
"group": "pdk@5"
354+
},
337355
{
338356
"when": "editorLangId == 'puppet'",
339357
"command": "puppet.puppetShowNodeGraphToSide",

src/feature/PDKFeature.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export class PDKFeature implements IFeature {
3434
}),
3535
);
3636
logger.debug('Registered ' + PDKCommandStrings.PdkNewTaskCommandId + ' command');
37+
context.subscriptions.push(
38+
vscode.commands.registerCommand(PDKCommandStrings.PdkNewDefinedTypeCommandId, () => {
39+
this.pdkNewDefinedTypeCommand();
40+
}),
41+
);
42+
logger.debug('Registered ' + PDKCommandStrings.PdkNewTaskCommandId + ' command');
3743
context.subscriptions.push(
3844
vscode.commands.registerCommand(PDKCommandStrings.PdkValidateCommandId, () => {
3945
this.pdkValidateCommand();
@@ -110,6 +116,21 @@ export class PDKFeature implements IFeature {
110116
});
111117
}
112118

119+
private pdkNewDefinedTypeCommand() {
120+
const nameOpts: vscode.QuickPickOptions = {
121+
placeHolder: 'Enter a name for the new Puppet defined type',
122+
matchOnDescription: true,
123+
matchOnDetail: true,
124+
};
125+
vscode.window.showInputBox(nameOpts).then((typeName) => {
126+
this.terminal.sendText(`pdk new defined_type ${typeName}`);
127+
this.terminal.show();
128+
if (reporter) {
129+
reporter.sendTelemetryEvent(PDKCommandStrings.PdkNewDefinedTypeCommandId);
130+
}
131+
});
132+
}
133+
113134
private pdkValidateCommand() {
114135
this.terminal.sendText(`pdk validate`);
115136
this.terminal.show();

src/messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class PDKCommandStrings {
7979
static PdkNewModuleCommandId = 'extension.pdkNewModule';
8080
static PdkNewClassCommandId = 'extension.pdkNewClass';
8181
static PdkNewTaskCommandId = 'extension.pdkNewTask';
82+
static PdkNewDefinedTypeCommandId = 'extension.pdkNewDefinedType';
8283
static PdkValidateCommandId = 'extension.pdkValidate';
8384
static PdkTestUnitCommandId = 'extension.pdkTestUnit';
8485
}

0 commit comments

Comments
 (0)