Gisle Aune
2 years ago
8 changed files with 187 additions and 168 deletions
-
50cmd/bustest/main.go
-
30commands/edit.go
-
9commands/scene.go
-
5device/Resolver.go
-
65device/pointer.go
-
2go.mod
-
2go.sum
-
178services/resolver.go
@ -0,0 +1,5 @@ |
|||||
|
package device |
||||
|
|
||||
|
type Resolver interface { |
||||
|
Resolve(pattern string) []Pointer |
||||
|
} |
@ -0,0 +1,65 @@ |
|||||
|
package device |
||||
|
|
||||
|
import ( |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
type PointerMatcher interface { |
||||
|
Match(str string) bool |
||||
|
} |
||||
|
|
||||
|
type Pointer struct { |
||||
|
ID string `json:"id"` |
||||
|
Aliases []string `json:"aliases"` |
||||
|
} |
||||
|
|
||||
|
func (p *Pointer) AddAlias(alias string) { |
||||
|
if strings.HasPrefix(alias, "lucifer:name:") { |
||||
|
for i, alias2 := range p.Aliases { |
||||
|
if strings.HasPrefix(alias2, "lucifer:name:") { |
||||
|
p.Aliases = append(p.Aliases[:i], p.Aliases[i+1:]...) |
||||
|
break |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
for _, alias2 := range p.Aliases { |
||||
|
if alias2 == alias { |
||||
|
return |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
p.Aliases = append(p.Aliases, alias) |
||||
|
} |
||||
|
|
||||
|
func (p *Pointer) RemoveAlias(alias string) { |
||||
|
for i, alias2 := range p.Aliases { |
||||
|
if alias2 == alias { |
||||
|
p.Aliases = append(p.Aliases[:i], p.Aliases[i+1:]...) |
||||
|
break |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (p *Pointer) Name() string { |
||||
|
for _, alias := range p.Aliases { |
||||
|
if strings.HasPrefix(alias, "lucifer:name:") { |
||||
|
return alias |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (p *Pointer) Matches(matcher PointerMatcher) bool { |
||||
|
if matcher.Match(p.ID) { |
||||
|
return true |
||||
|
} |
||||
|
for _, alias := range p.Aliases { |
||||
|
if matcher.Match(alias) { |
||||
|
return true |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return false |
||||
|
} |
@ -1,2 +1,4 @@ |
|||||
|
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= |
||||
|
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= |
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= |
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= |
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= |
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= |
Write
Preview
Loading…
Cancel
Save
Reference in new issue