github.com/verrazzano/verrazzano@v1.7.0/tools/vz/cmd/helpers/log_format.go (about) 1 // Copyright (c) 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package helpers 5 6 import "fmt" 7 8 type LogFormat string 9 10 const ( 11 LogFormatSimple LogFormat = "simple" 12 LogFormatJSON LogFormat = "json" 13 ) 14 15 // Implement the pflag.Value interface to support validating the logs format options 16 17 func (lf *LogFormat) String() string { 18 return string(*lf) 19 } 20 21 // Type is only used in help text 22 func (lf *LogFormat) Type() string { 23 return "format" 24 } 25 26 // Set must have pointer receiver so it doesn't change the value of a copy 27 func (lf *LogFormat) Set(value string) error { 28 switch value { 29 case string(LogFormatJSON), string(LogFormatSimple): 30 *lf = LogFormat(value) 31 return nil 32 default: 33 return fmt.Errorf("allowed values are %q and %q", string(LogFormatSimple), string(LogFormatJSON)) 34 } 35 }