23 lines
572 B
Go
23 lines
572 B
Go
package cli
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
|
|
"gitea.maximumdirect.net/eric/distributor/internal/app"
|
|
)
|
|
|
|
func addFormatFlag(flags *flag.FlagSet) *string {
|
|
return flags.String("format", string(app.OutputFormatText), "output format: text or json")
|
|
}
|
|
|
|
func parseOutputFormat(stderr io.Writer, command, raw string) (app.OutputFormat, bool) {
|
|
format := app.OutputFormat(raw)
|
|
if err := app.ValidateOutputFormat(format); err != nil {
|
|
fmt.Fprintf(stderr, "%s: %s --format: %s\n", app.Name, command, err)
|
|
return "", false
|
|
}
|
|
return app.NormalizeOutputFormat(format), true
|
|
}
|