Skip to content

Commit 0a13cc3

Browse files
committed
Fix how arguments are handled for commands running in terminal
Fixes #3320 Signed-off-by: David Thompson <[email protected]>
1 parent 39f361f commit 0a13cc3

File tree

15 files changed

+111
-96
lines changed

15 files changed

+111
-96
lines changed

src/base/command.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ export class CommandText {
5353
this.options.push(option);
5454
return this;
5555
}
56+
57+
get args(): string[] {
58+
const parameterSectionArgs = this.parameter.split(' ');
59+
60+
return [
61+
...parameterSectionArgs,
62+
...this.options.map(opt => opt.toString())
63+
];
64+
}
5665
}
5766

5867
// eslint-disable-next-line @typescript-eslint/ban-types
@@ -73,4 +82,4 @@ export function verbose(_: unknown, key: string, descriptor: TypedPropertyDescri
7382
const command = fn.apply(this, args) as CommandText;
7483
return v > 0 ? command.addOption(new CommandOption('-v', `${v}`)) : command;
7584
};
76-
}
85+
}

src/helm/helmCommands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
import { CommandOption, CommandText } from '../base/command';
77

88
export function addHelmRepo(): CommandText {
9-
return new CommandText('helm repo add openshift https://charts.openshift.io/');
9+
return new CommandText('helm', 'repo add openshift https://charts.openshift.io/');
1010
}
1111

1212
export function updateHelmRepo(): CommandText {
13-
return new CommandText('helm repo update');
13+
return new CommandText('helm', 'repo update');
1414
}
1515

1616
export function installHelmChart(name: string, chartName: string, version: string): CommandText {
1717
return new CommandText('helm', `install ${name} openshift/${chartName}`, [new CommandOption('--version', version)]);
1818
}
1919

2020
export function unInstallHelmChart(name: string): CommandText {
21-
return new CommandText(`helm uninstall ${name}`);
21+
return new CommandText('helm', `uninstall ${name}`);
2222
}
2323

2424
export function listHelmReleases(): CommandText {

src/k8s/build.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as common from './common';
1515
export class Build {
1616
public static command = {
1717
getAllBuilds(parent: ClusterExplorerV1.ClusterExplorerNode): CommandText {
18-
return new CommandText('get build', undefined, [
18+
return new CommandText('oc', 'get build', [
1919
new CommandOption(
2020
'-o',
2121
`jsonpath="{range .items[?(.metadata.labels.buildconfig=='${
@@ -25,30 +25,30 @@ export class Build {
2525
]);
2626
},
2727
startBuild(buildConfig: string): CommandText {
28-
return new CommandText('oc start-build', buildConfig);
28+
return new CommandText('oc', `start-build ${buildConfig}`);
2929
},
3030
getBuilds(build: string): CommandText {
31-
return new CommandText('oc get build', undefined, [
31+
return new CommandText('oc', 'get build', [
3232
new CommandOption('-l', `buildconfig=${build}`),
3333
new CommandOption('-o', 'json', false),
3434
]);
3535
},
3636
showLog(build: string, text: string): CommandText {
37-
return new CommandText('oc logs', `${build}${text}`);
37+
return new CommandText('oc', `logs ${build}${text}`);
3838
},
3939
rebuildFrom(resourceId: string): CommandText {
40-
return new CommandText('oc start-build', undefined, [
40+
return new CommandText('oc', 'start-build', [
4141
new CommandOption('--from-build', resourceId),
4242
]);
4343
},
4444
followLog(build: string, text: string): CommandText {
45-
return new CommandText('oc logs', `${build}${text}`, [new CommandOption('-f')]);
45+
return new CommandText('oc', `logs ${build}${text}`, [new CommandOption('-f')]);
4646
},
4747
delete(build: string): CommandText {
48-
return new CommandText('oc delete build', build);
48+
return new CommandText('oc', `delete build ${build}`);
4949
},
5050
getBuildConfigs(): CommandText {
51-
return new CommandText('oc get buildConfig -o json');
51+
return new CommandText('oc', 'get buildConfig -o json');
5252
},
5353
};
5454

src/k8s/common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { QuickPickItem, window } from 'vscode';
77

88
import * as k8s from 'vscode-kubernetes-tools-api';
99
import { CommandOption, CommandText } from '../base/command';
10+
import { CliChannel } from '../cli';
1011
import { VsCommandError } from '../vscommand';
1112
import { Node } from './node';
12-
import { CliChannel } from '../cli';
1313

1414
export const Command = {
1515
getResourceList(name: string) {
16-
return new CommandText('oc get', name , [ new CommandOption('-o', 'json')]);
16+
return new CommandText('oc', `get ${name}`, [ new CommandOption('-o', 'json')]);
1717
}
1818
}
1919

@@ -76,4 +76,4 @@ export function loadItems<I>(json: string, fetch: (data) => I[] = (data): I[] =>
7676
// ignore parse errors and return empty array
7777
}
7878
return data;
79-
}
79+
}

src/k8s/deployment.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
55

6-
import { CommandText, CommandOption } from '../base/command';
6+
import { CommandOption, CommandText } from '../base/command';
77

88
export const Command = {
99
delete(name: string): CommandText {
@@ -15,17 +15,17 @@ export const Command = {
1515
// present in namespace
1616
// TODO: Parse the deployment description, get the hooks and delete them
1717
// ignoring the possible errors
18-
return new CommandText('oc delete',
19-
'all', [
18+
return new CommandText('oc',
19+
'delete all', [
2020
new CommandOption('-l', `app.kubernetes.io/component=${name}`, true, true),
2121
new CommandOption('--wait=true'),
2222
new CommandOption('--cascade=true')
2323
]
2424
);
2525
},
2626
get(): CommandText {
27-
return new CommandText('oc get',
28-
'deployments', [
27+
return new CommandText('oc',
28+
'get deployments', [
2929
new CommandOption('-o', 'json')
3030
]
3131
);

src/k8s/deploymentConfig.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@ export class DeploymentConfig {
1616

1717
public static command = {
1818
getReplicationControllers(parent: ClusterExplorerV1.ClusterExplorerNode): CommandText {
19-
return new CommandText('get rc',
20-
undefined, [
19+
return new CommandText('oc', 'get rc',
20+
[
2121
new CommandOption('-o', `jsonpath="{range .items[?(.metadata.annotations.openshift\\.io/deployment-config\\.name=='${(parent as any).name}')]}{.metadata.namespace}{','}{.metadata.name}{','}{.metadata.annotations.openshift\\.io/deployment-config\\.latest-version}{\\"\\n\\"}{end}"`)
2222
]
2323
);
2424
},
2525
deploy(build: string): CommandText {
26-
return new CommandText('oc rollout latest', `dc/${build}`);
26+
return new CommandText('oc', `rollout latest dc/${build}`);
2727
},
2828
getDeploymentConfigs(): CommandText {
29-
return new CommandText('oc get deploymentConfig -o json');
29+
return new CommandText('oc', 'get deploymentConfig -o json');
3030
},
3131
getDeploymentFunctions(): CommandText {
32-
return new CommandText('func list -o json');
32+
return new CommandText('func', 'list -o json');
3333
},
3434
showDeploymentConfigLog(deploymentConfig: string): CommandText {
35-
return new CommandText('oc logs', `dc/${deploymentConfig}`);
35+
return new CommandText('oc', `logs dc/${deploymentConfig}`);
3636
},
3737
getReplicas(deploymentConfig: string): CommandText {
38-
return new CommandText('oc get rc', undefined, [
38+
return new CommandText('oc', 'get rc', [
3939
new CommandOption('-o', `jsonpath="{range .items[?(.metadata.annotations.openshift\\.io/deployment-config\\.name=='${deploymentConfig}')]}{.metadata.name}{\\"\\n\\"}{end}"`)
4040
]);
4141
},
4242
delete(replica: string): CommandText {
43-
return new CommandText('oc delete rc',replica);
43+
return new CommandText('oc', `delete rc ${replica}`);
4444
},
4545
showLog(replica: string): CommandText {
46-
return new CommandText('oc logs', `rc/${replica}`);
46+
return new CommandText('oc', `logs rc/${replica}`);
4747
}
4848
};
4949

0 commit comments

Comments
 (0)