Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ee/agent-smith/cmd/root.go
2500 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
"fmt"
9
"os"
10
11
goflag "flag"
12
13
"github.com/gitpod-io/gitpod/common-go/log"
14
"github.com/spf13/cobra"
15
)
16
17
var (
18
// ServiceName is the name we use for tracing/logging
19
ServiceName = "agent-smith"
20
// Version of this service - set during build
21
Version = ""
22
)
23
24
var cfgFile string
25
var jsonLog bool
26
var verbose bool
27
28
// rootCmd represents the base command when called without any subcommands
29
var rootCmd = &cobra.Command{
30
Use: "agent-smith",
31
Short: "Moves through workspace pods and finds bad players",
32
PersistentPreRun: func(cmd *cobra.Command, args []string) {
33
os.Args = []string{""}
34
log.Init(ServiceName, Version, jsonLog, verbose)
35
36
// Disable golog, Googles logging framwork for misanthropic
37
err := goflag.Set("stderrthreshold", "5")
38
if err != nil {
39
log.Debugf("error while disabling glog: %v", err)
40
}
41
goflag.Parse()
42
},
43
}
44
45
// Execute adds all child commands to the root command and sets flags appropriately.
46
// This is called by main.main(). It only needs to happen once to the rootCmd.
47
func Execute() {
48
if err := rootCmd.Execute(); err != nil {
49
fmt.Println(err)
50
os.Exit(1)
51
}
52
}
53
54
func init() {
55
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
56
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
57
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
58
}
59
60