feat: update new version in env file

This commit is contained in:
2024-07-08 17:55:40 +02:00
parent 4085eb6654
commit 7596982282
4 changed files with 48 additions and 0 deletions

View File

@ -568,3 +568,30 @@ func ReadAbraShCmdNames(abraSh string) ([]string, error) {
return cmdNames, nil
}
func (a App) WriteRecipeVersion(version string) error {
file, err := os.Open(a.Path)
if err != nil {
return err
}
defer file.Close()
scanner := bufio.NewScanner(file)
lines := []string{}
for scanner.Scan() {
line := scanner.Text()
if !strings.Contains(line, "RECIPE=") && !strings.Contains(line, "TYPE") {
lines = append(lines, line)
continue
}
splitted := strings.Split(line, ":")
line = fmt.Sprintf("%s:%s", splitted[0], version)
lines = append(lines, line)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
return os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm)
}