From d38212fbb3b3eadb184225ddb0470a7ccf64d4ad Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 17 Dec 2024 00:56:50 -0500 Subject: [PATCH] just playing around --- package.json | 22 +++++++++- src/extension.ts | 108 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 103 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index c46a0c8..c973913 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,18 @@ "contributes": { "commands": [ { - "command": "suvmanager.suv_manager", + "command": "mocha.suvmanager.suv_manager", "title": "Manage SUVs", "category": "Mocha" }, { - "command": "suvmanager.suv_up", + "command": "mocha.suvmanager.suv_show", + "title": "Open SUV in Web Browser", + "shortTitle": "Show in Web", + "category": "Mocha" + }, + { + "command": "mocha.suvmanager.suv_up", "title": "Launch SUV", "category": "Mocha" }, @@ -145,6 +151,18 @@ "when": "view == mocha.suvManager", "group": "navigation@1" } + ], + "view/item/context": [ + { + "command": "mocha.suvmanager.suv_show", + "group": "YourGroup@1", + "when": "view == mocha.suvManager" + }, + { + "command": "mocha.suvmanager.suv_up", + "group": "YourGroup@2", + "when": "view == mocha.suvManager" + } ] } }, diff --git a/src/extension.ts b/src/extension.ts index 5e061ef..b7cd777 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -25,7 +25,7 @@ export function mkotsuri(suvId : string, tenantName : string, command : string, } function updateModuleExplorerTreeView() { - /* + dpModuleExplorer.items.push(new GenericTreeDataItem("tools", "tools", [ new GenericTreeDataItem("tools:xpresso", "xpressO", [ new GenericTreeDataItem("tools:xpressO:method", "method", [ @@ -47,7 +47,7 @@ function updateModuleExplorerTreeView() { "type": "module" } )); - */ + return; let suvId : string = "i-0c0398f84acecb702"; let tenantName : string = "super"; @@ -102,10 +102,29 @@ function recursiveAddItemToTreeView(dp : GenericTreeDataProvider, item : any, pa } } +function launchSuv(name : string) +{ + cp.exec("mocha suv up " + name, (err2: string, stdout2: string, stderr2: string) => { + vscode.window.showInformationMessage('Selected SUV ( ' + name + ' ) launched successfully!'); + }); + vscode.window.showInformationMessage('Selected SUV ( ' + name + ' ) is launching now!'); +} + +let outputChannel: vscode.OutputChannel | undefined = undefined; + +export function openWebBrowser(url: vscode.Uri) { + + cp.exec("xdg-open " + url.toString(), (err: string, stdout: string, stderr: string) => { + }); +} + // This method is called when your extension is activated // Your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { + outputChannel = vscode.window.createOutputChannel("Mocha"); + outputChannel.appendLine("Mocha for VSCode activated"); + let treeDataProvider = new SuvManagerTreeDataProvider(); treeSuvManager = vscode.window.createTreeView("mocha.suvManager", { "canSelectMany": true, "showCollapseAll": true, "treeDataProvider": treeDataProvider }); treeDataProvider.treeview = treeSuvManager; @@ -116,7 +135,7 @@ export function activate(context: vscode.ExtensionContext) { // dpModuleExplorer.treeview = treeModuleExplorer; // treeModuleExplorer.badge = { "value": 1, "tooltip": "1 SUV(s) running" }; - // updateModuleExplorerTreeView(); + updateModuleExplorerTreeView(); // Use the console to output diagnostic information (console.log) and errors (console.error) // This line of code will only be executed once when your extension is activated @@ -208,7 +227,7 @@ export function activate(context: vscode.ExtensionContext) { // The command has been defined in the package.json file // Now provide the implementation of the command with registerCommand // The commandId parameter must match the command field in package.json - let cmd_suv_manager = vscode.commands.registerCommand('suvmanager.suv_manager', () => { + let cmd_suv_manager = vscode.commands.registerCommand('mocha.suvmanager.suv_manager', () => { // The code you place here will be executed every time your command is executed // Display a message box to the user @@ -216,34 +235,73 @@ export function activate(context: vscode.ExtensionContext) { }); context.subscriptions.push(cmd_suv_manager); - let cmd_suv_up = vscode.commands.registerCommand('suvmanager.suv_up', () => { - // The code you place here will be executed every time your command is executed - // Display a message box to the user - cp.exec('mocha suv list', (err: string, stdout: string, stderr: string) => - { - vscode.window.showInformationMessage(stdout); - let list = stdout.split(' '); - let list2 = new Array(); - list.forEach( (element) => - { - list2.push(element.trim()); - }); - - var w = vscode.window.showQuickPick(list2, { "title": "Launch SUV", "placeHolder": "Pick an SUV to launch (e.g. i-012345678)" }).then((value) => - { - cp.exec("mocha suv up " + value, (err2: string, stdout2: string, stderr2: string) => - { - vscode.window.showInformationMessage('Selected SUV ( ' + value + ' ) launched successfully!'); + let cmd_suv_show = vscode.commands.registerCommand('mocha.suvmanager.suv_show', (...args) => { + if (args.length === 0) { + cp.exec('mocha suv list', (err: string, stdout: string, stderr: string) => { + vscode.window.showInformationMessage(stdout); + let list = stdout.split(' '); + let list2 = new Array(); + list.forEach((element) => { + list2.push(element.trim()); + }); + + var w = vscode.window.showQuickPick(list2, { "title": "Open SUV in Web Browser", "placeHolder": "Choose an SUV to open" }).then((value) => { + if (value !== undefined) { + openWebBrowser(vscode.Uri.parse("https://" + value + ".privatesuv.com")); + } }); - vscode.window.showInformationMessage('Selected SUV ( ' + value + ' ) is launching now!'); }); - }); + } + else + { + let machine : Machine = args[0] as Machine; + openWebBrowser(vscode.Uri.parse("https://" + machine.name + ".privatesuv.com")); + } + }); + + let cmd_suv_up = vscode.commands.registerCommand('mocha.suvmanager.suv_up', (...args) => { + if (args.length === 0) { + cp.exec('mocha suv list', (err: string, stdout: string, stderr: string) => { + vscode.window.showInformationMessage(stdout); + let list = stdout.split(' '); + let list2 = new Array(); + list.forEach((element) => { + list2.push(element.trim()); + }); + + var w = vscode.window.showQuickPick(list2, { "title": "Launch SUV", "placeHolder": "Pick an SUV to launch (e.g. i-012345678)" }).then((value) => { + if (value !== undefined) { + launchSuv(value); + } + }); + }); + } + else + { + let machine : Machine = args[0] as Machine; + launchSuv(machine.name); + } }); let cmd_suv_new = vscode.commands.registerCommand('mocha.suvmanager.suv_new', () => { + outputChannel?.appendLine("Provisioning a new persistent SUV..."); + cp.exec('mocha suv new --unattended', (err: string, stdout: string, stderr: string) => { - vscode.window.showInformationMessage('New SUV provisioned successfully!'); + if (err == null) { + outputChannel?.appendLine("New SUV provisioned successfully!"); + + vscode.window.showInformationMessage('New SUV provisioned successfully!'); + } + else { + outputChannel?.appendLine(err); + vscode.window.showErrorMessage("SUV provisioning failed. Check the error log for details.", "Show Error Log").then((value) => { + if (value == "Show Error Log") + { + outputChannel?.show(); + } + }); + } treeDataProvider.refresh(); }); });