package cmd
import (
"context"
"os"
"path"
"github.com/gitpod-io/gitpod/common-go/log"
"github.com/spf13/cobra"
)
var (
ServiceName = "ide-metrics"
Version = ""
)
var rootOpts struct {
CfgFile string
JsonLog bool
Verbose bool
}
var rootCmd = &cobra.Command{
Use: ServiceName,
Short: "IDE Metrics API services",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, rootOpts.JsonLog, rootOpts.Verbose)
},
}
func Execute() {
if err := rootCmd.ExecuteContext(context.Background()); err != nil {
log.WithError(err).Error("failed to execute command.")
os.Exit(1)
}
}
func init() {
localConfig := path.Join(os.ExpandEnv("GOMOD"), "..", "config.json")
rootCmd.PersistentFlags().StringVar(&rootOpts.CfgFile, "config", localConfig, "config file")
rootCmd.PersistentFlags().BoolVar(&rootOpts.JsonLog, "json-log", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVar(&rootOpts.Verbose, "verbose", false, "enable verbose JSON logging")
}