@@ -15,6 +15,9 @@ package openapi
1515
1616import (
1717 "fmt"
18+ "io/ioutil"
19+ "strings"
20+
1821 "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
1922 "github.com/aliyun/aliyun-cli/cli"
2023 "github.com/aliyun/aliyun-cli/meta"
@@ -42,8 +45,11 @@ func (a *RpcInvoker) Prepare(ctx *cli.Context) error {
4245
4346 // assign parameters
4447 for _ , f := range ctx .UnknownFlags ().Flags () {
48+ if strings .HasSuffix (f .Name , "-FILE" ) {
49+ f .Name = strings .TrimSuffix (f .Name , "-FILE" )
50+ replaceValueWithFile (f )
51+ }
4552 param := api .FindParameter (f .Name )
46- // cli.Printf("flag: %s %v\n", f.Name, param)
4753 if param == nil {
4854 return & InvalidParameterError {Name : f .Name , api : api , flags : ctx .Flags ()}
4955 }
@@ -85,154 +91,11 @@ func (a *RpcInvoker) Call() (*responses.CommonResponse, error) {
8591 return resp , err
8692}
8793
88- // Deprecated Code
89- //
90- //func (c *Caller) InvokeRpc(ctx *cli.Context, product *meta.Product, apiName string) error {
91- // api, ok := c.library.GetApi(product.Code, product.Version, apiName)
92- // if !ok {
93- // return &InvalidApiError{Name: apiName, product: product}
94- // }
95- //
96- // //
97- // // call OpenApi
98- // // return: if check failed return error, otherwise return nil
99- // client, request, err := c.InitClient(ctx, product, true)
100- // if err != nil {
101- // return err
102- // }
103- //
104- // request.ApiName = apiName
105- // err = c.FillRpcParameters(ctx, request, &api)
106- // if err != nil {
107- // return err
108- // }
109- //
110- // request.Scheme = api.GetProtocol()
111- // request.Method = api.GetMethod()
112- //
113- // err = c.UpdateRequest(ctx, request)
114- // if err != nil {
115- // return err
116- // }
117- //
118- // if v, ok := PagerFlag.GetValue(); ok {
119- // pager := GetPager(v)
120- // r, err := c.InvokeRpcWithPager(client, request, pager)
121- // if err != nil {
122- // ctx.Command().PrintFailed(err, "")
123- // } else {
124- // filter, err := GetOutputFilter()
125- // if err != nil {
126- // ctx.Command().PrintFailed(err,"init output filter failed")
127- // return nil
128- // }
129- //
130- // if filter != nil {
131- // r, err = filter.FilterOutput(r)
132- // if err != nil {
133- // ctx.Command().PrintFailed(err,"output filter process failed")
134- // return nil
135- // }
136- // }
137- // cli.Println(r)
138- // if err != nil {
139- // ctx.Command().PrintFailed(err, "")
140- // }
141- // return nil
142- // }
143- // }
144- //
145- // // waiter := NewWaiterWithCTX(ctx, client, request)
146- //
147- //
148- // filter, err := GetOutputFilter()
149- // if err != nil {
150- // ctx.Command().PrintFailed(err,"init output filter failed")
151- // return nil
152- // }
153- //
154- // if filter != nil {
155- // out, err = filter.FilterOutput(out)
156- // if err != nil {
157- // ctx.Command().PrintFailed(err,"output filter process failed")
158- // return nil
159- // }
160- // }
161- // cli.Println(out)
162- //
163- // //
164- // return nil
165- //}
166- //
167- //func (c *Caller) InvokeRpcForce(ctx *cli.Context, product *meta.Product, apiName string) {
168- // //
169- // // call OpenApi
170- // // return: if check failed return error, otherwise return nil
171- // client, request, err := c.InitClient(ctx, product, true)
172- //
173- // if err != nil {
174- // ctx.Command().PrintFailed(fmt.Errorf("init client failed: %v", err), "")
175- // return
176- // }
177- //
178- //
179- // err = c.UpdateRequest(ctx, request)
180- // if err != nil {
181- // ctx.Command().PrintFailed(err, "")
182- // return
183- // }
184- //
185- // resp, err := client.ProcessCommonRequest(request)
186- // if err != nil {
187- // ctx.Command().PrintFailed(err, "")
188- // }
189- //
190- // // err = outputProcessor(ctx, resp.GetHttpContentString())
191- // //if err != nil {
192- // // ctx.Command().PrintFailed(err, "")
193- // //}
194- //
195- // out := resp.GetHttpContentString()
196- //
197- // filter, err := GetOutputFilter()
198- //
199- // if err != nil {
200- // ctx.Command().PrintFailed(err,"init output filter failed")
201- // return
202- // }
203- //
204- // if filter != nil {
205- // out, err = filter.FilterOutput(out)
206- // if err != nil {
207- // ctx.Command().PrintFailed(err,"output filter process failed")
208- // return
209- // }
210- // }
211- // cli.Println(out)
212- //}
213- //
214- //func (c *Caller) FillRpcParameters(ctx *cli.Context, request *requests.CommonRequest, api *meta.Api) error {
215- //
216- //}
217- //
218- //func (c *Caller) InvokeRpcWithPager(client *sdk.Client, request *requests.CommonRequest, pager *Pager) (string, error) {
219- // for {
220- // resp, err := client.ProcessCommonRequest(request)
221- // if err != nil {
222- // return "", fmt.Errorf("call failed %s", err)
223- // }
224- // //
225- // // jmespath.Parser{}
226- // err = pager.FeedResponse(resp.GetHttpContentBytes())
227- // if err != nil {
228- // return "", fmt.Errorf("call failed %s", err)
229- // }
230- //
231- // if !pager.HasMore() {
232- // break
233- // }
234- // pager.MoveNextPage(request)
235- // }
236- //
237- // return pager.GetResponseCollection(), nil
238- //}
94+ func replaceValueWithFile (f * cli.Flag ) {
95+ value , _ := f .GetValue ()
96+ data , err := ioutil .ReadFile (value )
97+ if err != nil {
98+ panic (err )
99+ }
100+ f .SetValue (string (data ))
101+ }
0 commit comments