Make everything build strings instead of printing

This commit is contained in:
2021-04-23 22:56:58 +00:00
parent 8c9af693e7
commit dd1ea7c276
12 changed files with 121 additions and 65 deletions

View File

@ -4,6 +4,7 @@ import (
"errors"
"flag"
"fmt"
"strings"
"git.kill0.net/chill9/lifx-go"
)
@ -23,10 +24,11 @@ func NewCmdValidate() Command {
}
func ValidateCmd(ctx Context) (int, error) {
var b strings.Builder
c := ctx.Client
if len(ctx.Args) != 1 {
printCmdHelp(ctx.Name)
fmt.Print(printCmdHelp(ctx.Name))
return ExitFailure, nil
}
@ -38,11 +40,12 @@ func ValidateCmd(ctx Context) (int, error) {
}
if validColor, ok := i.(*lifx.HSBKColor); ok {
fmt.Print(validColor)
fmt.Fprintln(&b, validColor)
} else {
return ExitFailure, errors.New("go type %T but wanted *HSBKColor")
}
fmt.Println()
fmt.Print(b.String())
return ExitSuccess, nil
}