build: remove directive text not applied on build.

This commit is contained in:
Alexandre Pujol 2024-04-28 14:22:00 +01:00
parent 2aa8986a21
commit c7fb47e97a
No known key found for this signature in database
GPG Key ID: C5469996F0DF68EC
3 changed files with 11 additions and 4 deletions

View File

@ -61,6 +61,13 @@ func NewOption(file *paths.Path, match []string) *Option {
}
}
// Clean the selected directive from profile.
// Useful to remove directive text applied on some condition only
func (o *Option) Clean(profile string) string {
reg := regexp.MustCompile(`\s*` + Keyword + o.Name + ` .*$`)
return reg.ReplaceAllString(profile, "")
}
func RegisterDirective(d Directive) {
Directives[d.Name()] = d
}

View File

@ -43,10 +43,10 @@ func filterRuleForUs(opt *Option) bool {
func filter(only bool, opt *Option, profile string) string {
if only && filterRuleForUs(opt) {
return profile
return opt.Clean(profile)
}
if !only && !filterRuleForUs(opt) {
return profile
return opt.Clean(profile)
}
inline := true

View File

@ -31,7 +31,7 @@ func TestFilterOnly_Apply(t *testing.T) {
Raw: " @{bin}/arch-audit rPx, #aa:only apt",
},
profile: " @{bin}/arch-audit rPx, #aa:only apt",
want: " @{bin}/arch-audit rPx, #aa:only apt",
want: " @{bin}/arch-audit rPx,",
},
{
name: "paragraph",
@ -121,7 +121,7 @@ func TestFilterExclude_Apply(t *testing.T) {
Raw: " @{bin}/dpkg rPx -> child-dpkg, #aa:exclude debian",
},
profile: " @{bin}/dpkg rPx -> child-dpkg, #aa:exclude debian",
want: " @{bin}/dpkg rPx -> child-dpkg, #aa:exclude debian",
want: " @{bin}/dpkg rPx -> child-dpkg,",
},
}
for _, tt := range tests {