main.go 896 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //go:build cli
  2. // +build cli
  3. package main
  4. import (
  5. "context"
  6. "os"
  7. "time"
  8. "github.com/fatih/color"
  9. "github.com/getsentry/sentry-go"
  10. "github.com/porter-dev/porter/cli/cmd/commands"
  11. "github.com/porter-dev/porter/cli/cmd/config"
  12. "github.com/porter-dev/porter/cli/cmd/errors"
  13. )
  14. func main() {
  15. ctx := context.Background()
  16. if errors.SentryDSN != "" {
  17. err := sentry.Init(sentry.ClientOptions{
  18. Dsn: errors.SentryDSN,
  19. Environment: "cli",
  20. Debug: config.Version == "dev",
  21. Release: config.Version,
  22. IgnoreErrors: []string{
  23. "Forbidden",
  24. },
  25. })
  26. if err != nil {
  27. color.New(color.FgRed).Fprintf(os.Stderr, "error initialising sentry: %s\n", err)
  28. os.Exit(1)
  29. }
  30. defer sentry.Flush(2 * time.Second)
  31. }
  32. err := commands.Execute(ctx)
  33. if err != nil {
  34. color.New(color.FgRed).Fprintf(os.Stderr, "error executing command: %s\n", err)
  35. os.Exit(1)
  36. }
  37. }