package resolution import ( "fmt" "regexp" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) // ofBackup is where a holder places them: ${backup:}. Loose inside the braces, so a misspelt key is found and // refused rather than written out as text. var ofBackup = regexp.MustCompile(`\$\{backup:([^}]*)\}`) // backupKinds is the contribution kind each key of the backup placement renders. var backupKinds = map[string]string{"lines": mcat.BackupKindBackup, "data": mcat.BackupKindData} // backupPlacer is the machine's modules the backup placement is composed over, as the old contributions are. type backupPlacer struct { modules []mcat.Manifest with mcat.Rendering facts map[string]string caps map[string]bool unplaced *[]string } // placed is the text of one key for a holder, or what is wrong with naming it. func (b backupPlacer) placed(holder mcat.Manifest, key string, item bool) (string, string) { kind, known := backupKinds[key] switch { case item: return "", "an item is kept per item; the machine's backup lines are placed only in a file" case !known: return "", fmt.Sprintf("the backup placement has `lines` and `data`, not %q", key) case !holder.ClaimsSeat(mcat.BackupSeat): return "", fmt.Sprintf("%s does not claim %s; the machine's backup lines are placed by its holder alone "+ "(novox/hq ADR 0212)", holder.Module, mcat.BackupSeat) } text, left, err := seatContributions(b.modules, holder, mcat.BackupSeat+":"+kind, b.with, b.facts, b.caps) if b.unplaced != nil { *b.unplaced = append(*b.unplaced, left...) } if err != nil { return "", err.Error() } return text, "" }