Path: blob/main/components/content-service/cmd/root.go
2498 views
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import (7"encoding/json"8"fmt"9"os"1011"github.com/gitpod-io/gitpod/common-go/log"12"github.com/gitpod-io/gitpod/common-go/tracing"13"github.com/gitpod-io/gitpod/content-service/api/config"14"github.com/spf13/cobra"15)1617var (18// ServiceName is the name we use for tracing/logging19ServiceName = "content-service"20// Version of this service - set during build21Version = ""22)2324var jsonLog bool25var verbose bool26var configFile string2728var rootCmd = &cobra.Command{29Use: "content-service",30Short: "Content service",31PersistentPreRun: func(cmd *cobra.Command, args []string) {32log.Init(ServiceName, Version, jsonLog, verbose)33},34}3536// Execute runs this main command37func Execute() {38closer := tracing.Init(ServiceName)39if closer != nil {40defer closer.Close()41}4243if err := rootCmd.Execute(); err != nil {44fmt.Println(err)45os.Exit(1)46}47}4849func getConfig() *config.ServiceConfig {50ctnt, err := os.ReadFile(configFile)51if err != nil {52log.WithError(fmt.Errorf("cannot read config: %w", err)).Error("cannot read configuration. Maybe missing --config?")53os.Exit(1)54}5556var cfg config.ServiceConfig57err = json.Unmarshal(ctnt, &cfg)58if err != nil {59log.WithError(err).Error("cannot read configuration. Maybe missing --config?")60os.Exit(1)61}6263return &cfg64}6566func init() {67rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")68rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")69rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "config file")70}717273