drone-s3-sync/types.go

72 lines
1.2 KiB
Go
Raw Normal View History

package main
2017-08-28 21:31:49 +00:00
import (
"encoding/json"
)
2016-07-22 00:27:25 +00:00
type DeepStringMapFlag struct {
parts map[string]map[string]string
}
2016-07-22 00:27:25 +00:00
func (d *DeepStringMapFlag) String() string {
return ""
}
2016-07-22 00:27:25 +00:00
func (d *DeepStringMapFlag) Get() map[string]map[string]string {
return d.parts
}
2016-07-22 00:27:25 +00:00
func (d *DeepStringMapFlag) Set(value string) error {
d.parts = map[string]map[string]string{}
err := json.Unmarshal([]byte(value), &d.parts)
if err != nil {
single := map[string]string{}
err := json.Unmarshal([]byte(value), &single)
if err != nil {
return err
}
2016-07-22 00:27:25 +00:00
d.parts["*"] = single
}
return nil
}
2016-07-22 00:27:25 +00:00
type StringMapFlag struct {
parts map[string]string
}
2016-07-22 00:27:25 +00:00
func (s *StringMapFlag) String() string {
return ""
}
2016-07-22 00:27:25 +00:00
func (s *StringMapFlag) Get() map[string]string {
return s.parts
}
2016-07-22 00:27:25 +00:00
func (s *StringMapFlag) Set(value string) error {
s.parts = map[string]string{}
err := json.Unmarshal([]byte(value), &s.parts)
if err != nil {
s.parts["*"] = value
}
return nil
}
2016-07-22 00:27:25 +00:00
type MapFlag struct {
parts map[string]string
}
2016-07-22 00:27:25 +00:00
func (m *MapFlag) String() string {
return ""
}
2016-07-22 00:27:25 +00:00
func (m *MapFlag) Get() map[string]string {
return m.parts
}
2016-07-22 00:27:25 +00:00
func (m *MapFlag) Set(value string) error {
m.parts = map[string]string{}
return json.Unmarshal([]byte(value), &m.parts)
}