Skip to content

Commit

Permalink
Merge pull request #127 from kata-ai/select-project-with-name
Browse files Browse the repository at this point in the history
Able to select project with name
  • Loading branch information
adityapurwa authored Aug 30, 2019
2 parents 7e84dc3 + 3bbdfb5 commit 3d3d483
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 12 deletions.
44 changes: 38 additions & 6 deletions components/projects/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,45 @@ export default class Project {
}
}

public async select() {
const chosen = await this.choose()
if (chosen) {
this.helper.setProp("projectId", chosen.id);
this.helper.setProp("projectName", chosen.name);
console.log(colors.green(`Project "${ chosen.name }" (${ chosen.id }) is successfully selected`));
public async select(projectName?: string) {
let chosen: any;
if (typeof projectName === "string") {
chosen = await this.getDataByName(projectName);
if (chosen !== undefined) {
// project name found
this.helper.setProp("projectId", chosen.id);
this.helper.setProp("projectName", chosen.name);
} else {
// project name not found, select through inquirer
console.log(
`Project with name ${colors.green(projectName)} is not found. ` +
`Please choose listed project name below:`);
chosen = await this.choose()
if (chosen) {
this.helper.setProp("projectId", chosen.id);
this.helper.setProp("projectName", chosen.name);
}
}
} else {
// projectName is empty
chosen = await this.choose()
if (chosen) {
this.helper.setProp("projectId", chosen.id);
this.helper.setProp("projectName", chosen.name);
}
}
console.log(colors.green(`Project "${ chosen.name }" (${ chosen.id }) is successfully selected`));

if (!chosen || chosen === undefined) {
chosen = await this.choose()
if (chosen) {
this.helper.setProp("projectId", chosen.id);
this.helper.setProp("projectName", chosen.name);
console.log(colors.green(`Project "${ chosen.name }" (${ chosen.id }) is successfully selected`));
}
}


}

public async delete(projectName?: string) {
Expand Down
42 changes: 36 additions & 6 deletions lib/components/projects/project.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3d3d483

Please sign in to comment.