-
Notifications
You must be signed in to change notification settings - Fork 4
/
option_types.go
48 lines (37 loc) · 1.02 KB
/
option_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0
package app
import (
"fmt"
"reflect"
"slices"
"github.com/ironcore-dev/libvirt-provider/api"
)
type GuestAgentOption api.GuestAgent
func (g *GuestAgentOption) String() string {
return string(g.GetAPIGuestAgent())
}
func (g *GuestAgentOption) Set(value string) error {
if g == nil {
return fmt.Errorf("invalid pointer to object type %s", g.Type())
}
options := guestAgentOptionAvailable()
index := slices.Index(options, value)
if index == -1 {
return fmt.Errorf("unsupported option %s", value)
}
*g = GuestAgentOption(value)
return nil
}
func (g *GuestAgentOption) Type() string {
return reflect.TypeOf(*g).String()
}
func (g *GuestAgentOption) GetAPIGuestAgent() api.GuestAgent {
if g == nil || *g == "" {
return api.GuestAgentNone
}
return api.GuestAgent(*g)
}
func guestAgentOptionAvailable() []string {
return []string{string(api.GuestAgentNone), string(api.GuestAgentQemu)}
}