56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
func (a App) repairSessionExport(pos []string, call func(protocol.Message) (protocol.Message, error), jsonOutput bool) error {
|
|
if len(pos) != 2 {
|
|
return fmt.Errorf("repair-session-export requires RUN_ID SEQUENCE")
|
|
}
|
|
id, err := strconv.ParseInt(pos[0], 10, 64)
|
|
if err != nil || id <= 0 {
|
|
return fmt.Errorf("run ID must be positive")
|
|
}
|
|
sequence, err := strconv.Atoi(pos[1])
|
|
if err != nil || sequence <= 0 {
|
|
return fmt.Errorf("sequence must be positive")
|
|
}
|
|
response, err := call(protocol.Message{Type: protocol.RepairSessionExport, RunID: id, ExportSequence: sequence})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if response.RunDetail == nil {
|
|
return fmt.Errorf("server returned no repair evidence")
|
|
}
|
|
for _, step := range response.RunDetail.Steps {
|
|
if step.Sequence == sequence && len(step.SessionExportRepairs) > 0 {
|
|
evidence := step.SessionExportRepairs[len(step.SessionExportRepairs)-1]
|
|
if jsonOutput {
|
|
if err := a.output(evidence); err != nil {
|
|
return err
|
|
}
|
|
if evidence.Status != "complete" {
|
|
return fmt.Errorf("session export repair incomplete: %s", evidence.Status)
|
|
}
|
|
return nil
|
|
}
|
|
fmt.Fprintf(a.Out, "Session export repair: %s · %d messages\n", evidence.Status, evidence.Messages)
|
|
if evidence.HTML != "" {
|
|
fmt.Fprintln(a.Out, evidence.HTML)
|
|
}
|
|
if evidence.Diagnostic != "" {
|
|
fmt.Fprintln(a.Out, evidence.Diagnostic)
|
|
}
|
|
if evidence.Status != "complete" {
|
|
return fmt.Errorf("session export repair incomplete: %s", evidence.Status)
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
return fmt.Errorf("server returned no recorded repair attempt")
|
|
}
|