garm/cmd/garm-cli/common/cobra.go
Gabriel Adrian Samfira f9abb30128 Add a default value to the new --format option
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2024-09-28 19:21:20 +00:00

31 lines
500 B
Go

package common
import "fmt"
type OutputFormat string
const (
OutputFormatTable OutputFormat = "table"
OutputFormatJSON OutputFormat = "json"
)
func (o *OutputFormat) String() string {
if o == nil {
return ""
}
return string(*o)
}
func (o *OutputFormat) Set(value string) error {
switch value {
case "table", "json":
*o = OutputFormat(value)
default:
return fmt.Errorf("allowed formats are: json, table")
}
return nil
}
func (o *OutputFormat) Type() string {
return "string"
}