Skip to content

Commit 2996d29

Browse files
authored
Merge pull request #692 from jpogran/gh-691-pdk-new-defined-type
(GH-691) PDK New Defined Type
2 parents 07bb5f2 + 8a3389f commit 2996d29

File tree

3 files changed

+74
-77
lines changed

3 files changed

+74
-77
lines changed

package.json

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@
164164
"category": "Puppet",
165165
"title": "PDK New Task"
166166
},
167+
{
168+
"command": "extension.pdkNewDefinedType",
169+
"category": "Puppet",
170+
"title": "PDK New Defined type"
171+
},
167172
{
168173
"command": "extension.puppetResource",
169174
"category": "Puppet",
@@ -268,6 +273,9 @@
268273
{
269274
"command": "extension.pdkNewTask"
270275
},
276+
{
277+
"command": "extension.pdkNewDefinedType"
278+
},
271279
{
272280
"command": "extension.puppetResource",
273281
"when": "editorLangId == 'puppet'"
@@ -293,15 +301,20 @@
293301
"command": "extension.pdkNewTask",
294302
"group": "pdk@3"
295303
},
304+
{
305+
"when": "editorLangId == 'puppet'",
306+
"command": "extension.pdkNewDefinedType",
307+
"group": "pdk@4"
308+
},
296309
{
297310
"when": "editorLangId == 'puppet' ",
298311
"command": "extension.pdkValidate",
299-
"group": "pdk@4"
312+
"group": "pdk@5"
300313
},
301314
{
302315
"when": "editorLangId == 'puppet'",
303316
"command": "extension.pdkTestUnit",
304-
"group": "pdk@5"
317+
"group": "pdk@6"
305318
},
306319
{
307320
"when": "editorLangId == 'puppet'",
@@ -322,19 +335,24 @@
322335
},
323336
{
324337
"when": "editorLangId == 'puppet'",
325-
"command": "extension.pdkNewClass",
338+
"command": "extension.pdkNewTask",
326339
"group": "pdk@2"
327340
},
328341
{
329342
"when": "editorLangId == 'puppet'",
330-
"command": "extension.pdkValidate",
343+
"command": "extension.pdkNewDefinedType",
331344
"group": "pdk@3"
332345
},
333346
{
334347
"when": "editorLangId == 'puppet'",
335-
"command": "extension.pdkTestUnit",
348+
"command": "extension.pdkValidate",
336349
"group": "pdk@4"
337350
},
351+
{
352+
"when": "editorLangId == 'puppet'",
353+
"command": "extension.pdkTestUnit",
354+
"group": "pdk@5"
355+
},
338356
{
339357
"when": "editorLangId == 'puppet'",
340358
"command": "puppet.puppetShowNodeGraphToSide",

src/feature/PDKFeature.ts

Lines changed: 50 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,61 @@ export class PDKFeature implements IFeature {
2222
}),
2323
);
2424
logger.debug('Registered ' + PDKCommandStrings.PdkNewModuleCommandId + ' command');
25-
context.subscriptions.push(
26-
vscode.commands.registerCommand(PDKCommandStrings.PdkNewClassCommandId, () => {
27-
this.pdkNewClassCommand();
28-
}),
29-
);
30-
logger.debug('Registered ' + PDKCommandStrings.PdkNewClassCommandId + ' command');
31-
context.subscriptions.push(
32-
vscode.commands.registerCommand(PDKCommandStrings.PdkNewTaskCommandId, () => {
33-
this.pdkNewTaskCommand();
34-
}),
35-
);
36-
logger.debug('Registered ' + PDKCommandStrings.PdkNewTaskCommandId + ' command');
37-
context.subscriptions.push(
38-
vscode.commands.registerCommand(PDKCommandStrings.PdkValidateCommandId, () => {
39-
this.pdkValidateCommand();
40-
}),
41-
);
42-
logger.debug('Registered ' + PDKCommandStrings.PdkValidateCommandId + ' command');
43-
context.subscriptions.push(
44-
vscode.commands.registerCommand(PDKCommandStrings.PdkTestUnitCommandId, () => {
45-
this.pdkTestUnitCommand();
46-
}),
47-
);
48-
logger.debug('Registered ' + PDKCommandStrings.PdkTestUnitCommandId + ' command');
25+
26+
// commands that require no user input
27+
[
28+
{ id: 'extension.pdkValidate', request: 'pdk validate', type: 'validate' },
29+
{ id: 'extension.pdkTestUnit', request: 'pdk test unit', type: 'test' },
30+
].forEach((command) => {
31+
context.subscriptions.push(
32+
vscode.commands.registerCommand(command.id, () => {
33+
this.terminal.sendText(command.request);
34+
this.terminal.show();
35+
if (reporter) {
36+
reporter.sendTelemetryEvent(command.id);
37+
}
38+
}),
39+
);
40+
logger.debug(`Registered ${command.id} command`);
41+
});
42+
43+
// commands that require user input
44+
[
45+
{ id: 'extension.pdkNewClass', request: 'pdk new class', type: 'Puppet class' },
46+
{ id: 'extension.pdkNewTask', request: 'pdk new task', type: 'Bolt task' },
47+
{ id: 'extension.pdkNewDefinedType', request: 'pdk new defined_type', type: 'Puppet defined_type' },
48+
].forEach((command) => {
49+
context.subscriptions.push(
50+
vscode.commands.registerCommand(command.id, () => {
51+
const nameOpts: vscode.QuickPickOptions = {
52+
placeHolder: `Enter a name for the new ${command.type}`,
53+
matchOnDescription: true,
54+
matchOnDetail: true,
55+
};
56+
57+
vscode.window.showInputBox(nameOpts).then((name) => {
58+
if (name === undefined) {
59+
vscode.window.showWarningMessage(`No ${command.type} value specifed. Exiting.`);
60+
return;
61+
}
62+
const request = `${command.request} ${name}`;
63+
this.terminal.sendText(request);
64+
this.terminal.show();
65+
if (reporter) {
66+
reporter.sendTelemetryEvent(command.id);
67+
}
68+
});
69+
}),
70+
);
71+
logger.debug(`Registered ${command.id} command`);
72+
});
4973
}
5074

51-
public dispose(): any {
75+
public dispose(): void {
5276
this.terminal.dispose();
5377
}
5478

55-
private pdkNewModuleCommand() {
79+
private pdkNewModuleCommand(): void {
5680
const nameOpts: vscode.QuickPickOptions = {
5781
placeHolder: 'Enter a name for the new Puppet module',
5882
matchOnDescription: true,
@@ -79,50 +103,4 @@ export class PDKFeature implements IFeature {
79103
});
80104
});
81105
}
82-
83-
private pdkNewClassCommand() {
84-
const nameOpts: vscode.QuickPickOptions = {
85-
placeHolder: 'Enter a name for the new Puppet class',
86-
matchOnDescription: true,
87-
matchOnDetail: true,
88-
};
89-
vscode.window.showInputBox(nameOpts).then((moduleName) => {
90-
this.terminal.sendText(`pdk new class ${moduleName}`);
91-
this.terminal.show();
92-
if (reporter) {
93-
reporter.sendTelemetryEvent(PDKCommandStrings.PdkNewClassCommandId);
94-
}
95-
});
96-
}
97-
98-
private pdkNewTaskCommand() {
99-
const nameOpts: vscode.QuickPickOptions = {
100-
placeHolder: 'Enter a name for the new Puppet Task',
101-
matchOnDescription: true,
102-
matchOnDetail: true,
103-
};
104-
vscode.window.showInputBox(nameOpts).then((taskName) => {
105-
this.terminal.sendText(`pdk new task ${taskName}`);
106-
this.terminal.show();
107-
if (reporter) {
108-
reporter.sendTelemetryEvent(PDKCommandStrings.PdkNewTaskCommandId);
109-
}
110-
});
111-
}
112-
113-
private pdkValidateCommand() {
114-
this.terminal.sendText(`pdk validate`);
115-
this.terminal.show();
116-
if (reporter) {
117-
reporter.sendTelemetryEvent(PDKCommandStrings.PdkValidateCommandId);
118-
}
119-
}
120-
121-
private pdkTestUnitCommand() {
122-
this.terminal.sendText(`pdk test unit`);
123-
this.terminal.show();
124-
if (reporter) {
125-
reporter.sendTelemetryEvent(PDKCommandStrings.PdkTestUnitCommandId);
126-
}
127-
}
128106
}

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)