Add normalize command scaffold
This commit is contained in:
@@ -58,6 +58,15 @@ type TrimOptions struct {
|
||||
AllowEmpty bool
|
||||
}
|
||||
|
||||
// NormalizeOptions captures raw CLI option values before validation.
|
||||
type NormalizeOptions struct {
|
||||
InputFile string
|
||||
OutputFile string
|
||||
ReportFile string
|
||||
OutputSchema string
|
||||
OutputModules string
|
||||
}
|
||||
|
||||
// Config is the validated runtime configuration for a merge invocation.
|
||||
type Config struct {
|
||||
InputFiles []string
|
||||
@@ -88,6 +97,15 @@ type TrimConfig struct {
|
||||
AllowEmpty bool
|
||||
}
|
||||
|
||||
// NormalizeConfig is the validated runtime configuration for a normalize invocation.
|
||||
type NormalizeConfig struct {
|
||||
InputFile string
|
||||
OutputFile string
|
||||
ReportFile string
|
||||
OutputSchema string
|
||||
OutputModules []string
|
||||
}
|
||||
|
||||
// NewMergeConfig validates raw merge options and returns normalized config.
|
||||
func NewMergeConfig(opts MergeOptions) (Config, error) {
|
||||
cfg := Config{
|
||||
@@ -247,6 +265,54 @@ func NewTrimConfig(opts TrimOptions) (TrimConfig, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewNormalizeConfig validates raw normalize options and returns normalized config.
|
||||
func NewNormalizeConfig(opts NormalizeOptions) (NormalizeConfig, error) {
|
||||
inputFile := filepath.Clean(strings.TrimSpace(opts.InputFile))
|
||||
if strings.TrimSpace(opts.InputFile) == "" {
|
||||
return NormalizeConfig{}, errors.New("--input-file is required")
|
||||
}
|
||||
if err := requireFile(inputFile, "--input-file"); err != nil {
|
||||
return NormalizeConfig{}, err
|
||||
}
|
||||
|
||||
outputFile, err := normalizeOutputPath(opts.OutputFile, "--output-file")
|
||||
if err != nil {
|
||||
return NormalizeConfig{}, err
|
||||
}
|
||||
|
||||
reportFile := ""
|
||||
if strings.TrimSpace(opts.ReportFile) != "" {
|
||||
reportFile, err = normalizeOutputPath(opts.ReportFile, "--report-file")
|
||||
if err != nil {
|
||||
return NormalizeConfig{}, err
|
||||
}
|
||||
}
|
||||
|
||||
outputSchema, err := resolveOutputSchema(opts.OutputSchema)
|
||||
if err != nil {
|
||||
return NormalizeConfig{}, err
|
||||
}
|
||||
|
||||
outputModules, err := parseModuleList(opts.OutputModules)
|
||||
if err != nil {
|
||||
return NormalizeConfig{}, fmt.Errorf("--output-modules: %w", err)
|
||||
}
|
||||
if len(outputModules) == 0 {
|
||||
return NormalizeConfig{}, errors.New("--output-modules must include at least one module")
|
||||
}
|
||||
if err := validateNormalizeOutputModules(outputModules); err != nil {
|
||||
return NormalizeConfig{}, err
|
||||
}
|
||||
|
||||
return NormalizeConfig{
|
||||
InputFile: inputFile,
|
||||
OutputFile: outputFile,
|
||||
ReportFile: reportFile,
|
||||
OutputSchema: outputSchema,
|
||||
OutputModules: outputModules,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseModuleList(value string) ([]string, error) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
@@ -400,3 +466,12 @@ func contains(values []string, target string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func validateNormalizeOutputModules(modules []string) error {
|
||||
for _, module := range modules {
|
||||
if module != "json" {
|
||||
return fmt.Errorf("unknown output module %q", module)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user