mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
Added the project list command
Signed-off-by: mdas <mrinald7@gmail.com>
This commit is contained in:
@@ -5,12 +5,17 @@ import (
|
||||
"github.com/redhat-developer/ocdev/pkg/occlient"
|
||||
)
|
||||
|
||||
// ApplicationInfo holds information about one project
|
||||
type ProjectInfo struct {
|
||||
// Name of the project
|
||||
Name string
|
||||
// is this project active?
|
||||
Active bool
|
||||
}
|
||||
|
||||
func GetCurrent(client *occlient.Client) (string, error) {
|
||||
// TODO: use project abstaction
|
||||
project, err := client.GetCurrentProjectName()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "unable to get current project")
|
||||
}
|
||||
project := client.GetCurrentProjectName()
|
||||
|
||||
return project, nil
|
||||
}
|
||||
@@ -30,3 +35,23 @@ func CreateProject(client *occlient.Client, projectName string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ListProjects(client *occlient.Client) ([]ProjectInfo, error) {
|
||||
currentProject := client.GetCurrentProjectName()
|
||||
allProjects, err := client.GetProjectNames()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "cannot get all the projects")
|
||||
}
|
||||
projects := []ProjectInfo{}
|
||||
for _, project := range allProjects {
|
||||
isActive := false
|
||||
if project == currentProject {
|
||||
isActive = true
|
||||
}
|
||||
projects = append(projects, ProjectInfo{
|
||||
Name: project,
|
||||
Active: isActive,
|
||||
})
|
||||
}
|
||||
return projects, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user