|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +package cmd |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "fmt" |
| 8 | + |
| 9 | + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" |
| 10 | + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" |
| 11 | + "github.com/context-dot-dev/context-go-sdk/v2" |
| 12 | + "github.com/context-dot-dev/context-go-sdk/v2/option" |
| 13 | + "github.com/tidwall/gjson" |
| 14 | + "github.com/urfave/cli/v3" |
| 15 | +) |
| 16 | + |
| 17 | +var batchRetrieve = cli.Command{ |
| 18 | + Name: "retrieve", |
| 19 | + Usage: "Check progress and get download links when the batch finishes. Also returns the\nrejected-URL list and webhook signing secret from submission, so nothing is lost\nif the submit response was dropped.", |
| 20 | + Suggest: true, |
| 21 | + Flags: []cli.Flag{ |
| 22 | + &requestflag.Flag[string]{ |
| 23 | + Name: "batch-id", |
| 24 | + Usage: "ID of the batch to retrieve or cancel.", |
| 25 | + Required: true, |
| 26 | + PathParam: "batch_id", |
| 27 | + }, |
| 28 | + &requestflag.Flag[[]string]{ |
| 29 | + Name: "tag", |
| 30 | + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", |
| 31 | + QueryPath: "tags", |
| 32 | + }, |
| 33 | + }, |
| 34 | + Action: handleBatchRetrieve, |
| 35 | + HideHelpCommand: true, |
| 36 | +} |
| 37 | + |
| 38 | +var batchList = cli.Command{ |
| 39 | + Name: "list", |
| 40 | + Usage: "List your batches from newest to oldest. Filter by status or continue with a\ncursor.", |
| 41 | + Suggest: true, |
| 42 | + Flags: []cli.Flag{ |
| 43 | + &requestflag.Flag[string]{ |
| 44 | + Name: "cursor", |
| 45 | + Usage: "Cursor from the previous page.", |
| 46 | + QueryPath: "cursor", |
| 47 | + }, |
| 48 | + &requestflag.Flag[int64]{ |
| 49 | + Name: "limit", |
| 50 | + Usage: "Batches per page. Defaults to 25.", |
| 51 | + QueryPath: "limit", |
| 52 | + }, |
| 53 | + &requestflag.Flag[string]{ |
| 54 | + Name: "status", |
| 55 | + Usage: "Filter by status.", |
| 56 | + QueryPath: "status", |
| 57 | + }, |
| 58 | + &requestflag.Flag[[]string]{ |
| 59 | + Name: "tag", |
| 60 | + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", |
| 61 | + QueryPath: "tags", |
| 62 | + }, |
| 63 | + }, |
| 64 | + Action: handleBatchList, |
| 65 | + HideHelpCommand: true, |
| 66 | +} |
| 67 | + |
| 68 | +var batchCancel = cli.Command{ |
| 69 | + Name: "cancel", |
| 70 | + Usage: "Stop a batch from starting new pages. In-progress pages finish, and unused\ncredits are refunded.", |
| 71 | + Suggest: true, |
| 72 | + Flags: []cli.Flag{ |
| 73 | + &requestflag.Flag[string]{ |
| 74 | + Name: "batch-id", |
| 75 | + Usage: "ID of the batch to retrieve or cancel.", |
| 76 | + Required: true, |
| 77 | + PathParam: "batch_id", |
| 78 | + }, |
| 79 | + &requestflag.Flag[[]string]{ |
| 80 | + Name: "tag", |
| 81 | + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", |
| 82 | + QueryPath: "tags", |
| 83 | + }, |
| 84 | + }, |
| 85 | + Action: handleBatchCancel, |
| 86 | + HideHelpCommand: true, |
| 87 | +} |
| 88 | + |
| 89 | +var batchGetResults = cli.Command{ |
| 90 | + Name: "get-results", |
| 91 | + Usage: "Page through the result records of a finished batch as JSON, in the same order\nas the downloadable result files. Use this instead of downloading and parsing\nthe NDJSON files yourself.", |
| 92 | + Suggest: true, |
| 93 | + Flags: []cli.Flag{ |
| 94 | + &requestflag.Flag[string]{ |
| 95 | + Name: "batch-id", |
| 96 | + Usage: "ID of the batch to retrieve or cancel.", |
| 97 | + Required: true, |
| 98 | + PathParam: "batch_id", |
| 99 | + }, |
| 100 | + &requestflag.Flag[string]{ |
| 101 | + Name: "cursor", |
| 102 | + Usage: "next_cursor from the previous page.", |
| 103 | + QueryPath: "cursor", |
| 104 | + }, |
| 105 | + &requestflag.Flag[int64]{ |
| 106 | + Name: "limit", |
| 107 | + Usage: "Records per page. Defaults to 25. A page can close early so its payload stays under ~8 MB; rely on next_cursor rather than counting records.", |
| 108 | + QueryPath: "limit", |
| 109 | + }, |
| 110 | + &requestflag.Flag[[]string]{ |
| 111 | + Name: "tag", |
| 112 | + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", |
| 113 | + QueryPath: "tags", |
| 114 | + }, |
| 115 | + }, |
| 116 | + Action: handleBatchGetResults, |
| 117 | + HideHelpCommand: true, |
| 118 | +} |
| 119 | + |
| 120 | +var batchSubmit = requestflag.WithInnerFlags(cli.Command{ |
| 121 | + Name: "submit", |
| 122 | + Usage: "Retrieve and normalize a person profile from identifiers.", |
| 123 | + Suggest: true, |
| 124 | + Flags: []cli.Flag{ |
| 125 | + &requestflag.Flag[map[string]any]{ |
| 126 | + Name: "identifiers", |
| 127 | + Usage: "Known identifiers for the person. At least one identifier is required.", |
| 128 | + Required: true, |
| 129 | + BodyPath: "identifiers", |
| 130 | + }, |
| 131 | + &requestflag.Flag[[]string]{ |
| 132 | + Name: "tag", |
| 133 | + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", |
| 134 | + BodyPath: "tags", |
| 135 | + }, |
| 136 | + &requestflag.Flag[int64]{ |
| 137 | + Name: "timeout-ms", |
| 138 | + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", |
| 139 | + BodyPath: "timeoutMS", |
| 140 | + }, |
| 141 | + }, |
| 142 | + Action: handleBatchSubmit, |
| 143 | + HideHelpCommand: true, |
| 144 | +}, map[string][]requestflag.HasOuterFlag{ |
| 145 | + "identifiers": { |
| 146 | + &requestflag.InnerFlag[string]{ |
| 147 | + Name: "identifiers.linkedin-url", |
| 148 | + Usage: "LinkedIn profile URL, e.g. https://www.linkedin.com/in/yahia-bakour/.", |
| 149 | + InnerField: "linkedinUrl", |
| 150 | + }, |
| 151 | + }, |
| 152 | +}) |
| 153 | + |
| 154 | +func handleBatchRetrieve(ctx context.Context, cmd *cli.Command) error { |
| 155 | + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) |
| 156 | + unusedArgs := cmd.Args().Slice() |
| 157 | + if !cmd.IsSet("batch-id") && len(unusedArgs) > 0 { |
| 158 | + cmd.Set("batch-id", unusedArgs[0]) |
| 159 | + unusedArgs = unusedArgs[1:] |
| 160 | + } |
| 161 | + if len(unusedArgs) > 0 { |
| 162 | + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) |
| 163 | + } |
| 164 | + |
| 165 | + options, err := flagOptions( |
| 166 | + cmd, |
| 167 | + apiquery.NestedQueryFormatBrackets, |
| 168 | + apiquery.ArrayQueryFormatComma, |
| 169 | + EmptyBody, |
| 170 | + false, |
| 171 | + ) |
| 172 | + if err != nil { |
| 173 | + return err |
| 174 | + } |
| 175 | + |
| 176 | + params := contextdev.BatchGetParams{} |
| 177 | + |
| 178 | + var res []byte |
| 179 | + options = append(options, option.WithResponseBodyInto(&res)) |
| 180 | + _, err = client.Batch.Get( |
| 181 | + ctx, |
| 182 | + cmd.Value("batch-id").(string), |
| 183 | + params, |
| 184 | + options..., |
| 185 | + ) |
| 186 | + if err != nil { |
| 187 | + return err |
| 188 | + } |
| 189 | + |
| 190 | + obj := gjson.ParseBytes(res) |
| 191 | + format := cmd.Root().String("format") |
| 192 | + explicitFormat := cmd.Root().IsSet("format") |
| 193 | + transform := cmd.Root().String("transform") |
| 194 | + return ShowJSON(obj, ShowJSONOpts{ |
| 195 | + ExplicitFormat: explicitFormat, |
| 196 | + Format: format, |
| 197 | + RawOutput: cmd.Root().Bool("raw-output"), |
| 198 | + Title: "batch retrieve", |
| 199 | + Transform: transform, |
| 200 | + }) |
| 201 | +} |
| 202 | + |
| 203 | +func handleBatchList(ctx context.Context, cmd *cli.Command) error { |
| 204 | + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) |
| 205 | + unusedArgs := cmd.Args().Slice() |
| 206 | + |
| 207 | + if len(unusedArgs) > 0 { |
| 208 | + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) |
| 209 | + } |
| 210 | + |
| 211 | + options, err := flagOptions( |
| 212 | + cmd, |
| 213 | + apiquery.NestedQueryFormatBrackets, |
| 214 | + apiquery.ArrayQueryFormatComma, |
| 215 | + EmptyBody, |
| 216 | + false, |
| 217 | + ) |
| 218 | + if err != nil { |
| 219 | + return err |
| 220 | + } |
| 221 | + |
| 222 | + params := contextdev.BatchListParams{} |
| 223 | + |
| 224 | + var res []byte |
| 225 | + options = append(options, option.WithResponseBodyInto(&res)) |
| 226 | + _, err = client.Batch.List(ctx, params, options...) |
| 227 | + if err != nil { |
| 228 | + return err |
| 229 | + } |
| 230 | + |
| 231 | + obj := gjson.ParseBytes(res) |
| 232 | + format := cmd.Root().String("format") |
| 233 | + explicitFormat := cmd.Root().IsSet("format") |
| 234 | + transform := cmd.Root().String("transform") |
| 235 | + return ShowJSON(obj, ShowJSONOpts{ |
| 236 | + ExplicitFormat: explicitFormat, |
| 237 | + Format: format, |
| 238 | + RawOutput: cmd.Root().Bool("raw-output"), |
| 239 | + Title: "batch list", |
| 240 | + Transform: transform, |
| 241 | + }) |
| 242 | +} |
| 243 | + |
| 244 | +func handleBatchCancel(ctx context.Context, cmd *cli.Command) error { |
| 245 | + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) |
| 246 | + unusedArgs := cmd.Args().Slice() |
| 247 | + if !cmd.IsSet("batch-id") && len(unusedArgs) > 0 { |
| 248 | + cmd.Set("batch-id", unusedArgs[0]) |
| 249 | + unusedArgs = unusedArgs[1:] |
| 250 | + } |
| 251 | + if len(unusedArgs) > 0 { |
| 252 | + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) |
| 253 | + } |
| 254 | + |
| 255 | + options, err := flagOptions( |
| 256 | + cmd, |
| 257 | + apiquery.NestedQueryFormatBrackets, |
| 258 | + apiquery.ArrayQueryFormatComma, |
| 259 | + EmptyBody, |
| 260 | + false, |
| 261 | + ) |
| 262 | + if err != nil { |
| 263 | + return err |
| 264 | + } |
| 265 | + |
| 266 | + params := contextdev.BatchCancelParams{} |
| 267 | + |
| 268 | + var res []byte |
| 269 | + options = append(options, option.WithResponseBodyInto(&res)) |
| 270 | + _, err = client.Batch.Cancel( |
| 271 | + ctx, |
| 272 | + cmd.Value("batch-id").(string), |
| 273 | + params, |
| 274 | + options..., |
| 275 | + ) |
| 276 | + if err != nil { |
| 277 | + return err |
| 278 | + } |
| 279 | + |
| 280 | + obj := gjson.ParseBytes(res) |
| 281 | + format := cmd.Root().String("format") |
| 282 | + explicitFormat := cmd.Root().IsSet("format") |
| 283 | + transform := cmd.Root().String("transform") |
| 284 | + return ShowJSON(obj, ShowJSONOpts{ |
| 285 | + ExplicitFormat: explicitFormat, |
| 286 | + Format: format, |
| 287 | + RawOutput: cmd.Root().Bool("raw-output"), |
| 288 | + Title: "batch cancel", |
| 289 | + Transform: transform, |
| 290 | + }) |
| 291 | +} |
| 292 | + |
| 293 | +func handleBatchGetResults(ctx context.Context, cmd *cli.Command) error { |
| 294 | + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) |
| 295 | + unusedArgs := cmd.Args().Slice() |
| 296 | + if !cmd.IsSet("batch-id") && len(unusedArgs) > 0 { |
| 297 | + cmd.Set("batch-id", unusedArgs[0]) |
| 298 | + unusedArgs = unusedArgs[1:] |
| 299 | + } |
| 300 | + if len(unusedArgs) > 0 { |
| 301 | + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) |
| 302 | + } |
| 303 | + |
| 304 | + options, err := flagOptions( |
| 305 | + cmd, |
| 306 | + apiquery.NestedQueryFormatBrackets, |
| 307 | + apiquery.ArrayQueryFormatComma, |
| 308 | + EmptyBody, |
| 309 | + false, |
| 310 | + ) |
| 311 | + if err != nil { |
| 312 | + return err |
| 313 | + } |
| 314 | + |
| 315 | + params := contextdev.BatchGetResultsParams{} |
| 316 | + |
| 317 | + var res []byte |
| 318 | + options = append(options, option.WithResponseBodyInto(&res)) |
| 319 | + _, err = client.Batch.GetResults( |
| 320 | + ctx, |
| 321 | + cmd.Value("batch-id").(string), |
| 322 | + params, |
| 323 | + options..., |
| 324 | + ) |
| 325 | + if err != nil { |
| 326 | + return err |
| 327 | + } |
| 328 | + |
| 329 | + obj := gjson.ParseBytes(res) |
| 330 | + format := cmd.Root().String("format") |
| 331 | + explicitFormat := cmd.Root().IsSet("format") |
| 332 | + transform := cmd.Root().String("transform") |
| 333 | + return ShowJSON(obj, ShowJSONOpts{ |
| 334 | + ExplicitFormat: explicitFormat, |
| 335 | + Format: format, |
| 336 | + RawOutput: cmd.Root().Bool("raw-output"), |
| 337 | + Title: "batch get-results", |
| 338 | + Transform: transform, |
| 339 | + }) |
| 340 | +} |
| 341 | + |
| 342 | +func handleBatchSubmit(ctx context.Context, cmd *cli.Command) error { |
| 343 | + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) |
| 344 | + unusedArgs := cmd.Args().Slice() |
| 345 | + |
| 346 | + if len(unusedArgs) > 0 { |
| 347 | + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) |
| 348 | + } |
| 349 | + |
| 350 | + options, err := flagOptions( |
| 351 | + cmd, |
| 352 | + apiquery.NestedQueryFormatBrackets, |
| 353 | + apiquery.ArrayQueryFormatComma, |
| 354 | + ApplicationJSON, |
| 355 | + false, |
| 356 | + ) |
| 357 | + if err != nil { |
| 358 | + return err |
| 359 | + } |
| 360 | + |
| 361 | + params := contextdev.BatchSubmitParams{} |
| 362 | + |
| 363 | + var res []byte |
| 364 | + options = append(options, option.WithResponseBodyInto(&res)) |
| 365 | + _, err = client.Batch.Submit(ctx, params, options...) |
| 366 | + if err != nil { |
| 367 | + return err |
| 368 | + } |
| 369 | + |
| 370 | + obj := gjson.ParseBytes(res) |
| 371 | + format := cmd.Root().String("format") |
| 372 | + explicitFormat := cmd.Root().IsSet("format") |
| 373 | + transform := cmd.Root().String("transform") |
| 374 | + return ShowJSON(obj, ShowJSONOpts{ |
| 375 | + ExplicitFormat: explicitFormat, |
| 376 | + Format: format, |
| 377 | + RawOutput: cmd.Root().Bool("raw-output"), |
| 378 | + Title: "batch submit", |
| 379 | + Transform: transform, |
| 380 | + }) |
| 381 | +} |
0 commit comments