MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / NewCmdRoot

Function NewCmdRoot

cli/cmd/root.go:44–235  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42)
43
44func NewCmdRoot() *cobra.Command {
45 logLevel := enum.NewEnum([]string{"trace", "debug", "info", "warn", "error"}, "info")
46 logFormat := enum.NewEnum([]string{"text", "json"}, "text")
47 telemetryLevel := enum.NewEnum([]string{"none", "errors", "stats", "all"}, "all")
48 noLogFile := false
49 logFileName := "cloudquery.log"
50 logFileOverwrite := false
51 sentryDsn := sentryDsnDefault
52 var err error
53 if invocationUUID.UUID, err = guuid.NewRandom(); err != nil {
54 fmt.Fprintf(os.Stderr, "failed to generate invocation uuid: %v", err)
55 os.Exit(1)
56 }
57 secretAwareRedactor = secrets.NewSecretAwareRedactor()
58
59 // support legacy telemetry environment variable,
60 // but the newer CQ_TELEMETRY_LEVEL environment variable takes precedence
61 defaultTelemetryValue := telemetryLevel.Value
62 legacyTelemetry := os.Getenv("CQ_NO_TELEMETRY")
63 if legacyTelemetry != "" {
64 defaultTelemetryValue = "none"
65 }
66 err = telemetryLevel.Set(env.GetEnvOrDefault("CQ_TELEMETRY_LEVEL", defaultTelemetryValue))
67 if err != nil {
68 fmt.Fprintf(os.Stderr, "failed to set telemetry level: %v", err)
69 os.Exit(1)
70 }
71
72 cmd := &cobra.Command{
73 Use: "cloudquery",
74 Short: rootShort,
75 Long: rootLong,
76 Version: Version,
77 PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
78 zerolog.TimestampFunc = func() time.Time {
79 return time.Now().UTC()
80 }
81
82 // Don't print usage on command errors.
83 // PersistentPreRunE runs after argument parsing, so errors during parsing will result in printing the help
84 cmd.SilenceUsage = true
85 var err error
86
87 if logFile, err = initLogging(noLogFile, logLevel, logFormat, logConsole, logFileName, logFileOverwrite); err != nil {
88 return err
89 }
90
91 oc, err := otelConfig()
92 if err != nil {
93 return err
94 }
95 if oc.Endpoint != "" {
96 loggingShutdownFn, err = otel.SetupOtel(context.Background(), log.Logger, oc)
97 if err != nil {
98 return fmt.Errorf("failed to setup OpenTelemetry: %w", err)
99 }
100 log.Logger = log.Logger.Hook(otel.NewOTELLoggerHook(invocationUUID.String()))
101 log.Info().Str("otel_logs_endpoint", oc.Endpoint).Msg("otel logs endpoint set")

Callers 15

TestMigrateFunction · 0.70
generateDocsFunction · 0.70
TestTestConnectionFunction · 0.70
TestAddonDownloadFunction · 0.70
TestAddonDownloadStdoutFunction · 0.70
TestSwitchFunction · 0.70
TestInitFunction · 0.70
getTablesCommandFunction · 0.70
TestValidateConfigFunction · 0.70
TestPluginPublishFunction · 0.70

Calls 15

SetMethod · 0.95
StringMethod · 0.95
initLoggingFunction · 0.85
otelConfigFunction · 0.85
initAnalyticsFunction · 0.85
initSentryFunction · 0.85
newCmdPluginDocsDownloadFunction · 0.85
newCmdPluginDocsUploadFunction · 0.85
newCmdPluginInstallFunction · 0.85
newCmdPluginPublishFunction · 0.85
newCmdAddonDownloadFunction · 0.85

Tested by 15

TestMigrateFunction · 0.56
generateDocsFunction · 0.56
TestTestConnectionFunction · 0.56
TestAddonDownloadFunction · 0.56
TestAddonDownloadStdoutFunction · 0.56
TestSwitchFunction · 0.56
TestInitFunction · 0.56
getTablesCommandFunction · 0.56
TestValidateConfigFunction · 0.56
TestPluginPublishFunction · 0.56