Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ide-metrics/cmd/root.go
2498 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"context"
9
"os"
10
"path"
11
12
"github.com/gitpod-io/gitpod/common-go/log"
13
"github.com/spf13/cobra"
14
)
15
16
var (
17
// ServiceName is the name we use for tracing/logging
18
ServiceName = "ide-metrics"
19
// Version of this service - set during build
20
Version = ""
21
)
22
23
var rootOpts struct {
24
CfgFile string
25
JsonLog bool
26
Verbose bool
27
}
28
29
// rootCmd represents the base command when called without any subcommands
30
var rootCmd = &cobra.Command{
31
Use: ServiceName,
32
Short: "IDE Metrics API services",
33
PersistentPreRun: func(cmd *cobra.Command, args []string) {
34
log.Init(ServiceName, Version, rootOpts.JsonLog, rootOpts.Verbose)
35
},
36
}
37
38
func Execute() {
39
if err := rootCmd.ExecuteContext(context.Background()); err != nil {
40
log.WithError(err).Error("failed to execute command.")
41
os.Exit(1)
42
}
43
}
44
45
func init() {
46
localConfig := path.Join(os.ExpandEnv("GOMOD"), "..", "config.json")
47
rootCmd.PersistentFlags().StringVar(&rootOpts.CfgFile, "config", localConfig, "config file")
48
rootCmd.PersistentFlags().BoolVar(&rootOpts.JsonLog, "json-log", true, "produce JSON log output on verbose level")
49
rootCmd.PersistentFlags().BoolVar(&rootOpts.Verbose, "verbose", false, "enable verbose JSON logging")
50
}
51
52