2026-11-22 02:49:48 +00:00
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 )
}
2026-11-28 04:26:30 +00:00
// Call after configuration and identity selection, before pipeline resolution.
// Shared loaders never allocate.
2026-11-22 02:49:48 +00:00
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 )
}