MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / initCmd

Function initCmd

cli/cmd/init.go:304–489  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

302}
303
304func initCmd(cmd *cobra.Command, args []string) (initCommandError error) {
305 ctx := cmd.Context()
306 source, destination, specPath, acceptDefaults, disableAI, resumeConversation, disablePlatform, err := parseFlags(cmd)
307 analytics.TrackInitStarted(ctx, invocationUUID.UUID, analytics.InitEvent{
308 Source: source,
309 Destination: destination,
310 AcceptDefaults: acceptDefaults,
311 SpecPath: specPath,
312 Error: err,
313 })
314 defer func() {
315 analytics.TrackInitCompleted(ctx, invocationUUID.UUID, analytics.InitEvent{
316 Source: source,
317 Destination: destination,
318 AcceptDefaults: acceptDefaults,
319 SpecPath: specPath,
320 Error: initCommandError,
321 })
322 }()
323 if err != nil {
324 return err
325 }
326
327 authClient := cqauth.NewTokenClient()
328 token, err := authClient.GetToken()
329 var user *cqapi.User
330 if err == nil {
331 user, _ = auth.GetUser(cmd.Context(), token)
332 }
333
334 team, _ := auth.GetTeamForToken(cmd.Context(), token)
335
336 // If the user has a CloudQuery Platform tenant (cloud login, or a
337 // CQ_PLATFORM_TOKEN), scaffold a source-only spec that targets the platform
338 // destination (auto-injected at sync time), skipping the destination prompt
339 // and AI. --disable-platform opts out (normal source+destination spec); an
340 // explicit --destination also takes the normal path.
341 platformURL, platformTenant := "", false
342 if !disablePlatform {
343 platformURL, platformTenant = platform.DetectTenant(ctx, token.Value, team)
344 }
345
346 apiClient, err := api.NewAnonymousClient()
347 var apiClientWithoutRetries *cqapi.ClientWithResponses
348 if err != nil {
349 return err
350 }
351 if user != nil {
352 apiClient, err = api.NewClient(token.Value)
353 if err != nil {
354 return err
355 }
356
357 apiClientWithoutRetries, err = api.NewClient(token.Value, cqapi.WithHTTPClient(http.DefaultClient))
358 if err != nil {
359 return err
360 }
361 }

Callers

nothing calls this directly

Calls 15

parseFlagsFunction · 0.85
aiCmdFunction · 0.85
pluginFilterFunction · 0.85
selectSourceFunction · 0.85
normalizePluginPathFunction · 0.85
selectDestinationFunction · 0.85
configForSourcePluginFunction · 0.85
linkForPluginFunction · 0.85
PrintlnMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected