build: cleanup base build interface.
This commit is contained in:
parent
c6c4920598
commit
6f5604d59d
6 changed files with 21 additions and 16 deletions
|
|
@ -9,20 +9,20 @@ import "fmt"
|
||||||
type BaseInterface interface {
|
type BaseInterface interface {
|
||||||
Message() string
|
Message() string
|
||||||
Name() string
|
Name() string
|
||||||
Usage() string
|
Usage() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Base struct {
|
type Base struct {
|
||||||
Msg string
|
Msg string
|
||||||
Keyword string
|
Keyword string
|
||||||
Help string
|
Help []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Base) Name() string {
|
func (b Base) Name() string {
|
||||||
return b.Keyword
|
return b.Keyword
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Base) Usage() string {
|
func (b Base) Usage() []string {
|
||||||
return b.Help
|
return b.Help
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +41,9 @@ func Help[T BaseInterface](name string, tasks map[string]T) string {
|
||||||
func Usage[T BaseInterface](name string, tasks map[string]T) string {
|
func Usage[T BaseInterface](name string, tasks map[string]T) string {
|
||||||
res := fmt.Sprintf("%s\n", name)
|
res := fmt.Sprintf("%s\n", name)
|
||||||
for _, t := range tasks {
|
for _, t := range tasks {
|
||||||
res += fmt.Sprintf(" %s\n", t.Usage())
|
for _, h := range t.Usage() {
|
||||||
|
res += fmt.Sprintf(" #aa:%s %s\n", t.Name(), h)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
@ -17,7 +18,7 @@ func TestBase_Helpers(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "base",
|
name: "base",
|
||||||
b: Base{Keyword: "test", Help: "test", Msg: "test"},
|
b: Base{Keyword: "test", Help: []string{"test"}, Msg: "test"},
|
||||||
want: "test",
|
want: "test",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +27,7 @@ func TestBase_Helpers(t *testing.T) {
|
||||||
if got := tt.b.Name(); got != tt.want {
|
if got := tt.b.Name(); got != tt.want {
|
||||||
t.Errorf("Base.Name() = %v, want %v", got, tt.want)
|
t.Errorf("Base.Name() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
if got := tt.b.Usage(); got != tt.want {
|
if got := tt.b.Usage(); !slices.Equal(got, []string{tt.want}) {
|
||||||
t.Errorf("Base.Usage() = %v, want %v", got, tt.want)
|
t.Errorf("Base.Usage() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
if got := tt.b.Message(); got != tt.want {
|
if got := tt.b.Message(); got != tt.want {
|
||||||
|
|
@ -45,8 +46,8 @@ func TestHelp(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "one",
|
name: "one",
|
||||||
tasks: map[string]Base{
|
tasks: map[string]Base{
|
||||||
"one": {Keyword: "one", Help: "one", Msg: "one"},
|
"one": {Keyword: "one", Help: []string{"one"}, Msg: "one"},
|
||||||
"two": {Keyword: "two", Help: "two", Msg: "two"},
|
"two": {Keyword: "two", Help: []string{"two"}, Msg: "two"},
|
||||||
},
|
},
|
||||||
want: `one`,
|
want: `one`,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,12 @@ func init() {
|
||||||
Base: cfg.Base{
|
Base: cfg.Base{
|
||||||
Keyword: "dbus",
|
Keyword: "dbus",
|
||||||
Msg: "Dbus directive applied",
|
Msg: "Dbus directive applied",
|
||||||
Help: `#aa:dbus own bus=<bus> name=<name> [interface=AARE] [path=AARE]
|
Help: []string{
|
||||||
#aa:dbus talk bus=<bus> name=<name> label=<profile> [interface=AARE] [path=AARE]`,
|
"own bus=<bus> name=<name> [interface=AARE] [path=AARE]",
|
||||||
},
|
"talk bus=<bus> name=<name> label=<profile> [interface=AARE] [path=AARE]",
|
||||||
})
|
},
|
||||||
|
}},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setInterfaces(rules map[string]string) []string {
|
func setInterfaces(rules map[string]string) []string {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ func init() {
|
||||||
Base: cfg.Base{
|
Base: cfg.Base{
|
||||||
Keyword: "exec",
|
Keyword: "exec",
|
||||||
Msg: "Exec directive applied",
|
Msg: "Exec directive applied",
|
||||||
Help: Keyword + `exec [P|U|p|u|PU|pu|] profiles...`,
|
Help: []string{"[P|U|p|u|PU|pu|] profiles..."},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,14 @@ func init() {
|
||||||
Base: cfg.Base{
|
Base: cfg.Base{
|
||||||
Keyword: "only",
|
Keyword: "only",
|
||||||
Msg: "Only directive applied",
|
Msg: "Only directive applied",
|
||||||
Help: Keyword + `only filters...`,
|
Help: []string{"filters..."},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
RegisterDirective(&FilterExclude{
|
RegisterDirective(&FilterExclude{
|
||||||
Base: cfg.Base{
|
Base: cfg.Base{
|
||||||
Keyword: "exclude",
|
Keyword: "exclude",
|
||||||
Msg: "Exclude directive applied",
|
Msg: "Exclude directive applied",
|
||||||
Help: Keyword + `exclude filters...`,
|
Help: []string{"filters..."},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func init() {
|
||||||
Base: cfg.Base{
|
Base: cfg.Base{
|
||||||
Keyword: "stack",
|
Keyword: "stack",
|
||||||
Msg: "Stack directive applied",
|
Msg: "Stack directive applied",
|
||||||
Help: Keyword + `stack [X] profiles...`,
|
Help: []string{"[X] profiles..."},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue