52 lines
1.9 KiB
Go
52 lines
1.9 KiB
Go
|
|
package cli
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"path/filepath"
|
||
|
|
"strings"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
frameworkdebug "gitea.maximumdirect.net/eric/notarius/internal/framework/debug"
|
||
|
|
"go.maximumdirect.net/commandkit"
|
||
|
|
)
|
||
|
|
|
||
|
|
type runDebugInput struct {
|
||
|
|
Enabled commandkit.Supplied[bool]
|
||
|
|
Directory commandkit.Supplied[string]
|
||
|
|
}
|
||
|
|
|
||
|
|
func runDebugFlags[I any](selectInput func(*I) *runDebugInput) []commandkit.Flag[I] {
|
||
|
|
return []commandkit.Flag[I]{
|
||
|
|
commandkit.BoolFlag(commandkit.FlagMeta{Name: "debug", Usage: "Capture run evidence."}, false, func(input *I, value commandkit.Supplied[bool]) { selectInput(input).Enabled = value }),
|
||
|
|
commandkit.ValueFlag(commandkit.FlagMeta{Name: "debug-dir", Usage: "Debug capture directory; empty disables capture."}, (*string)(nil), func(value string) (string, error) {
|
||
|
|
if strings.ContainsRune(value, '\x00') {
|
||
|
|
return "", fmt.Errorf("debug directory must not contain NUL")
|
||
|
|
}
|
||
|
|
return value, nil
|
||
|
|
}, func(input *I, value commandkit.Supplied[string]) { selectInput(input).Directory = value }),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// The configured directory has already been resolved against its source by the
|
||
|
|
// application load. CLI paths instead belong to the invocation directory.
|
||
|
|
func (input runDebugInput) directory(configuredDirectory string) (string, error) {
|
||
|
|
directory := configuredDirectory
|
||
|
|
if input.Directory.Set {
|
||
|
|
directory = input.Directory.Value
|
||
|
|
}
|
||
|
|
if !input.Enabled.Value || directory == "" {
|
||
|
|
return "", nil
|
||
|
|
}
|
||
|
|
return filepath.Abs(directory)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Only the run handler calls this, after configuration/run identity and before
|
||
|
|
// engine construction or pipeline preflight. Shared loaders never allocate.
|
||
|
|
func startRunDebug(input runDebugInput, configuredDirectory, runID string, startedAt time.Time) (*frameworkdebug.Recorder, error) {
|
||
|
|
directory, err := input.directory(configuredDirectory)
|
||
|
|
if err != nil || directory == "" {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return frameworkdebug.Start(directory, runID, startedAt)
|
||
|
|
}
|