diff --git a/package.json b/package.json index 4d8b2cd..f3ab66c 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,11 @@ "title": "Compose Up", "icon": "$(arrow-up)" }, + { + "command": "podmanager.composeDown", + "title": "Compose Down", + "icon": "$(trash)" + }, { "command": "podmanager.composeStart", "title": "Compose Start", @@ -128,11 +133,6 @@ "title": "Compose Restart", "icon": "$(refresh)" }, - { - "command": "podmanager.composeDown", - "title": "Compose Down", - "icon": "$(trash)" - }, { "command": "podmanager.refreshOverview", "title": "Refresh Podman Overview", @@ -289,22 +289,27 @@ "group": "inline" }, { - "command": "podmanager.composeStart", + "command": "podmanager.composeUp", "when": "view == podmanView && viewItem == compose-group", "group": "inline" }, { - "command": "podmanager.composeStop", + "command": "podmanager.composeDown", "when": "view == podmanView && viewItem == compose-group", "group": "inline" }, { - "command": "podmanager.composeRestart", + "command": "podmanager.composeStart", "when": "view == podmanView && viewItem == compose-group", "group": "inline" }, { - "command": "podmanager.composeDown", + "command": "podmanager.composeStop", + "when": "view == podmanView && viewItem == compose-group", + "group": "inline" + }, + { + "command": "podmanager.composeRestart", "when": "view == podmanView && viewItem == compose-group", "group": "inline" }, diff --git a/src/extension.ts b/src/extension.ts index e9f2413..dd2940c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -8,8 +8,8 @@ import { PodmanItem } from './podmanItem'; import { createContainer } from './createContainer'; import { createVolume, createNetwork } from './createResource'; - const execAsync = promisify(exec); +const podmanTreeDataProvider = new PodmanTreeDataProvider(); function getPodmanPath(): string { const config = vscode.workspace.getConfiguration('podmanager'); @@ -25,7 +25,6 @@ async function resetPodmanPath() { export function activate(context: vscode.ExtensionContext) { console.log('Podmanager extension is now active!'); - const podmanTreeDataProvider = new PodmanTreeDataProvider(); const treeView = vscode.window.createTreeView('podmanView', { treeDataProvider: podmanTreeDataProvider }); context.subscriptions.push(treeView); @@ -55,6 +54,10 @@ export function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand('podmanager.deleteVolume', deleteVolume), vscode.commands.registerCommand('podmanager.deleteNetwork', deleteNetwork), vscode.commands.registerCommand('podmanager.composeUp', composeUp), + vscode.commands.registerCommand('podmanager.composeDown', composeDown), + vscode.commands.registerCommand('podmanager.composeStart', composeStart), + vscode.commands.registerCommand('podmanager.composeStop', composeStop), + vscode.commands.registerCommand('podmanager.composeRestart', composeRestart), vscode.commands.registerCommand('podmanager.startPod', startPod), vscode.commands.registerCommand('podmanager.stopPod', stopPod), vscode.commands.registerCommand('podmanager.restartPod', restartPod), @@ -273,6 +276,22 @@ async function composeUp(uri?: vscode.Uri) { await runComposeCommand('up -d', uri); } +async function composeDown(uri?: vscode.Uri) { + await runComposeCommand('down', uri); +} + +async function composeStart(uri?: vscode.Uri) { + await runComposeCommand('start', uri); +} + +async function composeStop(uri?: vscode.Uri) { + await runComposeCommand('stop', uri); +} + +async function composeRestart(uri?: vscode.Uri) { + await runComposeCommand('restart', uri); +} + async function startPod(item: PodmanItem) { await runPodCommand('start', item.id!); } @@ -363,6 +382,7 @@ async function runComposeCommand(command: string, uri?: vscode.Uri) { } catch (error) { vscode.window.showErrorMessage(`Failed to execute Podman Compose ${command}: ${error}`); } + podmanTreeDataProvider.refresh(); } async function runPodCommand(command: string, podId: string, force: boolean = false) { diff --git a/src/podmanItem.ts b/src/podmanItem.ts index 9b6efdf..5ada04e 100644 --- a/src/podmanItem.ts +++ b/src/podmanItem.ts @@ -11,7 +11,8 @@ export class PodmanItem extends vscode.TreeItem { public readonly composeProject?: string, public children?: PodmanItem[], public readonly isUsed?: boolean, - public readonly resourceName?: string + public readonly resourceName?: string, + public readonly fsPath?: string ) { super(label, collapsibleState); this.contextValue = contextValue; diff --git a/src/podmanTreeDataProvider.ts b/src/podmanTreeDataProvider.ts index c22066a..07aceef 100644 --- a/src/podmanTreeDataProvider.ts +++ b/src/podmanTreeDataProvider.ts @@ -82,6 +82,9 @@ export class PodmanTreeDataProvider implements vscode.TreeDataProvider label.startsWith('com.docker.compose.project=')); - return projectLabel ? projectLabel.split('=')[1] : 'Unknown Project'; + const projectPattern = /com\.docker\.compose\.project(=|:)/; + return this.extractLabelValue(labels, projectPattern, 'Unknown Project'); + } + + private extractComposeFile(labels: string): string { + const directoryPattern = /com\.docker\.compose\.project\.working_dir(=|:)/; + const path = this.extractLabelValue(labels, directoryPattern, ''); + if (path.length > 0) { + const filePattern = /com\.docker\.compose\.project\.config_files(=|:)/; + const composeFile = this.extractLabelValue(labels, filePattern, ''); + return composeFile.length > 0 ? `${path}/${composeFile}` : ''; + } + return ''; + } + + private extractLabelValue(labels: string, labelKeyPattern: RegExp, defaultValue: string): string { + const splitLabels = labels.split(/,| /); + const projectLabel = splitLabels.find(label => labelKeyPattern.test(label)); + return projectLabel ? projectLabel.split(labelKeyPattern)[2] : defaultValue; } private getComposeGroups(containers: any[]): PodmanItem[] { @@ -293,10 +314,22 @@ export class PodmanTreeDataProvider implements vscode.TreeDataProvider { - const groupItem = new PodmanItem(`Compose Group ${index + 1}: ${project}`, vscode.TreeItemCollapsibleState.Collapsed, 'compose-group', undefined, undefined, undefined, project); - groupItem.children = containers.map((c: any) => + const children = containers.map((c: any) => new PodmanItem(`${c.name} (${c.id})`, vscode.TreeItemCollapsibleState.None, 'compose-container', c.id, c.status, c.isRunning, project) ); + const groupItem = new PodmanItem( + `Compose Group ${index + 1}: ${project}`, + vscode.TreeItemCollapsibleState.Collapsed, + 'compose-group', + undefined, + undefined, + undefined, + project, + children, + undefined, + undefined, + containers[0].composeFile + ); return groupItem; }); }