Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/blobserve/cmd/root.go
2498 views
1
// Copyright (c) 2020 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
"fmt"
10
"os"
11
12
containerd_log "github.com/containerd/containerd/log"
13
"github.com/spf13/cobra"
14
15
"github.com/gitpod-io/gitpod/common-go/log"
16
"github.com/gitpod-io/gitpod/common-go/tracing"
17
)
18
19
var (
20
// ServiceName is the name we use for tracing/logging
21
ServiceName = "blobserve"
22
// Version of this service - set during build
23
Version = ""
24
)
25
26
// rootCmd represents the base command when called without any subcommands
27
var rootCmd = &cobra.Command{
28
Use: "blobserve",
29
Short: "This service provides static assets from OCI images",
30
Args: cobra.MinimumNArgs(1),
31
PersistentPreRun: func(cmd *cobra.Command, args []string) {
32
log.Init(ServiceName, Version, jsonLog, verbose)
33
34
// configure containerd log with gitpod-io configuration
35
containerd_log.WithLogger(context.Background(), log.Log)
36
},
37
}
38
39
// Execute adds all child commands to the root command and sets flags appropriately.
40
// This is called by main.main(). It only needs to happen once to the rootCmd.
41
func Execute() {
42
closer := tracing.Init("blobserve")
43
if closer != nil {
44
defer closer.Close()
45
}
46
if err := rootCmd.Execute(); err != nil {
47
fmt.Println(err)
48
os.Exit(1)
49
}
50
}
51
52
func init() {
53
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
54
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
55
}
56
57