Skip to content

Commit dc9b8fd

Browse files
committed
OpenShift: Create command implementation (1)
Fix #1268.
1 parent c4443eb commit dc9b8fd

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"onView:extension.vsKubernetesExplorer",
4040
"onCommand:openshift.about",
4141
"onCommand:openshift.output",
42+
"onCommand:openshift.create",
4243
"onCommand:openshift.openshiftConsole.palette",
4344
"onCommand:openshift.explorer.login",
4445
"onCommand:openshift.explorer.login.credentialsLogin",
@@ -117,6 +118,11 @@
117118
"title": "About",
118119
"category": "OpenShift"
119120
},
121+
{
122+
"command": "openshift.create",
123+
"title": "Create",
124+
"category": "OpenShift"
125+
},
120126
{
121127
"command": "clusters.openshift.build.start",
122128
"title": "Start Build",

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { OdoImpl } from './odo';
2727
import { Build } from './k8s/build';
2828
import { DeploymentConfig } from './k8s/deployment';
2929
import { TokenStore } from './util/credentialManager';
30+
import * as Oc from './oc';
3031

3132
let clusterExplorer: k8s.ClusterExplorerV1 | undefined = undefined;
3233

@@ -35,6 +36,7 @@ export async function activate(context: vscode.ExtensionContext) {
3536
Cluster.extensionContext = Component.extensionContext = TokenStore.extensionContext = context;
3637
const disposable = [
3738
vscode.commands.registerCommand('openshift.about', (context) => execute(Cluster.about, context)),
39+
vscode.commands.registerCommand('openshift.create', (context) => execute(Oc.create, context)),
3840
vscode.commands.registerCommand('openshift.output', (context) => execute(Cluster.showOpenShiftOutput, context)),
3941
vscode.commands.registerCommand('openshift.openshiftConsole', (context) => execute(Cluster.openshiftConsole, context)),
4042
vscode.commands.registerCommand('openshift.openshiftConsole.palette', (context) => execute(Cluster.openshiftConsole, context)),

src/oc.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*-----------------------------------------------------------------------------------------------
2+
* Copyright (c) Red Hat, Inc. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4+
*-----------------------------------------------------------------------------------------------*/
5+
6+
import { window } from 'vscode';
7+
import { Cli } from './cli';
8+
import { ToolsConfig } from './tools';
9+
import { OpenShiftItem } from './openshift/openshiftItem';
10+
11+
export async function create() {
12+
const document = window.activeTextEditor ? window.activeTextEditor.document : undefined;
13+
const pleaseSave = 'Please save your changes before executing \'OpenShift: Create\' command.';
14+
let message: string;
15+
if (document) {
16+
if (document.isUntitled) {
17+
message = pleaseSave;
18+
}
19+
20+
if (!message && document.isDirty) {
21+
const save = 'Save';
22+
const action = await window.showInformationMessage('Editor has unsaved changes', save);
23+
if (action !== save) {
24+
message = pleaseSave;
25+
} else {
26+
await document.save();
27+
}
28+
}
29+
30+
if (message) {
31+
window.showWarningMessage(message);
32+
} else {
33+
const project = await OpenShiftItem.getOpenShiftCmdData(undefined, 'Select a Project where to create new resource');
34+
const toolLocation = await ToolsConfig.detectOrDownload('oc');
35+
const result = await Cli.getInstance().execute(`${toolLocation} create -f ${document.fileName} --namespace ${project.getName()}`);
36+
if (result.error) {
37+
throw result.error;
38+
} else {
39+
return 'Resources were successfully created.';
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)