blob: 5a7b038ca9618ee3c5a6e7a12f91d1491db81c17 [file] [log] [blame]
Matteo Scandoloa4285862020-12-01 18:10:10 -08001/*
Joey Armstrongaadcaa42024-02-01 19:54:17 -05002 * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandoloa4285862020-12-01 18:10:10 -08003
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package utils
18
19import (
20 "flag"
21 "fmt"
David K. Bainbridge06631892021-08-19 13:07:00 +000022 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Matteo Scandoloa4285862020-12-01 18:10:10 -080023)
24
25const (
26 defaultLogLevel = "WARN"
27 defaultLogFormat = "json" // or "console"
28 defaultBBsimSadisPort = 50074
29)
30
31type ConfigFlags struct {
32 LogLevel string
33 LogFormat string
34 Kubeconfig string
35 BBsimSadisPort int
36}
37
38func NewConfigFlags() *ConfigFlags {
39 flags := &ConfigFlags{
Matteo Scandolo06e564f2022-03-22 15:45:26 -070040 LogLevel: defaultLogLevel,
41 LogFormat: defaultLogFormat,
42 Kubeconfig: "",
Matteo Scandoloa4285862020-12-01 18:10:10 -080043 BBsimSadisPort: defaultBBsimSadisPort,
44 }
45 return flags
46}
47
48func (cf *ConfigFlags) ParseCommandArguments() {
49 help := fmt.Sprintf("Log level (debug, infor, warn, error)")
50 flag.StringVar(&(cf.LogLevel), "log_level", defaultLogLevel, help)
51
52 help = fmt.Sprintf("Log format (json or console) ")
53 logFormat := flag.String("log_format", defaultLogFormat, help)
54
55 flag.StringVar(&(cf.Kubeconfig), "kubeconfig", "", "Absolute path to the kubeconfig file")
56 flag.IntVar(&(cf.BBsimSadisPort), "bbsim_sadis_port", defaultBBsimSadisPort, "The port on which BBSim exposes the Sadis server")
57
58 flag.Parse()
59
60 if *logFormat != log.CONSOLE && *logFormat != log.JSON {
61 panic(fmt.Sprintf("log_format is invalid, allowed values are: %s, %s", log.JSON, log.CONSOLE))
62 }
63
64 cf.LogFormat = *logFormat
65}