2026-11-22 03:51:08 +00:00
package cli
import (
"fmt"
"strings"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"go.maximumdirect.net/ckconfig"
"go.maximumdirect.net/commandkit"
)
type pipelineRunInput struct {
Selection ckconfig . Selection
PipelineID string
InputFile commandkit . Supplied [ string ]
Lanes commandkit . Supplied [ [ ] string ]
OutputDirectory commandkit . Supplied [ string ]
Cache commandkit . Supplied [ contracts . CacheMode ]
References commandkit . Supplied [ [ ] cliReferenceRequest ]
Unbinds commandkit . Supplied [ [ ] cliReferenceUnbindRequest ]
Debug runDebugInput
Overrides executionOverrides
}
func runFlags ( ) [ ] commandkit . Flag [ pipelineRunInput ] {
flags := configurationSelectionFlags ( func ( input * pipelineRunInput ) * ckconfig . Selection { return & input . Selection } )
flags = append ( flags ,
commandkit . ValueFlag ( commandkit . FlagMeta { Name : "input-file" , Usage : "Source input file." , Completion : commandkit . CompleteFiles ( ) } , ( * string ) ( nil ) , parseRequiredRunValue , func ( input * pipelineRunInput , value commandkit . Supplied [ string ] ) { input . InputFile = value } ) ,
commandkit . RepeatFlag ( commandkit . FlagMeta { Name : "lane" , Usage : "Select a literal artifact lane identifier; repeat for multiple lanes." } , [ ] string ( nil ) , parseRequiredRunValue , func ( input * pipelineRunInput , value commandkit . Supplied [ [ ] string ] ) { input . Lanes = value } ) ,
commandkit . ValueFlag ( commandkit . FlagMeta { Name : "output-dir" , Usage : "Output directory." , Completion : commandkit . CompleteFiles ( ) } , ( * string ) ( nil ) , parseRequiredRunValue , func ( input * pipelineRunInput , value commandkit . Supplied [ string ] ) { input . OutputDirectory = value } ) ,
commandkit . ValueFlag ( commandkit . FlagMeta { Name : "cache" , Usage : "Use auto, bypass, or refresh for all cacheable work." , Completion : commandkit . CompleteChoices ( commandkit . CompletionChoice { Value : "auto" } , commandkit . CompletionChoice { Value : "bypass" } , commandkit . CompletionChoice { Value : "refresh" } ) } , ( * contracts . CacheMode ) ( nil ) , func ( value string ) ( contracts . CacheMode , error ) {
mode := contracts . CacheMode ( value )
switch mode {
case contracts . CacheAuto , contracts . CacheBypass , contracts . CacheRefresh :
return mode , nil
default :
return "" , fmt . Errorf ( "cache must be auto, bypass, or refresh" )
}
} , func ( input * pipelineRunInput , value commandkit . Supplied [ contracts . CacheMode ] ) { input . Cache = value } ) ,
commandkit . RepeatFlag ( commandkit . FlagMeta { Name : "reference" , Usage : "Bind SELECTOR=PATH to compatible reference slots." } , [ ] cliReferenceRequest ( nil ) , func ( value string ) ( cliReferenceRequest , error ) {
parsed , err := parseReferenceFlags ( [ ] string { value } )
if err != nil {
return cliReferenceRequest { } , err
}
return parsed [ 0 ] , nil
} , func ( input * pipelineRunInput , value commandkit . Supplied [ [ ] cliReferenceRequest ] ) {
input . References = value
} ) ,
commandkit . RepeatFlag ( commandkit . FlagMeta { Name : "without-reference" , Usage : "Unbind an optional reference SELECTOR." } , [ ] cliReferenceUnbindRequest ( nil ) , func ( value string ) ( cliReferenceUnbindRequest , error ) {
parsed , err := parseReferenceUnbindFlags ( [ ] string { value } )
if err != nil {
return cliReferenceUnbindRequest { } , err
}
return parsed [ 0 ] , nil
} , func ( input * pipelineRunInput , value commandkit . Supplied [ [ ] cliReferenceUnbindRequest ] ) {
input . Unbinds = value
} ) ,
)
flags = append ( flags , runDebugFlags ( func ( input * pipelineRunInput ) * runDebugInput { return & input . Debug } ) ... )
return append ( flags , executionOverrideFlags ( func ( input * pipelineRunInput ) * executionOverrides { return & input . Overrides } ) ... )
}
2026-11-28 04:05:54 +00:00
func pipelineRunArguments ( ) [ ] commandkit . Argument [ pipelineRunInput ] {
return [ ] commandkit . Argument [ pipelineRunInput ] { commandkit . ValueArgument ( commandkit . ArgumentMeta { Name : "pipeline-id" , Usage : "Configured pipeline identifier." } , true , parseRequiredRunValue , func ( input * pipelineRunInput , value commandkit . Supplied [ string ] ) { input . PipelineID = value . Value } ) }
}
2026-11-22 03:51:08 +00:00
func parseRequiredRunValue ( value string ) ( string , error ) {
if strings . TrimSpace ( value ) == "" {
return "" , fmt . Errorf ( "value must not be empty" )
}
return value , nil
}
func checkPipelineRunInput ( input pipelineRunInput ) error {
if err := checkConfigSelection ( input . Selection ) ; err != nil {
return err
}
if ! input . InputFile . Set {
return fmt . Errorf ( "--input-file is required" )
}
return nil
}