Skip to content

Commit b74acdb

Browse files
author
James Pogran
authored
Merge pull request #481 from jpogran/GH-476-bolt-command-palatte
(GH-476)(GH-477) Add Bolt Feature Support
2 parents 0dc4c10 + deabd36 commit b74acdb

File tree

8 files changed

+180
-15
lines changed

8 files changed

+180
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
66

77
## Unreleased
88

9+
### Added
10+
11+
- ([GH-476](https://github.com/lingua-pupuli/puppet-vscode/issues/476)) Add Bolt commands
12+
- ([GH-477](https://github.com/lingua-pupuli/puppet-vscode/issues/477)) Add Bolt yaml snippets
13+
914
## [0.16.0] - 2019-01-25
1015

1116
### Added

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ In Puppet VSCode Extension v0.17.0 release support for Puppet Bolt was added. Fu
253253

254254
The first step in this is enabling parsing Bolt Plans. This means when opening a Puppet module with Puppet Bolt plans or a folder with a Puppet Bolt plan file the Puppet VSCode Extension will no longer log an error in the Problems Pane for failing to parse Puppet Bolt Plan keywords. You will get symbol support (OutlineView and Breadcrumbs) as well as syntax highlighting. Subsequent releases will focus on adding intellisense, autocompletion, hover support and other advanced editor features. This work is tracked in the [Puppet Bolt Support Github project](https://github.com/orgs/lingua-pupuli/projects/20)
255255

256+
#### Puppet Bolt Commands and Snippets
257+
258+
We have added support for VSCode Command Palatte commands for opening Bolt user config and inventory yaml files. We have also added support for yaml snippets for common operations in Bolt yaml files.
259+
260+
![bolt_command_palatte](docs/assets/bolt_config_command.gif)
261+
262+
![bolt_command_palatte](docs/assets/bolt_inventory_command.gif)
263+
256264
### Debugging Puppet manifests
257265

258266
**Note - This is an experimental feature**
234 KB
Loading
426 KB
Loading

package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
"onCommand:extension.pdkNewClass",
6464
"onCommand:extension.pdkNewTask",
6565
"onCommand:extension.pdkTestUnit",
66-
"onCommand:extension.pdkValidate"
66+
"onCommand:extension.pdkValidate",
67+
"onCommand:puppet-bolt.OpenUserConfigFile",
68+
"onCommand:puppet-bolt.OpenUserInventoryFile"
6769
],
6870
"main": "./out/extension",
6971
"contributes": {
@@ -126,6 +128,10 @@
126128
{
127129
"language": "puppetfile",
128130
"path": "./snippets/puppetfile.snippets.json"
131+
},
132+
{
133+
"language": "yaml",
134+
"path": "./snippets/bolt.snippets.json"
129135
}
130136
],
131137
"commands": [
@@ -176,6 +182,16 @@
176182
"light": "./media/PreviewOnRightPane_16x.svg",
177183
"dark": "./media/PreviewOnRightPane_16x_dark.svg"
178184
}
185+
},
186+
{
187+
"command": "puppet-bolt.OpenUserConfigFile",
188+
"title": "Open Bolt User Configuration File",
189+
"category": "Puppet"
190+
},
191+
{
192+
"command": "puppet-bolt.OpenUserInventoryFile",
193+
"title": "Open Bolt User Inventory File",
194+
"category": "Puppet"
179195
}
180196
],
181197
"menus": {

snippets/bolt.snippets.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"Bolt Config template": {
3+
"prefix": "bolt-config",
4+
"description": "A complete Bolt config template structure snippet",
5+
"body": [
6+
"modulepath: ${1:modulePath}",
7+
"inventoryFile: ${2:inventoryFile}",
8+
"concurrency: ${3:10}",
9+
"format: ${4|human,json|}",
10+
"color: ${6|true,false|}",
11+
"\t${7|ssh,wirnm|}:${0}"
12+
]
13+
},
14+
"Bolt Inventory template": {
15+
"prefix": "bolt-inventory",
16+
"description": "A complete Bolt inventory template structure snippet",
17+
"body": [
18+
"groups:",
19+
"- name: ${1:groupName}",
20+
"\tgroups:",
21+
"\t\t- name: ${2:nodeGroupName1}",
22+
"\t\t\tnodes:",
23+
"\t\t\t\t- ${3:node1}",
24+
"\t\t- name: ${4:nodeGroupName2}",
25+
"\t\t\tnodes:",
26+
"\t\t\t\t- ${5:node2}",
27+
"\tconfig:",
28+
"\t\ttransport: ${6|ssh,wirnm|}",
29+
"\t\t${6|ssh,wirnm|}:${0}"
30+
]
31+
},
32+
"Bolt Inventory groups": {
33+
"prefix": "groups",
34+
"description": "Adds new root group",
35+
"body": [
36+
"groups:",
37+
" - name: ${1:groupName}"
38+
]
39+
},
40+
"Bolt Inventory node": {
41+
"prefix": "node",
42+
"description": "Adds new node",
43+
"body": [
44+
"- name: ${1:nodeName}",
45+
" config:",
46+
" transport: ${2|ssh,wirnm|}",
47+
" ${2|ssh,wirnm|}:${0}"
48+
]
49+
},
50+
"Bolt WinRM Transport template": {
51+
"prefix": "winrm",
52+
"description": "",
53+
"body": [
54+
"winrm:",
55+
" user: ${1:userName}",
56+
" password: ${2:passwd}",
57+
" ssl: ${3|true,false|}${0}"
58+
]
59+
},
60+
"Bolt SSH Transport template": {
61+
"prefix": "ssh",
62+
"description": "",
63+
"body": [
64+
"ssh:${0}"
65+
]
66+
}
67+
}

src/extension.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
'use strict';
22

3-
import * as vscode from 'vscode';
43
import * as fs from 'fs';
5-
4+
import * as vscode from 'vscode';
65
import { ConnectionConfiguration } from './configuration';
7-
import { ConnectionHandler } from './handler';
8-
import { StdioConnectionHandler } from './handlers/stdio';
9-
import { TcpConnectionHandler } from './handlers/tcp';
106
import { IFeature } from './feature';
7+
import { BoltFeature } from './feature/BoltFeature';
118
import { DebuggingFeature } from './feature/DebuggingFeature';
129
import { FormatDocumentFeature } from './feature/FormatDocumentFeature';
1310
import { NodeGraphFeature } from './feature/NodeGraphFeature';
1411
import { PDKFeature } from './feature/PDKFeature';
1512
import { PuppetResourceFeature } from './feature/PuppetResourceFeature';
16-
import { ProtocolType, ConnectionType, IConnectionConfiguration } from './interfaces';
13+
import { ConnectionHandler } from './handler';
14+
import { DockerConnectionHandler } from './handlers/docker';
15+
import { StdioConnectionHandler } from './handlers/stdio';
16+
import { TcpConnectionHandler } from './handlers/tcp';
17+
import { ConnectionType, IConnectionConfiguration, ProtocolType } from './interfaces';
1718
import { ILogger } from './logging';
1819
import { OutputChannelLogger } from './logging/outputchannel';
1920
import { PuppetStatusBar } from './PuppetStatusBar';
2021
import { ISettings, legacySettings, settingsFromWorkspace } from './settings';
2122
import { Reporter, reporter } from './telemetry/telemetry';
22-
import { DockerConnectionHandler } from './handlers/docker';
2323

2424
export const puppetLangID = 'puppet'; // don't change this
2525
export const puppetFileLangID = 'puppetfile'; // don't change this
@@ -52,6 +52,11 @@ export function activate(context: vscode.ExtensionContext) {
5252
statusBar = new PuppetStatusBar([puppetLangID, puppetFileLangID], context, logger);
5353
configSettings = new ConnectionConfiguration();
5454

55+
extensionFeatures = [
56+
new PDKFeature(extContext, logger),
57+
new BoltFeature(extContext),
58+
];
59+
5560
if(settings.editorService.enable === false){
5661
notifyEditorServiceDisabled(extContext);
5762
reporter.sendTelemetryEvent('editorServiceDisabled');
@@ -78,13 +83,10 @@ export function activate(context: vscode.ExtensionContext) {
7883
break;
7984
}
8085

81-
extensionFeatures = [
82-
new FormatDocumentFeature(puppetLangID, connectionHandler, settings, logger, extContext),
83-
new NodeGraphFeature(puppetLangID, connectionHandler, logger, extContext),
84-
new PDKFeature(extContext, logger),
85-
new PuppetResourceFeature(extContext, connectionHandler, logger),
86-
new DebuggingFeature(debugType, settings, configSettings, extContext, logger)
87-
];
86+
extensionFeatures.push(new FormatDocumentFeature(puppetLangID, connectionHandler, settings, logger, extContext));
87+
extensionFeatures.push(new NodeGraphFeature(puppetLangID, connectionHandler, logger, extContext));
88+
extensionFeatures.push(new PuppetResourceFeature(extContext, connectionHandler, logger));
89+
extensionFeatures.push(new DebuggingFeature(debugType, settings, configSettings, extContext, logger));
8890
}
8991

9092
export function deactivate() {

src/feature/BoltFeature.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { ExtensionContext, commands, window, Uri } from 'vscode';
2+
import { IFeature } from '../feature';
3+
import * as path from 'path';
4+
import * as fs from 'fs';
5+
import { reporter } from '../telemetry/telemetry';
6+
7+
export class BoltFeature implements IFeature {
8+
dispose() { }
9+
constructor(context: ExtensionContext) {
10+
context.subscriptions.push(
11+
commands.registerCommand('puppet-bolt.OpenUserConfigFile', () => {
12+
let userInventoryFile = path.join(process.env['USERPROFILE'] || '~', '.puppetlabs', 'bolt', 'bolt.yaml');
13+
14+
this.openOrCreateFile(
15+
userInventoryFile,
16+
`Default bolt config yml not present. Do you want to create it?`,
17+
'# This is an empty bolt config file.\n# You can get started quickly by using the built-in bolt snippets'
18+
);
19+
20+
if (reporter) {
21+
reporter.sendTelemetryEvent('puppet-bolt.OpenUserConfigFile');
22+
}
23+
})
24+
);
25+
26+
context.subscriptions.push(
27+
commands.registerCommand('puppet-bolt.OpenUserInventoryFile', () => {
28+
let userInventoryFile = path.join(process.env['USERPROFILE'] || '~', '.puppetlabs', 'bolt', 'inventory.yaml');
29+
30+
this.openOrCreateFile(
31+
userInventoryFile,
32+
`Default bolt inventory yml not present. Do you want to create it?`,
33+
'# This is an empty bolt inventory file.\n# You can get started quickly by using the built-in bolt snippets or use bolt to generate an inventory file from PuppetDb'
34+
);
35+
36+
if (reporter) {
37+
reporter.sendTelemetryEvent('puppet-bolt.OpenUserInventoryFile');
38+
}
39+
})
40+
);
41+
}
42+
43+
private openOrCreateFile(file: string, message: string, template: string) {
44+
if (!fs.existsSync(file)) {
45+
window
46+
.showQuickPick(['yes', 'no'], {
47+
placeHolder: message,
48+
canPickMany: false,
49+
ignoreFocusOut: true
50+
})
51+
.then(answer => {
52+
switch (answer) {
53+
case 'no':
54+
break;
55+
case 'yes':
56+
fs.writeFile(file, template, 'utf8', function (err) {
57+
window.showErrorMessage(`Error creating file ${file}. Error: ${err.message}`);
58+
});
59+
commands.executeCommand('vscode.openFolder', Uri.file(file), false);
60+
}
61+
});
62+
}
63+
else {
64+
commands.executeCommand('vscode.openFolder', Uri.file(file), false);
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)