Skip to content

Commit

Permalink
prompts, op_doc: add config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkCaster committed Dec 19, 2024
1 parent ae12974 commit 72585f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions op_doc/op_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func Run(args []string, logger logging.ILogger) {
if err = utils.LoadJsonFile(filepath.Join(perpetualDir, prompts.OpDocConfigFile), &docConfig); err != nil {
logger.Panicf("Error loading %s config :%s", prompts.OpDocConfigFile, err)
}
if err = prompts.ValidateOpDocConfig(docConfig); err != nil {
logger.Panicf("Failed to validate op_doc config: %s", err)
}

var filesToMdLangMappings [][2]string
err = utils.LoadJsonFile(filepath.Join(perpetualDir, prompts.ProjectFilesToMarkdownLangMappingFileName), &filesToMdLangMappings)
Expand Down
21 changes: 21 additions & 0 deletions prompts/config_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,24 @@ func ValidateOpImplementConfig(config map[string]interface{}) error {

return nil
}

func ValidateOpDocConfig(config map[string]interface{}) error {
template := getDefaultDocConfigTemplate()
if err := validateConfigAgainstTemplate(template, config); err != nil {
return err
}

if err := validateEvenStringArray(config[FilenameTagsName], FilenameTagsName); err != nil {
return err
}

if err := validateEvenStringArray(config[FilenameTagsRxName], FilenameTagsRxName); err != nil {
return err
}

if err := validateNonEmptyStringArray(config[NoUploadCommentsRxName], NoUploadCommentsRxName); err != nil {
return err
}

return nil
}

0 comments on commit 72585f5

Please sign in to comment.