Add a --write and --diff flag; require --write to be set before making any changes, for safety

This commit is contained in:
Pim van Pelt
2025-08-28 11:18:59 +02:00
parent 6bc0071bdb
commit d027ec9108
8 changed files with 133 additions and 26 deletions

View File

@@ -110,7 +110,7 @@ type TemporalInterval struct {
EndExclusive string `json:"end_exclusive"`
}
func generateHTML(yamlFile string) {
func generateHTML(yamlFile string, wantDiff bool, allowWrite bool, useColor bool) {
config := loadConfig(yamlFile)
// Check that all local directories exist
@@ -145,14 +145,14 @@ func generateHTML(yamlFile string) {
}
// Write file with status
err = writeFileWithStatus(indexPath, buf.Bytes())
err = writeFileWithStatus(indexPath, buf.Bytes(), wantDiff, allowWrite, useColor)
if err != nil {
log.Fatalf("Failed to write HTML to %s: %v", indexPath, err)
}
// Generate log.v3.json for this log
jsonPath := filepath.Join(logEntry.LocalDirectory, "log.v3.json")
err = generateLogJSONWithStatus(logEntry, jsonPath)
err = generateLogJSONWithStatus(logEntry, jsonPath, wantDiff, allowWrite, useColor)
if err != nil {
log.Fatalf("Failed to generate %s: %v", jsonPath, err)
}
@@ -209,7 +209,7 @@ func computeKeyInfo(logEntry *Log) error {
return nil
}
func generateLogJSONWithStatus(logEntry Log, outputPath string) error {
func generateLogJSONWithStatus(logEntry Log, outputPath string, wantDiff bool, allowWrite bool, useColor bool) error {
logJSON := LogV3JSON{
Description: fmt.Sprintf("%s.log.ct.ipng.ch", logEntry.ShortName),
SubmissionURL: fmt.Sprintf("%s/", logEntry.SubmissionPrefix),
@@ -228,5 +228,5 @@ func generateLogJSONWithStatus(logEntry Log, outputPath string) error {
return fmt.Errorf("failed to marshal JSON: %v", err)
}
return writeFileWithStatus(outputPath, jsonData)
return writeFileWithStatus(outputPath, jsonData, wantDiff, allowWrite, useColor)
}