Skip to content

Commit b413c9e

Browse files
committed
commands: mountpoint - FieldParser is optional
Neither the host nor the guest need to support this, but if they do we will handle the requests.
1 parent 967584d commit b413c9e

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

internal/commands/mountpoint.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ import (
1818
type (
1919
mountPointHost[T any] interface {
2020
*T
21-
p9fs.FieldParser
2221
p9fs.Mounter
2322
p9fs.HostIdentifier
2423
}
2524
mountPointGuest[T any] interface {
2625
*T
27-
p9fs.FieldParser
2826
p9fs.SystemMaker
2927
p9fs.GuestIdentifier
3028
}
@@ -170,25 +168,44 @@ func (mp *mountPoint[HT, GT, HC, GC]) ParseField(key, value string) error {
170168
guestPrefix = "guest."
171169
)
172170
var (
173-
prefix string
174-
parseFn func(_, _ string) error
171+
prefix string
172+
parser p9fs.FieldParser
173+
)
174+
const (
175+
// TODO: [Go 1.21] use [errors.ErrUnsupported].
176+
unsupported = generic.ConstError("unsupported operation")
177+
unsupportedFmt = "%w: %T does not implement field parser"
175178
)
176179
switch {
177180
case strings.HasPrefix(key, hostPrefix):
178181
prefix = hostPrefix
179-
parseFn = HC(&mp.Host).ParseField
182+
var ok bool
183+
if parser, ok = any(&mp.Host).(p9fs.FieldParser); !ok {
184+
return fmt.Errorf(
185+
unsupportedFmt,
186+
unsupported, &mp.Host,
187+
)
188+
}
180189
case strings.HasPrefix(key, guestPrefix):
181190
prefix = guestPrefix
182-
parseFn = GC(&mp.Guest).ParseField
191+
var ok bool
192+
if parser, ok = any(&mp.Guest).(p9fs.FieldParser); !ok {
193+
return fmt.Errorf(
194+
unsupportedFmt,
195+
unsupported, &mp.Guest,
196+
)
197+
}
183198
default:
184199
const wildcard = "*"
185200
return p9fs.FieldError{
186201
Key: key,
187202
Tried: []string{hostPrefix + wildcard, guestPrefix + wildcard},
188203
}
189204
}
190-
baseKey := key[len(prefix):]
191-
err := parseFn(baseKey, value)
205+
var (
206+
baseKey = key[len(prefix):]
207+
err = parser.ParseField(baseKey, value)
208+
)
192209
if err == nil {
193210
return nil
194211
}

0 commit comments

Comments
 (0)