blob: 19a91a93027dc2142a13d4d1bb5ece83cce0a200 [file] [log] [blame]
Matteo Scandoloa4285862020-12-01 18:10:10 -08001/*
2 * Copyright 2020-present Open Networking Foundation
3
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"
22 "github.com/opencord/voltha-lib-go/v4/pkg/log"
23)
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{
40 LogLevel: defaultLogLevel,
41 LogFormat: defaultLogFormat,
42 Kubeconfig: "",
43 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}