Added the project list command

Signed-off-by: mdas <mrinald7@gmail.com>
This commit is contained in:
mdas
2018-03-23 16:57:02 +05:30
parent 86c7086dcb
commit 44cec00531
6 changed files with 111 additions and 83 deletions

View File

@@ -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
}