garm/cmd/garm-cli/common/cobra.go
Gabriel Adrian Samfira 63000113ee Add --format command line option
This change adds a --format command line option to the GARM cli. This
option accepts either json or table as a value.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2024-09-28 19:09:45 +00:00

28 lines
467 B
Go

package common
import "fmt"
type OutputFormat string
const (
OutputFormatTable OutputFormat = "table"
OutputFormatJSON OutputFormat = "json"
)
func (o OutputFormat) String() string {
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"
}