move ComposeResult type into common package to allow its reusing
This commit is contained in:
parent
642b90c977
commit
a43dd00459
2 changed files with 8 additions and 7 deletions
72
internal/common/compose_result.go
Normal file
72
internal/common/compose_result.go
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ComposeResult struct {
|
||||
TreeID string `json:"tree_id"`
|
||||
OutputID string `json:"output_id"`
|
||||
Build *struct {
|
||||
Stages []struct {
|
||||
Name string `json:"name"`
|
||||
Options json.RawMessage `json:"options"`
|
||||
Success bool `json:"success"`
|
||||
Output string `json:"output"`
|
||||
} `json:"stages"`
|
||||
TreeID string `json:"tree_id"`
|
||||
Success bool `json:"success"`
|
||||
} `json:"build"`
|
||||
Stages []struct {
|
||||
Name string `json:"name"`
|
||||
Options json.RawMessage `json:"options"`
|
||||
Success bool `json:"success"`
|
||||
Output string `json:"output"`
|
||||
} `json:"stages"`
|
||||
Assembler *struct {
|
||||
Name string `json:"name"`
|
||||
Options json.RawMessage `json:"options"`
|
||||
Success bool `json:"success"`
|
||||
Output string `json:"output"`
|
||||
} `json:"assembler"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
func (cr *ComposeResult) Write(writer io.Writer) {
|
||||
if cr.Build == nil && len(cr.Stages) == 0 && cr.Assembler == nil {
|
||||
fmt.Fprintf(writer, "The compose result is empty.\n")
|
||||
}
|
||||
|
||||
if cr.Build != nil {
|
||||
fmt.Fprintf(writer, "Build pipeline:\n")
|
||||
|
||||
for _, stage := range cr.Build.Stages {
|
||||
fmt.Fprintf(writer, "Stage %s\n", stage.Name)
|
||||
enc := json.NewEncoder(writer)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(stage.Options)
|
||||
fmt.Fprintf(writer, "\nOutput:\n%s\n", stage.Output)
|
||||
}
|
||||
}
|
||||
|
||||
if len(cr.Stages) > 0 {
|
||||
fmt.Fprintf(writer, "Stages:\n")
|
||||
for _, stage := range cr.Stages {
|
||||
fmt.Fprintf(writer, "Stage: %s\n", stage.Name)
|
||||
enc := json.NewEncoder(writer)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(stage.Options)
|
||||
fmt.Fprintf(writer, "\nOutput:\n%s\n", stage.Output)
|
||||
}
|
||||
}
|
||||
|
||||
if cr.Assembler != nil {
|
||||
fmt.Fprintf(writer, "Assembler %s:\n", cr.Assembler.Name)
|
||||
enc := json.NewEncoder(writer)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(cr.Assembler.Options)
|
||||
fmt.Fprintf(writer, "\nOutput:\n%s\n", cr.Assembler.Output)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue