Start refactor how qemu-system commands are built
This commit is contained in:
parent
153d1b5e1f
commit
fc7fe2e6c0
8 changed files with 427 additions and 0 deletions
48
qemucli/uint_arg.go
Normal file
48
qemucli/uint_arg.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package qemucli
|
||||
|
||||
import (
|
||||
"github.com/AlexSSD7/linsk/utils"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
type UintArg struct {
|
||||
key string
|
||||
value uint64
|
||||
}
|
||||
|
||||
func MustNewUintArg[T constraints.Integer](key string, value T) *UintArg {
|
||||
a, err := NewUintArg(key, uint64(value))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func NewUintArg(key string, value uint64) (*UintArg, error) {
|
||||
a := &UintArg{
|
||||
key: key,
|
||||
value: value,
|
||||
}
|
||||
|
||||
// Preflight arg key/type check.
|
||||
err := validateArgKey(key, a.ValueType())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "validate arg key")
|
||||
}
|
||||
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func (a *UintArg) StringKey() string {
|
||||
return a.key
|
||||
}
|
||||
|
||||
func (a *UintArg) StringValue() string {
|
||||
return utils.UintToStr(a.value)
|
||||
}
|
||||
|
||||
func (a *UintArg) ValueType() ArgAcceptedValue {
|
||||
return ArgAcceptedValueUint
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue