-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.go
97 lines (75 loc) · 2.32 KB
/
parse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package cli
import (
"bytes"
"encoding/json"
"fmt"
"os"
"github.com/spf13/pflag"
)
// TODO: move these to exported types within an internal package
type XCreatePoolInputs createBalancerPoolInputs
type XCreatePoolInputsExceptions struct {
XCreatePoolInputs
Other *string // Other won't raise an error
}
type XCreateStableswapPoolInputs createStableswapPoolInputs
type XCreateStableswapPoolInputsExceptions struct {
XCreateStableswapPoolInputs
Other *string // Other won't raise an error
}
// UnmarshalJSON should error if there are fields unexpected.
func (release *createBalancerPoolInputs) UnmarshalJSON(data []byte) error {
var createPoolE XCreatePoolInputsExceptions
dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields() // Force
if err := dec.Decode(&createPoolE); err != nil {
return err
}
*release = createBalancerPoolInputs(createPoolE.XCreatePoolInputs)
return nil
}
func parseCreateBalancerPoolFlags(fs *pflag.FlagSet) (*createBalancerPoolInputs, error) {
pool := &createBalancerPoolInputs{}
poolFile, _ := fs.GetString(FlagPoolFile)
if poolFile == "" {
return nil, fmt.Errorf("must pass in a pool json using the --%s flag", FlagPoolFile)
}
contents, err := os.ReadFile(poolFile)
if err != nil {
return nil, err
}
// make exception if unknown field exists
err = pool.UnmarshalJSON(contents)
if err != nil {
return nil, err
}
return pool, nil
}
// UnmarshalJSON should error if there are fields unexpected.
func (release *createStableswapPoolInputs) UnmarshalJSON(data []byte) error {
var createPoolE XCreateStableswapPoolInputsExceptions
dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields() // Force
if err := dec.Decode(&createPoolE); err != nil {
return err
}
*release = createStableswapPoolInputs(createPoolE.XCreateStableswapPoolInputs)
return nil
}
func parseCreateStableswapPoolFlags(fs *pflag.FlagSet) (*createStableswapPoolInputs, error) {
pool := &createStableswapPoolInputs{}
poolFile, _ := fs.GetString(FlagPoolFile)
if poolFile == "" {
return nil, fmt.Errorf("must pass in a pool json using the --%s flag", FlagPoolFile)
}
contents, err := os.ReadFile(poolFile)
if err != nil {
return nil, err
}
// make exception if unknown field exists
err = pool.UnmarshalJSON(contents)
if err != nil {
return nil, err
}
return pool, nil
}