Files
seriatim/internal/normalize/normalize.go

50 lines
916 B
Go
Raw Normal View History

2026-05-09 12:26:47 +00:00
package normalize
import (
"context"
2026-05-09 12:32:18 +00:00
"encoding/json"
2026-05-09 12:26:47 +00:00
"fmt"
2026-05-09 12:32:18 +00:00
"os"
2026-05-09 12:26:47 +00:00
"gitea.maximumdirect.net/eric/seriatim/internal/config"
)
// Run validates command wiring for normalize and will later execute
// artifact-level normalization.
func Run(ctx context.Context, cfg config.NormalizeConfig) error {
if err := ctx.Err(); err != nil {
return err
}
2026-05-09 12:32:18 +00:00
parsed, err := ParseFile(cfg.InputFile)
if err != nil {
2026-05-09 12:29:12 +00:00
return err
}
2026-05-09 12:32:18 +00:00
output, err := Build(parsed, cfg)
if err != nil {
return err
}
if err := writeOutputJSON(cfg.OutputFile, output); err != nil {
return err
}
return nil
}
func writeOutputJSON(path string, value any) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
if err := encoder.Encode(value); err != nil {
return fmt.Errorf("encode normalize output JSON: %w", err)
}
return nil
2026-05-09 12:26:47 +00:00
}