writeFileWithStatus() which shows 'Creating' for new, 'Updating' for changed and 'Unchanged' for files that won't change
This commit is contained in:
@@ -97,6 +97,26 @@ func loadConfig(yamlFile string) Config {
|
||||
return config
|
||||
}
|
||||
|
||||
func writeFileWithStatus(filename string, content []byte) error {
|
||||
existingContent, err := os.ReadFile(filename)
|
||||
if os.IsNotExist(err) {
|
||||
fmt.Printf("Creating %s\n", filename)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("failed to read existing file %s: %v", filename, err)
|
||||
} else if string(existingContent) == string(content) {
|
||||
fmt.Printf("Unchanged %s\n", filename)
|
||||
return nil
|
||||
} else {
|
||||
fmt.Printf("Updating %s\n", filename)
|
||||
}
|
||||
|
||||
err = os.WriteFile(filename, content, 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to write file %s: %v", filename, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func showHelp() {
|
||||
fmt.Printf("Usage: %s [options] <command>\n\n", os.Args[0])
|
||||
fmt.Printf("Options:\n")
|
||||
|
Reference in New Issue
Block a user