2015-11-19 00:32:44 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "encoding/json"
|
|
|
|
|
2016-07-22 00:27:25 +00:00
|
|
|
type DeepStringMapFlag struct {
|
|
|
|
parts map[string]map[string]string
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-22 00:27:25 +00:00
|
|
|
func (d *DeepStringMapFlag) String() string {
|
|
|
|
return ""
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-22 00:27:25 +00:00
|
|
|
func (d *DeepStringMapFlag) Get() map[string]map[string]string {
|
|
|
|
return d.parts
|
|
|
|
}
|
2015-11-19 00:32:44 +00:00
|
|
|
|
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 {
|
2015-11-19 00:32:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-07-22 00:27:25 +00:00
|
|
|
|
|
|
|
d.parts["*"] = single
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-07-22 00:27:25 +00:00
|
|
|
type StringMapFlag struct {
|
|
|
|
parts map[string]string
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-22 00:27:25 +00:00
|
|
|
func (s *StringMapFlag) String() string {
|
|
|
|
return ""
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-22 00:27:25 +00:00
|
|
|
func (s *StringMapFlag) Get() map[string]string {
|
|
|
|
return s.parts
|
|
|
|
}
|
2015-11-19 00:32:44 +00:00
|
|
|
|
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
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-07-22 00:27:25 +00:00
|
|
|
type MapFlag struct {
|
|
|
|
parts map[string]string
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-22 00:27:25 +00:00
|
|
|
func (m *MapFlag) String() string {
|
|
|
|
return ""
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-22 00:27:25 +00:00
|
|
|
func (m *MapFlag) Get() map[string]string {
|
|
|
|
return m.parts
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|
|
|
|
|
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)
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|