2022-08-15 17:13:45 +00:00
|
|
|
package cliutils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/multiformats/go-multiaddr"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MultiaddrSlice struct {
|
|
|
|
Values *[]multiaddr.Multiaddr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (k *MultiaddrSlice) Set(value string) error {
|
2023-01-03 19:51:43 +00:00
|
|
|
addresses := strings.Split(value, ",")
|
|
|
|
for _, addr := range addresses {
|
|
|
|
ma, err := multiaddr.NewMultiaddr(addr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*k.Values = append(*k.Values, ma)
|
2022-08-15 17:13:45 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-09-11 14:24:05 +00:00
|
|
|
func (k *MultiaddrSlice) String() string {
|
|
|
|
if k.Values == nil {
|
2022-08-15 17:13:45 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
var output []string
|
2023-09-11 14:24:05 +00:00
|
|
|
for _, v := range *k.Values {
|
2022-08-15 17:13:45 +00:00
|
|
|
output = append(output, v.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Join(output, ", ")
|
|
|
|
}
|
|
|
|
|
|
|
|
type MultiaddrValue struct {
|
|
|
|
Value **multiaddr.Multiaddr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MultiaddrValue) Set(value string) error {
|
|
|
|
ma, err := multiaddr.NewMultiaddr(value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*v.Value = new(multiaddr.Multiaddr)
|
|
|
|
**v.Value = ma
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MultiaddrValue) String() string {
|
|
|
|
if v.Value == nil || *v.Value == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return (**v.Value).String()
|
|
|
|
}
|