mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
Improve project list (#1622)
* Improve project list * fixed repetitive code
This commit is contained in:
committed by
OpenShift Merge Robot
parent
63695c5f0e
commit
5975a3f074
@@ -47,7 +47,7 @@ func (plo *ProjectListOptions) Validate() (err error) {
|
||||
// Run contains the logic for the odo project list command
|
||||
func (plo *ProjectListOptions) Run() (err error) {
|
||||
|
||||
projects, err := project.List(plo.Client)
|
||||
projects, err := project.DescribeProjects(plo.Client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/openshift/odo/pkg/component"
|
||||
componentlabels "github.com/openshift/odo/pkg/component/labels"
|
||||
"github.com/openshift/odo/pkg/odo/genericclioptions"
|
||||
"github.com/openshift/odo/pkg/project"
|
||||
"github.com/openshift/odo/pkg/service"
|
||||
"github.com/openshift/odo/pkg/storage"
|
||||
"github.com/openshift/odo/pkg/url"
|
||||
@@ -167,18 +166,18 @@ var FileCompletionHandler = func(cmd *cobra.Command, args parsedArgs, context *g
|
||||
// ProjectNameCompletionHandler provides project name completion
|
||||
var ProjectNameCompletionHandler = func(cmd *cobra.Command, args parsedArgs, context *genericclioptions.Context) (completions []string) {
|
||||
completions = make([]string, 0)
|
||||
projects, err := project.List(context.Client)
|
||||
projects, err := context.Client.GetProjectNames()
|
||||
if err != nil {
|
||||
return completions
|
||||
}
|
||||
|
||||
for _, project := range projects.Items {
|
||||
for _, project := range projects {
|
||||
// we found the project name in the list which means
|
||||
// that the project name has been already selected by the user so no need to suggest more
|
||||
if args.commands[project.Name] {
|
||||
if args.commands[project] {
|
||||
return nil
|
||||
}
|
||||
completions = append(completions, project.Name)
|
||||
completions = append(completions, project)
|
||||
}
|
||||
return completions
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package project
|
||||
|
||||
import (
|
||||
"github.com/openshift/odo/pkg/application"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/openshift/odo/pkg/application"
|
||||
"github.com/openshift/odo/pkg/log"
|
||||
"github.com/openshift/odo/pkg/occlient"
|
||||
|
||||
@@ -49,7 +49,7 @@ func Delete(client *occlient.Client, projectName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func List(client *occlient.Client) (ProjectList, error) {
|
||||
func DescribeProjects(client *occlient.Client) (ProjectList, error) {
|
||||
currentProject := client.GetCurrentProjectName()
|
||||
allProjects, err := client.GetProjectNames()
|
||||
if err != nil {
|
||||
@@ -74,12 +74,12 @@ func List(client *occlient.Client) (ProjectList, error) {
|
||||
// The first returned parameter is a bool indicating if a project with the given name already exists or not
|
||||
// The second returned parameter is the error that might occurs while execution
|
||||
func Exists(client *occlient.Client, projectName string) (bool, error) {
|
||||
projects, err := List(client)
|
||||
projects, err := client.GetProjectNames()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "unable to get the project list")
|
||||
}
|
||||
for _, project := range projects.Items {
|
||||
if project.Name == projectName {
|
||||
for _, project := range projects {
|
||||
if project == projectName {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user