Compose native application commands and shared configuration scopes
This commit is contained in:
@@ -26,20 +26,10 @@ import (
|
||||
frameworkdebug "gitea.maximumdirect.net/eric/notarius/internal/framework/debug"
|
||||
frameworkllm "gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
const usage = `Usage:
|
||||
notarius help
|
||||
notarius --version
|
||||
notarius run <pipeline-id> --input path/to/source.json [--json] [flags]
|
||||
notarius config validate --config path/to/config.yml [--config-overlay name] [--pipeline pipeline-id] [--only lane-a,lane-b]
|
||||
notarius config effective [--scope notarius|promptkit] --config path/to/config.yml [--config-overlay name]
|
||||
notarius config explain [--scope notarius|promptkit] --config path/to/config.yml [--config-overlay name] <json-pointer>
|
||||
notarius config profile [--config path/to/config.yml] [--config-overlay name] <profile-id>
|
||||
notarius pipelines list --config path/to/config.yml [--config-overlay name] [--json]
|
||||
`
|
||||
|
||||
type Options struct {
|
||||
Catalog pipeline.ModuleCatalog
|
||||
Registries pipeline.Registries
|
||||
@@ -66,50 +56,17 @@ func Run(args []string, stdout, stderr io.Writer) int {
|
||||
}
|
||||
|
||||
func RunWithOptions(args []string, stdout, stderr io.Writer, opts Options) int {
|
||||
if len(args) > 0 && args[0] == "--version" {
|
||||
if len(args) != 1 {
|
||||
fmt.Fprintln(stderr, "notarius: --version does not accept arguments")
|
||||
return 2
|
||||
}
|
||||
version, err := buildinfo.Version()
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "notarius: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintf(stdout, "notarius %s\n", version)
|
||||
return 0
|
||||
}
|
||||
|
||||
var err error
|
||||
opts, err = normalizeOptions(opts)
|
||||
version, err := buildinfo.Version()
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "notarius: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
if len(args) == 0 {
|
||||
writeUsage(stdout)
|
||||
return 0
|
||||
app, err := NewApplication(version, opts)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "notarius: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
switch args[0] {
|
||||
case "help", "--help", "-h":
|
||||
writeUsage(stdout)
|
||||
return 0
|
||||
case "config":
|
||||
return runConfig(args[1:], stdout, stderr, opts)
|
||||
case "pipelines":
|
||||
return runPipelines(args[1:], stdout, stderr, opts)
|
||||
case "run":
|
||||
return runPipelineCommand(args[1:], stdout, stderr, opts)
|
||||
default:
|
||||
fmt.Fprintf(stderr, "notarius: unknown command %q\n", args[0])
|
||||
writeUsage(stderr)
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
func writeUsage(w io.Writer) {
|
||||
fmt.Fprint(w, usage)
|
||||
return app.Execute(context.Background(), args, commandkit.Streams{Out: stdout, Err: stderr}).Status
|
||||
}
|
||||
|
||||
func normalizeOptions(opts Options) (Options, error) {
|
||||
@@ -1046,44 +1003,6 @@ func runMetadata(outputDir, debugDir string) map[string]any {
|
||||
return metadata
|
||||
}
|
||||
|
||||
func runConfig(args []string, stdout, stderr io.Writer, opts Options) int {
|
||||
if len(args) == 0 {
|
||||
fmt.Fprintln(stderr, "notarius: config requires a subcommand")
|
||||
writeUsage(stderr)
|
||||
return 2
|
||||
}
|
||||
switch args[0] {
|
||||
case "validate":
|
||||
return runConfigValidate(args[1:], stdout, stderr, opts)
|
||||
case "effective":
|
||||
return runConfigEffective(args[1:], stdout, stderr, opts)
|
||||
case "explain":
|
||||
return runConfigExplain(args[1:], stdout, stderr, opts)
|
||||
case "profile":
|
||||
return runConfigProfile(args[1:], stdout, stderr, opts)
|
||||
default:
|
||||
fmt.Fprintf(stderr, "notarius: unknown config subcommand %q\n", args[0])
|
||||
writeUsage(stderr)
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
func runPipelines(args []string, stdout, stderr io.Writer, opts Options) int {
|
||||
if len(args) == 0 {
|
||||
fmt.Fprintln(stderr, "notarius: pipelines requires a subcommand")
|
||||
writeUsage(stderr)
|
||||
return 2
|
||||
}
|
||||
switch args[0] {
|
||||
case "list":
|
||||
return runPipelinesList(args[1:], stdout, stderr, opts)
|
||||
default:
|
||||
fmt.Fprintf(stderr, "notarius: unknown pipelines subcommand %q\n", args[0])
|
||||
writeUsage(stderr)
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
func parseOnly(raw string) ([]string, error) {
|
||||
if strings.TrimSpace(raw) == "" {
|
||||
return nil, nil
|
||||
|
||||
Reference in New Issue
Block a user