Skip to content

Commit f0c9a17

Browse files
sudhirvermadgolovin
authored andcommitted
Provide keybinding for Login, push and refresh commands (#835)
1 parent 0146d70 commit f0c9a17

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"onCommand:openshift.component.followLog.palette",
5656
"onCommand:openshift.component.delete",
5757
"onCommand:openshift.component.push",
58+
"onCommand:openshift.component.last.push",
5859
"onCommand:openshift.component.push.palette",
5960
"onCommand:openshift.component.watch",
6061
"onCommand:openshift.component.watch.palette",
@@ -248,6 +249,11 @@
248249
"title": "Push Component",
249250
"category": "OpenShift"
250251
},
252+
{
253+
"command": "openshift.component.last.push",
254+
"title": "Repeat last push command",
255+
"category": "OpenShift"
256+
},
251257
{
252258
"command": "openshift.component.watch",
253259
"title": "Watch",
@@ -345,6 +351,23 @@
345351
"category": "OpenShift"
346352
}
347353
],
354+
"keybindings": [
355+
{
356+
"command": "openshift.explorer.login",
357+
"key": "alt+shift+l",
358+
"mac": "ctrl+shift+l"
359+
},
360+
{
361+
"command": "openshift.explorer.refresh",
362+
"key": "alt+shift+r",
363+
"mac": "ctrl+shift+r"
364+
},
365+
{
366+
"command": "openshift.component.last.push",
367+
"key": "alt+shift+p",
368+
"mac": "ctrl+shift+p"
369+
}
370+
],
348371
"viewsContainers": {
349372
"activitybar": [
350373
{

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export async function activate(context: vscode.ExtensionContext) {
5656
vscode.commands.registerCommand('openshift.component.create.binary', (context) => execute(Component.createFromBinary, context)),
5757
vscode.commands.registerCommand('openshift.component.delete.palette', (context) => execute(Component.del, context)),
5858
vscode.commands.registerCommand('openshift.component.push', (context) => execute(Component.push, context)),
59+
vscode.commands.registerCommand('openshift.component.last.push', (context) => execute(Component.lastPush, context)),
5960
vscode.commands.registerCommand('openshift.component.push.palette', (context) => execute(Component.push, context)),
6061
vscode.commands.registerCommand('openshift.component.watch', (context) => execute(Component.watch, context)),
6162
vscode.commands.registerCommand('openshift.component.watch.palette', (context) => execute(Component.watch, context)),

src/openshift/component.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { V1ServicePort, V1Service } from '@kubernetes/client-node';
1414
import { isURL } from 'validator';
1515
import { Refs, Ref, Type } from '../util/refs';
1616
import { Delayer } from '../util/async';
17+
import { contextGlobalState } from '../extension';
1718

1819
export class Component extends OpenShiftItem {
1920

@@ -148,13 +149,31 @@ export class Component extends OpenShiftItem {
148149
);
149150
}
150151

152+
static getPushCmd(): Thenable< string | undefined> {
153+
return contextGlobalState.globalState.get('PUSH');
154+
}
155+
156+
static setPushCmd(component: string, application: string, project: string): Thenable<void> {
157+
return contextGlobalState.globalState.update('PUSH', Command.pushComponent(project, application, component));
158+
}
159+
151160
static async push(context: OpenShiftObject): Promise<string> {
152161
const component = await Component.getOpenShiftCmdData(context,
153162
"In which Project you want to push the changes",
154163
"In which Application you want to push the changes",
155164
"For which Component you want to push the changes");
156165
if (!component) return null;
157-
Component.odo.executeInTerminal(Command.pushComponent(component.getParent().getParent().getName(), component.getParent().getName(), component.getName()));
166+
Component.setPushCmd(component.getName(), component.getParent().getName(), component.getParent().getParent().getName());
167+
Component.odo.executeInTerminal(Command.pushComponent(component.getParent().getParent().getName(), component.getParent().getName(), component.getName()))
168+
}
169+
170+
static async lastPush() {
171+
const getPushCmd = await Component.getPushCmd();
172+
if (getPushCmd) {
173+
Component.odo.executeInTerminal(getPushCmd);
174+
} else {
175+
throw Error('No existing push command found');
176+
}
158177
}
159178

160179
static async watch(context: OpenShiftObject): Promise<void> {

test/openshift/component.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as Util from '../../src/util/async';
1717
import { Refs } from '../../src/util/refs';
1818
import { OpenShiftItem } from '../../src/openshift/openshiftItem';
1919
import pq = require('proxyquire');
20+
import { contextGlobalState } from '../../src/extension';
2021

2122
const expect = chai.expect;
2223
chai.use(sinonChai);
@@ -664,12 +665,15 @@ suite('OpenShift/Component', () => {
664665
});
665666

666667
suite('push', () => {
668+
let getpushStub;
667669

668670
setup(() => {
669671
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
670672
quickPickStub.onFirstCall().resolves(projectItem);
671673
quickPickStub.onSecondCall().resolves(appItem);
672674
quickPickStub.onThirdCall().resolves(componentItem);
675+
getpushStub = sandbox.stub(Component, 'getPushCmd').resolves(undefined);
676+
sandbox.stub(Component, 'setPushCmd');
673677
});
674678

675679
test('returns null when cancelled', async () => {
@@ -690,6 +694,13 @@ suite('OpenShift/Component', () => {
690694

691695
expect(termStub).calledOnceWith(Command.pushComponent(projectItem.getName(), appItem.getName(), componentItem.getName()));
692696
});
697+
698+
test('works from keybinding', async () => {
699+
getpushStub.resolves(`odo push ${componentItem.getName()} --app ${appItem.getName()} --project ${projectItem.getName()}`);
700+
await Component.push(null);
701+
702+
expect(termStub).calledOnceWith(Command.pushComponent(projectItem.getName(), appItem.getName(), componentItem.getName()));
703+
});
693704
});
694705

695706
suite('watch', () => {

0 commit comments

Comments
 (0)