build: remove directive text not applied on build.
This commit is contained in:
parent
2aa8986a21
commit
c7fb47e97a
3 changed files with 11 additions and 4 deletions
|
|
@ -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) {
|
func RegisterDirective(d Directive) {
|
||||||
Directives[d.Name()] = d
|
Directives[d.Name()] = d
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,10 @@ func filterRuleForUs(opt *Option) bool {
|
||||||
|
|
||||||
func filter(only bool, opt *Option, profile string) string {
|
func filter(only bool, opt *Option, profile string) string {
|
||||||
if only && filterRuleForUs(opt) {
|
if only && filterRuleForUs(opt) {
|
||||||
return profile
|
return opt.Clean(profile)
|
||||||
}
|
}
|
||||||
if !only && !filterRuleForUs(opt) {
|
if !only && !filterRuleForUs(opt) {
|
||||||
return profile
|
return opt.Clean(profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline := true
|
inline := true
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ func TestFilterOnly_Apply(t *testing.T) {
|
||||||
Raw: " @{bin}/arch-audit rPx, #aa:only apt",
|
Raw: " @{bin}/arch-audit rPx, #aa:only apt",
|
||||||
},
|
},
|
||||||
profile: " @{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",
|
name: "paragraph",
|
||||||
|
|
@ -121,7 +121,7 @@ func TestFilterExclude_Apply(t *testing.T) {
|
||||||
Raw: " @{bin}/dpkg rPx -> child-dpkg, #aa:exclude debian",
|
Raw: " @{bin}/dpkg rPx -> child-dpkg, #aa:exclude debian",
|
||||||
},
|
},
|
||||||
profile: " @{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 {
|
for _, tt := range tests {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue