Skip to content

Commit 132dc1a

Browse files
committed
Replace starter:boolean to starter:string in odo create command
This PR related to #1855. It allows to create component with specific starter project if there are many for selected devfile component type Signed-off-by: Denis Golovin dgolovin@redhat.com
1 parent dfdf99c commit 132dc1a

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/odo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export interface Odo {
354354
createApplication(application: OpenShiftObject): Promise<OpenShiftObject>;
355355
deleteApplication(application: OpenShiftObject): Promise<OpenShiftObject>;
356356
createComponentFromGit(application: OpenShiftObject, type: string, version: string, name: string, repoUri: string, context: Uri, ref: string): Promise<OpenShiftObject>;
357-
createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, path: Uri, starter?: boolean, useExistingDevfile?: boolean): Promise<OpenShiftObject>;
357+
createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, path: Uri, starterName?: string, useExistingDevfile?: boolean): Promise<OpenShiftObject>;
358358
createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, path: Uri, context: Uri): Promise<OpenShiftObject>;
359359
deleteComponent(component: OpenShiftObject): Promise<OpenShiftObject>;
360360
undeployComponent(component: OpenShiftObject): Promise<OpenShiftObject>;
@@ -894,7 +894,7 @@ export class OdoImpl implements Odo {
894894
return application;
895895
}
896896

897-
public async createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, location: Uri, starter = false, useExistingDevfile = false): Promise<OpenShiftObject> {
897+
public async createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, location: Uri, starter: string = undefined, useExistingDevfile = false): Promise<OpenShiftObject> {
898898
await this.execute(Command.createLocalComponent(application.getParent().getName(), application.getName(), type, version, name, location.fsPath, starter, useExistingDevfile), location.fsPath);
899899
if (workspace.workspaceFolders) {
900900
const targetApplication = (await this.getApplications(application.getParent())).find((value) => value === application);

src/odo/command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ export class Command {
220220
version: string,
221221
name: string,
222222
folder: string,
223-
starter: boolean,
223+
starter: string = undefined,
224224
useExistingDevfile = false
225225
): string {
226-
return `odo create ${type}${version?':':''}${version?version:''} ${name} ${version?'--s2i':''} --context ${folder} --app ${app} --project ${project}${starter ? ' --starter' : ''}${useExistingDevfile ? ' --devfile devfile.yaml' : ''}`;
226+
return `odo create ${type}${version?':':''}${version?version:''} ${name} ${version?'--s2i':''} --context ${folder} --app ${app} --project ${project}${starter ? ` --starter=${starter}` : ''}${useExistingDevfile ? ' --devfile devfile.yaml' : ''}`;
227227
}
228228

229229
@verbose

src/openshift/component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ export class Component extends OpenShiftItem {
591591

592592
if (!componentName) return null;
593593

594-
let createStarter = false;
594+
let createStarter: string;
595595
let componentType: ComponentTypeAdapter;
596596
if (!useExistingDevfile) {
597597
const componentTypes = Component.odo.getComponentTypes();
@@ -611,8 +611,10 @@ export class Component extends OpenShiftItem {
611611
const descr = await this.odo.execute(Command.describeCatalogComponent(componentType.name));
612612
const starterProjects: StarterProjectDescription[] =this.odo.loadItems<StarterProjectDescription>(descr,(data:{Data:ComponentDescription})=>data.Data.starterProjects);
613613
if(starterProjects?.length && starterProjects?.length > 0) {
614-
const create = await window.showQuickPick(['Yes', 'No'] , {placeHolder: 'Initialize Component using default Starter Project?'});
615-
createStarter = create === 'Yes';
614+
const create = await window.showQuickPick(['Yes', 'No'] , {placeHolder: `Initialize Component using '${starterProjects[0].name}' Starter Project?`});
615+
if (create === 'Yes') {
616+
createStarter = starterProjects[0].name;
617+
};
616618
}
617619
}
618620
}
@@ -907,7 +909,7 @@ export class Component extends OpenShiftItem {
907909
const gitRef = bcJson.spec.source.git.ref || 'master';
908910
await Component.odo.execute(Command.createGitComponent(prjName, appName, compTypeName, compTypeVersion, compName, gitUrl, gitRef), workspaceFolder.fsPath);
909911
} else { // componentType === ComponentType.Local
910-
await Component.odo.execute(Command.createLocalComponent(prjName, appName, componentJson.metadata.labels['app.kubernetes.io/name'], componentJson.metadata.labels['app.openshift.io/runtime-version'], compName, workspaceFolder.fsPath, false));
912+
await Component.odo.execute(Command.createLocalComponent(prjName, appName, componentJson.metadata.labels['app.kubernetes.io/name'], componentJson.metadata.labels['app.openshift.io/runtime-version'], compName, workspaceFolder.fsPath));
911913
}
912914
// import storage if present
913915
if (componentJson.spec.template.spec.containers[0].volumeMounts) {

test/unit/openshift/component.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ suite('OpenShift/Component', () => {
142142
expect(result).equals(`Component '${componentItem.getName()}' successfully created. To deploy it on cluster, perform 'Push' action.`);
143143
expect(progressFunctionStub).calledOnceWith(
144144
`Creating new Component '${componentItem.getName()}'`);
145-
expect(execStub).calledWith(Command.createLocalComponent(appItem.getParent().getName(), appItem.getName(), componentType.name, version, componentItem.getName(), folder.uri.fsPath, false));
145+
expect(execStub).calledWith(Command.createLocalComponent(appItem.getParent().getName(), appItem.getName(), componentType.name, version, componentItem.getName(), folder.uri.fsPath));
146146
});
147147

148148
test('returns null when no option is selected from quick pick', async () => {

0 commit comments

Comments
 (0)