Adds odo create project -o json output (#1916)

Adds machine readable output for odo create project.

To test:

```sh
odo create project -o json
```
This commit is contained in:
Charlie Drage
2019-08-22 13:04:07 -04:00
committed by OpenShift Merge Robot
parent a27225d9e6
commit 387145f5bc
6 changed files with 184 additions and 35 deletions

View File

@@ -2,6 +2,7 @@ package project
import (
"github.com/openshift/odo/pkg/application"
"github.com/openshift/odo/pkg/machineoutput"
"github.com/pkg/errors"
"github.com/openshift/odo/pkg/log"
@@ -82,26 +83,45 @@ func Exists(client *occlient.Client, projectName string) (bool, error) {
return true, nil
}
// GetMachineReadableFormat gathers the readable format and output a Project struct
// for json to marshal
func GetMachineReadableFormat(projectName string, isActive bool, apps []string) Project {
return Project{
TypeMeta: metav1.TypeMeta{
Kind: "Project",
APIVersion: "odo.openshift.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: projectName,
Name: projectName,
Namespace: projectName,
},
Spec: ProjectSpec{
Applications: apps,
},
Status: ProjectStatus{
Active: isActive,
},
}
}
// MachineReadableSuccessOutput outputs a success output that includes
// project information and namespace
func MachineReadableSuccessOutput(projectName string, message string) {
machineOutput := machineoutput.Success{
TypeMeta: metav1.TypeMeta{
Kind: "Project",
APIVersion: "odo.openshift.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: projectName,
Namespace: projectName,
},
Message: message,
}
machineoutput.OutputSuccess(machineOutput)
}
// getMachineReadableFormatForList returns application list in machine readable format
func getMachineReadableFormatForList(projects []Project) ProjectList {
return ProjectList{