Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ide-service/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/gitpod-io/gitpod/ide-service-api/config"
14
"github.com/spf13/cobra"
15
)
16
17
var (
18
// ServiceName is the name we use for tracing/logging
19
ServiceName = "ide-service"
20
// Version of this service - set during build
21
Version = ""
22
)
23
24
var rootOpts struct {
25
CfgFile string
26
JsonLog bool
27
Verbose bool
28
}
29
30
// rootCmd represents the base command when called without any subcommands
31
var rootCmd = &cobra.Command{
32
Use: ServiceName,
33
Short: "IDE Service API services",
34
PersistentPreRun: func(cmd *cobra.Command, args []string) {
35
log.Init(ServiceName, Version, rootOpts.JsonLog, rootOpts.Verbose)
36
},
37
}
38
39
func Execute() {
40
if err := rootCmd.ExecuteContext(context.Background()); err != nil {
41
log.WithError(err).Error("failed to execute command.")
42
os.Exit(1)
43
}
44
}
45
46
func init() {
47
localConfig := path.Join(os.ExpandEnv("GOMOD"), "..", "config.json")
48
rootCmd.PersistentFlags().StringVar(&rootOpts.CfgFile, "config", localConfig, "config file")
49
rootCmd.PersistentFlags().BoolVar(&rootOpts.JsonLog, "json-log", true, "produce JSON log output on verbose level")
50
rootCmd.PersistentFlags().BoolVar(&rootOpts.Verbose, "verbose", false, "enable verbose JSON logging")
51
}
52
53
func getConfig() *config.ServiceConfiguration {
54
cfg, err := config.Read(rootOpts.CfgFile)
55
if err != nil {
56
log.WithError(err).Fatal("cannot read configuration")
57
}
58
return cfg
59
}
60
61