Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Run Che command in selected container
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
  • Loading branch information
mmorhun committed Sep 25, 2019
1 parent 04b3b46 commit 2494b2a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
13 changes: 11 additions & 2 deletions plugins/containers-plugin/src/containers-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { ContainersTreeDataProvider } from './containers-tree-data-provider';
import { ContainersService } from './containers-service';
import * as theia from '@theia/plugin';
import { ContainersService } from './containers-service';
import {
ContainersTreeDataProvider,
CONTAINERS_PLUGIN_RUN_TASK_COMMAND_ID,
containersTreeTaskLauncherCommandHandler
} from './containers-tree-data-provider';

export function start(context: theia.PluginContext) {
const treeDataProvider = new ContainersTreeDataProvider();
Expand All @@ -28,6 +32,11 @@ export function start(context: theia.PluginContext) {
console.error(error);
theia.window.showErrorMessage(error);
});

const containersTreeTaskLauncherCommand = { id: CONTAINERS_PLUGIN_RUN_TASK_COMMAND_ID };
context.subscriptions.push(
theia.commands.registerCommand(containersTreeTaskLauncherCommand, containersTreeTaskLauncherCommandHandler)
);
}

export function stop() {
Expand Down
29 changes: 28 additions & 1 deletion plugins/containers-plugin/src/containers-tree-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ export class ContainersTreeDataProvider implements theia.TreeDataProvider<ITreeN
name: command.commandName,
tooltip: command.commandLine,
iconPath: 'fa-cogs medium-yellow',
command: { id: 'task:run', arguments: [this.getRootPath(), command.commandName] }
command: {
id: CONTAINERS_PLUGIN_RUN_TASK_COMMAND_ID,
arguments: [this.getRootPath(), command.commandName, container.name]
}
});
});
}
Expand Down Expand Up @@ -267,3 +270,27 @@ export class ContainersTreeDataProvider implements theia.TreeDataProvider<ITreeN
}
}
}

export const CONTAINERS_PLUGIN_RUN_TASK_COMMAND_ID = 'containers-plugin-run-task';
/**
* Command handler which is invoked when a user clicks on a task in the Workspace panel.
* This is needed if a command doesn't have container to be run in specified.
* In such case we run the command in the container under which this command was clicked.
*/
export async function containersTreeTaskLauncherCommandHandler(source: string, label: string, containerName: string): Promise<void> {
const tasks: theia.Task[] = await theia.tasks.fetchTasks({ type: 'che' });
for (const task of tasks) {
if (task.name === label && task.source === source) {
if (!task.definition.target) {
task.definition.target = {};
}
task.definition.target.containerName = containerName;

theia.tasks.executeTask(task);
return;
}
}

// Shouldn't happen. Fallback to default behaviour.
theia.commands.executeCommand('task:run', source, label);
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8270,9 +8270,9 @@ move-concurrently@^1.0.1:
rimraf "^2.5.4"
run-queue "^1.0.3"

"moxios@git://github.com/stoplightio/moxios.git#v1.3.0":
"moxios@git://github.com/stoplightio/moxios#v1.3.0":
version "1.3.0"
resolved "git://github.com/stoplightio/moxios.git#9d702c8eafee4b02917d6bc400ae15f1e835cf51"
resolved "git://github.com/stoplightio/moxios#9d702c8eafee4b02917d6bc400ae15f1e835cf51"
dependencies:
class-autobind "^0.1.4"

Expand Down

0 comments on commit 2494b2a

Please sign in to comment.