-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathcommand.ts
105 lines (93 loc) · 3.65 KB
/
command.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { CommandOption, CommandText, verbose } from '../base/command';
export class Command {
static deploy(): CommandText {
return new CommandText('odo', 'deploy');
}
static undeploy(name?: string): CommandText {
const command = new CommandText('odo', 'delete component');
if (name) {
command.addOption(new CommandOption('--name', name));
}
return command;
}
static dev(debug: boolean, runOn?: 'podman', manualRebuild: boolean = false): CommandText {
const command = new CommandText('odo', 'dev');
if (debug) {
command.addOption(new CommandOption('--debug'));
}
if (runOn) {
command.addOption(new CommandOption('--platform', 'podman'));
command.addOption(new CommandOption('--forward-localhost'));
}
if (manualRebuild) {
command.addOption(new CommandOption('--no-watch'));
}
return command;
}
static printOdoVersion(): CommandText {
return new CommandText('odo', 'version');
}
static describeComponent(): CommandText {
return new CommandText('odo', 'describe component');
}
static describeComponentJson(): CommandText {
return Command.describeComponent().addOption(new CommandOption('-o', 'json', false));
}
static showLog(platform?: string): CommandText {
const result = new CommandText('odo', 'logs', [
new CommandOption('--dev'),
]);
if (platform) {
result.addOption(new CommandOption('--platform', platform));
}
return result;
}
static showLogAndFollow(platform?: string): CommandText {
return Command.showLog(platform).addOption(new CommandOption('--follow'));
}
@verbose
static createLocalComponent(
devfileType = '', // will use empty string in case of undefined devfileType passed in
devfileVersion: string = undefined,
registryName: string,
name: string,
portNumber: number,
starter: string = undefined,
useExistingDevfile = false,
customDevfilePath = ''
): CommandText {
const cTxt = new CommandText('odo', 'init', [
new CommandOption('--name', name)
]
);
if (devfileType !== '') {
cTxt.addOption(new CommandOption('--devfile', devfileType));
}
if (devfileVersion) {
cTxt.addOption(new CommandOption('--devfile-version', devfileVersion, false));
}
if (registryName) {
cTxt.addOption(new CommandOption('--devfile-registry', registryName));
}
if (starter) {
cTxt.addOption(new CommandOption('--starter', starter, false));
}
if (useExistingDevfile && customDevfilePath.length === 0) {
cTxt.addOption(new CommandOption('--devfile-path', 'devfile.yaml', false));
}
if (customDevfilePath.length > 0) {
cTxt.addOption(new CommandOption('--devfile-path', customDevfilePath, false));
}
if (portNumber) {
cTxt.addOption(new CommandOption(' --run-port', portNumber.toString(), false));
}
return cTxt;
}
static runComponentCommand(commandId : string): CommandText {
return new CommandText('odo', `run ${commandId}`);
}
}