-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds
odo create project -o json
output (#1916)
Adds machine readable output for odo create project. To test: ```sh odo create project -o json ```
- Loading branch information
1 parent
a27225d
commit 387145f
Showing
6 changed files
with
184 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package machineoutput | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/openshift/odo/pkg/log" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// Kind is what kind we should use in the machine readable output | ||
const Kind = "Error" | ||
|
||
// APIVersion is the current API version we are using | ||
const APIVersion = "odo.openshift.io/v1alpha1" | ||
|
||
// Error for machine readable output error messages | ||
type Error struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// Success same as above, but copy-and-pasted just in case | ||
// we change the output in the future | ||
type Success struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// OutputSuccess outputs a "successful" machine-readable output format in json | ||
func OutputSuccess(machineOutput Success) { | ||
printableOutput, err := json.Marshal(machineOutput) | ||
|
||
// If we error out... there's no way to output it (since we disable logging when using -o json) | ||
if err != nil { | ||
fmt.Fprintf(log.GetStderr(), "Unable to unmarshal JSON: %s\n", err.Error()) | ||
} else { | ||
fmt.Fprintf(log.GetStdout(), "%s\n", string(printableOutput)) | ||
} | ||
} | ||
|
||
// OutputError outputs a "successful" machine-readable output format in json | ||
func OutputError(machineOutput Error) { | ||
printableOutput, err := json.Marshal(machineOutput) | ||
|
||
// If we error out... there's no way to output it (since we disable logging when using -o json) | ||
if err != nil { | ||
fmt.Fprintf(log.GetStderr(), "Unable to unmarshal JSON: %s\n", err.Error()) | ||
} else { | ||
fmt.Fprintf(log.GetStderr(), "%s\n", string(printableOutput)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters