databricks-cli/main.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.3 KiB
Go
Raw Normal View History

2022-05-13 13:30:22 +00:00
package main
2022-05-14 17:56:09 +00:00
import (
"context"
2025-02-04 15:25:59 +00:00
"encoding/json"
2025-02-03 03:18:38 +00:00
"fmt"
"os"
"github.com/databricks/cli/cmd"
"github.com/databricks/cli/cmd/root"
2025-02-03 03:18:38 +00:00
"github.com/databricks/cli/libs/telemetry"
2025-02-21 17:05:42 +00:00
"github.com/databricks/databricks-sdk-go/logger"
2022-05-14 17:56:09 +00:00
)
2022-05-13 13:30:22 +00:00
func main() {
ctx := context.Background()
2025-02-03 03:18:38 +00:00
2025-02-24 17:09:21 +00:00
// A new process is spawned for uploading telemetry data. We handle this separately
2025-02-03 03:18:38 +00:00
// from the rest of the CLI commands.
// This is done because [root.Execute] spawns a new process to run the
// "telemetry upload" command if there are logs to be uploaded. Having this outside
// of [root.Execute] ensures that the telemetry upload process is not spawned
// infinitely in a recursive manner.
2025-02-03 03:24:09 +00:00
if len(os.Args) == 3 && os.Args[1] == "telemetry" && os.Args[2] == "upload" {
2025-02-28 16:52:47 +00:00
// Suppress info logs (and lower) from the SDK. This ensures that INFO / DEBUG logs
2025-02-27 11:58:43 +00:00
// from the SDK are not printed to stdout / stderr.
2025-02-21 17:05:42 +00:00
logger.DefaultLogger = &logger.SimpleLogger{
2025-02-28 16:52:47 +00:00
Level: logger.LevelWarn,
2025-02-21 17:05:42 +00:00
}
2025-02-24 17:05:19 +00:00
resp, err := telemetry.Upload(ctx)
2025-02-03 03:18:38 +00:00
if err != nil {
2025-02-27 11:47:26 +00:00
fmt.Fprintf(os.Stderr, "error: %s\n", err)
2025-02-03 03:18:38 +00:00
os.Exit(1)
}
2025-02-27 11:47:26 +00:00
fmt.Printf("Telemetry logs uploaded successfully\n")
fmt.Println("Response:")
2025-02-04 15:25:59 +00:00
b, err := json.Marshal(resp)
if err == nil {
2025-02-27 11:47:26 +00:00
fmt.Println(string(b))
2025-02-04 15:25:59 +00:00
}
2025-02-03 03:18:38 +00:00
os.Exit(0)
}
err := root.Execute(ctx, cmd.New(ctx))
if err != nil {
os.Exit(1)
}
2022-05-13 13:30:22 +00:00
}