@@ -24,34 +24,24 @@ type Request struct {
24
24
25
25
// NewRequest returns a request initialized with given arguments
26
26
// An non-nil error will be returned if the provided option values are invalid
27
- << << << < HEAD
28
27
func NewRequest (ctx context.Context ,
29
- path []string , opts OptMap ,
28
+ path []string ,
29
+ opts OptMap ,
30
30
args []string ,
31
31
file files.Directory ,
32
32
root * Command ,
33
33
) (* Request , error ) {
34
- == == == =
35
- func NewRequest (ctx context .Context , path []string , opts OptMap , args []string ,
36
- file files.Directory , root * Command ) (* Request , error ) {
37
- >> >> >> > 90843374 f694708a997c8e6e4d15142610c50cbf
38
- if opts == nil {
39
- opts = make (OptMap )
40
- }
41
34
42
35
cmd , err := root .Get (path )
43
36
if err != nil {
44
37
return nil , err
45
38
}
46
39
47
- << << << < HEAD
48
- err = checkAndConvertOptions (root , opts , path )
49
- == == == =
50
- err = convertOptions (root , opts , path )
51
- >> >> >> > 90843374 f694708a997c8e6e4d15142610c50cbf
40
+ options , err := checkAndConvertOptions (root , opts , path )
41
+
52
42
req := & Request {
53
43
Path : path ,
54
- Options : opts ,
44
+ Options : options ,
55
45
Arguments : args ,
56
46
Files : file ,
57
47
Root : root ,
@@ -109,14 +99,15 @@ func (req *Request) SetOption(name string, value interface{}) {
109
99
return
110
100
}
111
101
112
- << << << < HEAD
113
- func checkAndConvertOptions (root * Command , opts OptMap , path []string ) error {
114
- == == == =
115
- func convertOptions (root * Command , opts OptMap , path []string ) error {
116
- >> >> >> > 90843374 f694708a997c8e6e4d15142610c50cbf
102
+ func checkAndConvertOptions (root * Command , opts OptMap , path []string ) (OptMap , error ) {
117
103
optDefs , err := root .GetOptions (path )
104
+ options := make (OptMap )
105
+
118
106
if err != nil {
119
- return err
107
+ return options , err
108
+ }
109
+ for k , v := range opts {
110
+ options [k ] = v
120
111
}
121
112
122
113
for k , v := range opts {
@@ -134,26 +125,26 @@ func convertOptions(root *Command, opts OptMap, path []string) error {
134
125
if len (str ) == 0 {
135
126
value = "empty value"
136
127
}
137
- return fmt.Errorf ("Could not convert % s to type % q (for option % q )",
128
+ return options , fmt .Errorf ("Could not convert %s to type %q (for option %q)" ,
138
129
value , opt .Type ().String (), "-" + k )
139
130
}
140
- opts [k ] = val
131
+ options [k ] = val
141
132
142
133
} else {
143
- return fmt.Errorf ("Option % q should be type % q , but got type % q ",
134
+ return options , fmt .Errorf ("Option %q should be type %q, but got type %q" ,
144
135
k , opt .Type ().String (), kind .String ())
145
136
}
146
137
}
147
138
148
139
for _ , name := range opt .Names () {
149
140
if _ , ok := opts [name ]; name != k && ok {
150
- return fmt.Errorf ("Duplicate command options were provided (% q and % q )",
141
+ return options , fmt .Errorf ("Duplicate command options were provided (%q and %q)" ,
151
142
k , name )
152
143
}
153
144
}
154
145
}
155
146
156
- return nil
147
+ return options , nil
157
148
}
158
149
159
150
// GetEncoding returns the EncodingType set in a request, falling back to JSON
0 commit comments