portainer/api/cli/pairlist.go

41 lines
802 B
Go
Raw Normal View History

2016-12-18 05:21:29 +00:00
package cli
import (
2016-12-18 05:21:29 +00:00
"github.com/portainer/portainer"
"fmt"
"gopkg.in/alecthomas/kingpin.v2"
"strings"
)
2016-12-18 05:21:29 +00:00
type pairList []portainer.Pair
2016-12-18 05:21:29 +00:00
// Set implementation for a list of portainer.Pair
func (l *pairList) Set(value string) error {
parts := strings.SplitN(value, "=", 2)
if len(parts) != 2 {
return fmt.Errorf("expected NAME=VALUE got '%s'", value)
}
2016-12-18 05:21:29 +00:00
p := new(portainer.Pair)
p.Name = parts[0]
p.Value = parts[1]
*l = append(*l, *p)
return nil
}
2016-12-18 05:21:29 +00:00
// String implementation for a list of pair
func (l *pairList) String() string {
return ""
}
2016-12-18 05:21:29 +00:00
// IsCumulative implementation for a list of pair
func (l *pairList) IsCumulative() bool {
return true
}
2016-12-18 05:21:29 +00:00
func pairs(s kingpin.Settings) (target *[]portainer.Pair) {
target = new([]portainer.Pair)
s.SetValue((*pairList)(target))
return
}