Skip to content

Commit

Permalink
Add context menu options to run components without watching for changes
Browse files Browse the repository at this point in the history
Closes redhat-developer#2589

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Oct 18, 2023
1 parent 5ba235c commit 1b65009
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
34 changes: 31 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@
"title": "Start Dev",
"category": "OpenShift"
},
{
"command": "openshift.component.dev.manual",
"title": "Start Dev (manually trigger rebuild)",
"category": "OpenShift"
},
{
"command": "openshift.component.binding.add",
"title": "Bind Service",
Expand Down Expand Up @@ -744,6 +749,11 @@
"title": "Start Dev on Podman",
"category": "OpenShift"
},
{
"command": "openshift.component.dev.onPodman.manual",
"title": "Start Dev on Podman (manually trigger rebuild)",
"category": "OpenShift"
},
{
"command": "openshift.component.deleteConfigurationFiles",
"title": "Delete Component Configuration",
Expand Down Expand Up @@ -1093,10 +1103,18 @@
"command": "openshift.component.dev",
"when": "false"
},
{
"command": "openshift.component.dev.manual",
"when": "false"
},
{
"command": "openshift.component.dev.onPodman",
"when": "false"
},
{
"command": "openshift.component.dev.onPodman.manual",
"when": "false"
},
{
"command": "openshift.component.deploy",
"when": "false"
Expand Down Expand Up @@ -1542,19 +1560,29 @@
"group": "c1@1"
},
{
"command": "openshift.component.dev.onPodman",
"command": "openshift.component.dev.manual",
"when": "view == openshiftComponentsView && viewItem =~ /openshift\\.component.*\\.dev-nrn.*/",
"group": "c1@2"
},
{
"command": "openshift.component.dev.onPodman",
"when": "view == openshiftComponentsView && viewItem =~ /openshift\\.component.*\\.dev-nrn.*/",
"group": "c1@3"
},
{
"command": "openshift.component.dev.onPodman.manual",
"when": "view == openshiftComponentsView && viewItem =~ /openshift\\.component.*\\.dev-nrn.*/",
"group": "c1@4"
},
{
"command": "openshift.component.exitDevMode",
"when": "view == openshiftComponentsView && viewItem =~ /openshift\\.component.*\\.dev-(?:str)|(?:run).*/",
"group": "c1@3"
"group": "c1@5"
},
{
"command": "openshift.component.forceExitDevMode",
"when": "view == openshiftComponentsView && viewItem =~ /openshift\\.component.*\\.dev-stp.*/",
"group": "c1@4"
"group": "c1@6"
},
{
"command": "openshift.component.deploy",
Expand Down
5 changes: 4 additions & 1 deletion src/odo/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Command {
return command;
}

static dev(debug: boolean, runOn?: undefined | 'podman'): CommandText {
static dev(debug: boolean, runOn?: undefined | 'podman', manualRebuild: boolean = false): CommandText {
const command = new CommandText('odo', 'dev');
if (debug) {
command.addOption(new CommandOption('--debug'));
Expand All @@ -28,6 +28,9 @@ export class Command {
command.addOption(new CommandOption('--platform', 'podman'));
command.addOption(new CommandOption('--forward-localhost'));
}
if (manualRebuild) {
command.addOption(new CommandOption('--no-watch'));
}
return command;
}

Expand Down
27 changes: 23 additions & 4 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,29 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.dev.onPodman')
static async devOnPodman(component: ComponentWorkspaceFolder) {
if (await Component.odo.isPodmanPresent()) {
if (await Component.checkForPodman()) {
return Component.devRunOn(component, 'podman');
}
}

@vsCommand('openshift.component.dev.onPodman.manual')
static async devOnPodmanManualRebuild(component: ComponentWorkspaceFolder) {
if (await Component.checkForPodman()) {
return Component.devRunOn(component, 'podman', true);
}
}

private static async checkForPodman(): Promise<boolean> {
if (await Component.odo.isPodmanPresent()) {
return true;
}
void window.showErrorMessage('Podman is not present in the system, please install podman on your machine and try again.', 'Install podman')
.then(async (result) => {
if (result === 'Install podman') {
await commands.executeCommand('vscode.open', Uri.parse('https://podman.io/'));
}
});
return;
return false;
}

@vsCommand('openshift.component.binding.add')
Expand Down Expand Up @@ -292,7 +305,13 @@ export class Component extends OpenShiftItem {
return Component.devRunOn(component, undefined);
}

static async devRunOn(component: ComponentWorkspaceFolder, runOn?: undefined | 'podman') {
@vsCommand('openshift.component.dev.manual')
@clusterRequired()
static async devManual(component: ComponentWorkspaceFolder): Promise<void> {
await Component.devRunOn(component, undefined, true);
}

static async devRunOn(component: ComponentWorkspaceFolder, runOn?: undefined | 'podman', manualRebuild: boolean = false) {
const cs = Component.getComponentDevState(component);
cs.devStatus = ComponentContextState.DEV_STARTING;
cs.runOn = runOn;
Expand All @@ -306,7 +325,7 @@ export class Component extends OpenShiftItem {
}
try {
cs.devTerminal = await OpenShiftTerminalManager.getInstance().createTerminal(
Command.dev(component.component.devfileData.supportedOdoFeatures.debug, runOn),
Command.dev(component.component.devfileData.supportedOdoFeatures.debug, runOn, manualRebuild),
`odo dev: ${component.component.devfileData.devfile.metadata.name}`,
component.contextPath,
process.env,
Expand Down

0 comments on commit 1b65009

Please sign in to comment.