MCPcopy
hub / github.com/larksuite/cli / apiRun

Function apiRun

cmd/api/api.go:213–298  ·  view source on GitHub ↗
(opts *APIOptions)

Source from the content-addressed store, hash-verified

211}
212
213func apiRun(opts *APIOptions) error {
214 f := opts.Factory
215 opts.As = f.ResolveAs(opts.Ctx, opts.Cmd, opts.As)
216
217 if err := f.CheckStrictMode(opts.Ctx, opts.As); err != nil {
218 return err
219 }
220
221 if opts.PageAll && opts.Output != "" {
222 return errs.NewValidationError(errs.SubtypeInvalidArgument,
223 "--output and --page-all are mutually exclusive").
224 WithHint("drop --page-all to save a binary response, or drop --output to paginate JSON").
225 WithParams(
226 errs.InvalidParam{Name: "--output", Reason: "conflicts with --page-all"},
227 errs.InvalidParam{Name: "--page-all", Reason: "conflicts with --output"},
228 )
229 }
230 if err := output.ValidateJqFlags(opts.JqExpr, opts.Output, opts.Format); err != nil {
231 return err
232 }
233
234 request, fileMeta, err := buildAPIRequest(opts)
235 if err != nil {
236 return err
237 }
238
239 config, err := f.Config()
240 if err != nil {
241 return err
242 }
243
244 if opts.DryRun {
245 if fileMeta != nil {
246 return cmdutil.PrintDryRunWithFile(f.IOStreams.Out, request, config, opts.Format, fileMeta.FieldName, fileMeta.FilePath, fileMeta.FormFields)
247 }
248 return apiDryRun(f, request, config, opts.Format)
249 }
250 // Identity info is now included in the JSON envelope; skip stderr printing.
251 // cmdutil.PrintIdentity(f.IOStreams.ErrOut, opts.As, config, f.IdentityAutoDetected)
252
253 ac, err := f.NewAPIClientWithConfig(config)
254 if err != nil {
255 return err
256 }
257
258 out := f.IOStreams.Out
259 format, formatOK := output.ParseFormat(opts.Format)
260 if !formatOK {
261 fmt.Fprintf(f.IOStreams.ErrOut, "warning: unknown format %q, falling back to json\n", opts.Format)
262 }
263
264 if opts.PageAll {
265 return apiPaginate(opts.Ctx, ac, request, format, opts.JqExpr, out, f.IOStreams.ErrOut, opts.Cmd.CommandPath(),
266 client.PaginationOptions{PageLimit: opts.PageLimit, PageDelay: opts.PageDelay})
267 }
268
269 resp, err := ac.DoAPI(opts.Ctx, request)
270 if err != nil {

Calls 15

NewValidationErrorFunction · 0.92
ValidateJqFlagsFunction · 0.92
PrintDryRunWithFileFunction · 0.92
ParseFormatFunction · 0.92
MarkRawFunction · 0.92
HandleResponseFunction · 0.92
buildAPIRequestFunction · 0.85
apiDryRunFunction · 0.85
apiPaginateFunction · 0.85
ResolveAsMethod · 0.80
CheckStrictModeMethod · 0.80
WithParamsMethod · 0.80