@@ -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}
0 commit comments