forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoc.ts
More file actions
66 lines (54 loc) · 2.38 KB
/
Copy pathoc.ts
File metadata and controls
66 lines (54 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { window } from 'vscode';
import { getInstance } from './odo';
import { Command } from './odo/command';
import { clusterRequired } from './openshift/openshiftItem';
import { ToolsConfig } from './tools';
import { vsCommand } from './vscommand';
export class Oc {
private static odo = getInstance();
@vsCommand('openshift.create')
@clusterRequired()
public static async create(): Promise<string | null> {
const document = window.activeTextEditor ? window.activeTextEditor.document : undefined;
const pleaseSave = 'Please save your changes before executing \'OpenShift: Create\' command.';
let message: string;
if (!document
|| !(document.fileName.endsWith('.yaml') || document.fileName.endsWith('.json'))) {
message =
'\'OpenShift: Create\' command requires a .yaml or a .json file opened in editor.';
}
if (!message && document.isUntitled) {
message = pleaseSave;
}
if (!message && document.isDirty) {
const save = 'Save';
const action = await window.showInformationMessage('Editor has unsaved changes.', save);
if (action !== save) {
message = pleaseSave;
} else {
await document.save();
}
}
const activeProject = await Oc.odo.getActiveProject();
if (!message && !activeProject) {
message = '\'OpenShift: Create\' requires setting a project as active, and none is currently set.';
}
let toolLocation: string;
if (!message) {
toolLocation = await ToolsConfig.detect('oc');
if (!toolLocation) {
message = 'Cannot run \'oc create\'. OKD CLI client tool cannot be found.';
}
}
if (message) {
void window.showWarningMessage(message);
return null;
}
await Oc.odo.execute(Command.ocCreate(document.fileName, activeProject));
return 'Resources were successfully created.';
}
}