2026-11-27 01:15:40 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v4/internal/core/diagnostics"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type debugInput struct {
|
|
|
|
|
WorkDir string
|
|
|
|
|
RunID string
|
|
|
|
|
Metadata diagnostics.InvocationMetadata
|
|
|
|
|
EffectiveConfig []byte
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type preparedOutput struct {
|
|
|
|
|
Output *diagnostics.OutputSession
|
|
|
|
|
Debug *diagnostics.RunDirectory
|
|
|
|
|
Warnings []error
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-27 01:17:45 +00:00
|
|
|
func prepareOutput(ctx context.Context, checked *diagnostics.CheckedDestinations, initial diagnostics.ReportBundle, failed diagnostics.ReportRenderer, debug *debugInput) (*preparedOutput, error) {
|
2026-11-27 01:15:40 +00:00
|
|
|
if err := ctx.Err(); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
session := diagnostics.NewOutputSession(checked)
|
|
|
|
|
if err := session.Prepare(); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err := ctx.Err(); err != nil {
|
|
|
|
|
return nil, errors.Join(err, session.Close())
|
|
|
|
|
}
|
|
|
|
|
if err := session.Initialize(ctx, initial, failed); err != nil {
|
|
|
|
|
return nil, errors.Join(err, session.Close())
|
|
|
|
|
}
|
|
|
|
|
cancelOutput := func(err error) error { return session.Finish(ctx, err, nil, failed) }
|
|
|
|
|
if err := ctx.Err(); err != nil {
|
|
|
|
|
return nil, cancelOutput(err)
|
|
|
|
|
}
|
2026-11-27 01:17:45 +00:00
|
|
|
result := &preparedOutput{Output: session}
|
2026-11-27 01:15:40 +00:00
|
|
|
if debug != nil {
|
|
|
|
|
result.Debug, result.Warnings = diagnostics.PrepareDebug(debug.WorkDir, debug.RunID, debug.Metadata, debug.EffectiveConfig)
|
|
|
|
|
}
|
|
|
|
|
if err := ctx.Err(); err != nil {
|
|
|
|
|
return nil, cancelOutput(err)
|
|
|
|
|
}
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|