build: update directives with the new interface.
This commit is contained in:
parent
38e9e5f08e
commit
08d4110c2a
9 changed files with 63 additions and 89 deletions
|
|
@ -10,36 +10,25 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/arduino/go-paths-helper"
|
||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
||||
)
|
||||
|
||||
// Define the directive keyword globally
|
||||
const Keyword = "#aa:"
|
||||
|
||||
// Build the profiles with the following directive applied
|
||||
var Directives = map[string]Directive{}
|
||||
var (
|
||||
// Build the profiles with the following directive applied
|
||||
Directives = map[string]Directive{}
|
||||
|
||||
var regDirective = regexp.MustCompile(`(?m).*` + Keyword + `([a-z]*) (.*)`)
|
||||
regDirective = regexp.MustCompile(`(?m).*` + Keyword + `([a-z]*) (.*)`)
|
||||
)
|
||||
|
||||
// Main directive interface
|
||||
type Directive interface {
|
||||
Usage() string
|
||||
Message() string
|
||||
cfg.BaseInterface
|
||||
Apply(opt *Option, profile string) string
|
||||
}
|
||||
|
||||
type DirectiveBase struct {
|
||||
message string
|
||||
usage string
|
||||
}
|
||||
|
||||
func (d *DirectiveBase) Usage() string {
|
||||
return d.usage
|
||||
}
|
||||
|
||||
func (d *DirectiveBase) Message() string {
|
||||
return d.message
|
||||
}
|
||||
|
||||
// Directive options
|
||||
type Option struct {
|
||||
Name string
|
||||
|
|
@ -72,6 +61,10 @@ func NewOption(file *paths.Path, match []string) *Option {
|
|||
}
|
||||
}
|
||||
|
||||
func RegisterDirective(d Directive) {
|
||||
Directives[d.Name()] = d
|
||||
}
|
||||
|
||||
func Run(file *paths.Path, profile string) string {
|
||||
for _, match := range regDirective.FindAllStringSubmatch(profile, -1) {
|
||||
opt := NewOption(file, match)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue