PrintDryRunWithFile outputs a dry-run summary for file upload requests. Instead of serializing the Formdata body, it shows file metadata.
(w io.Writer, request client.RawApiRequest, config *core.CliConfig, format, fileField, filePath string, formFields any)
| 218 | // PrintDryRunWithFile outputs a dry-run summary for file upload requests. |
| 219 | // Instead of serializing the Formdata body, it shows file metadata. |
| 220 | func PrintDryRunWithFile(w io.Writer, request client.RawApiRequest, config *core.CliConfig, format, fileField, filePath string, formFields any) error { |
| 221 | dr := NewDryRunAPI() |
| 222 | switch request.Method { |
| 223 | case "POST": |
| 224 | dr.POST(request.URL) |
| 225 | case "PUT": |
| 226 | dr.PUT(request.URL) |
| 227 | case "PATCH": |
| 228 | dr.PATCH(request.URL) |
| 229 | case "DELETE": |
| 230 | dr.DELETE(request.URL) |
| 231 | default: |
| 232 | dr.GET(request.URL) |
| 233 | } |
| 234 | if len(request.Params) > 0 { |
| 235 | dr.Params(request.Params) |
| 236 | } |
| 237 | filePathDisplay := filePath |
| 238 | if filePathDisplay == "" { |
| 239 | filePathDisplay = "<stdin>" |
| 240 | } |
| 241 | fileInfo := map[string]any{ |
| 242 | "file": map[string]string{"field": fileField, "path": filePathDisplay}, |
| 243 | } |
| 244 | if formFields != nil { |
| 245 | fileInfo["form_fields"] = formFields |
| 246 | } |
| 247 | fileInfo["options"] = []string{"WithFileUpload"} |
| 248 | dr.Body(fileInfo) |
| 249 | dr.Set("as", string(request.As)) |
| 250 | dr.Set("appId", config.AppID) |
| 251 | if config.UserOpenId != "" { |
| 252 | dr.Set("userOpenId", config.UserOpenId) |
| 253 | } |
| 254 | fmt.Fprintln(w, "=== Dry Run ===") |
| 255 | if format == "pretty" { |
| 256 | fmt.Fprint(w, dr.Format()) |
| 257 | } else { |
| 258 | output.PrintJson(w, dr) |
| 259 | } |
| 260 | return nil |
| 261 | } |
| 262 | |
| 263 | // PrintDryRun outputs a standardised dry-run summary using DryRunAPI. |
| 264 | // When format is "pretty", outputs human-readable text; otherwise JSON. |