command: add Covers() for attenuation test, fix incorrect Segments()

This commit is contained in:
Michael Muré
2024-11-12 18:42:59 +01:00
parent c577d73f3e
commit e938d64220
2 changed files with 33 additions and 1 deletions

View File

@@ -98,7 +98,24 @@ func (c Command) Join(segments ...string) Command {
// Segments returns the ordered segments that comprise the Command as a
// slice of strings.
func (c Command) Segments() []string {
return strings.Split(string(c), separator)
if c == separator {
return nil
}
return strings.Split(string(c), separator)[1:]
}
// Covers returns true if the command is identical or a parent of the given other command.
func (c Command) Covers(other Command) bool {
otherSegments := other.Segments()
if len(otherSegments) < len(c.Segments()) {
return false
}
for i, s := range c.Segments() {
if otherSegments[i] != s {
return false
}
}
return true
}
// String returns the composed representation the command. This is also