Use tablewriter for output formatting

This commit is contained in:
2021-03-10 20:57:05 -06:00
parent 2d2efd4431
commit 1a7b665376
11 changed files with 221 additions and 96 deletions

View File

@ -19,6 +19,8 @@ func NewCmdPoweron() Command {
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
fs.String("format", defaultOutputFormat, "Set the output format")
return fs
}(),
Use: "[--selector <selector>] [--duration <sec>]",
@ -30,12 +32,24 @@ func PoweronCmd(args CmdArgs) (int, error) {
c := args.Client
duration := args.Flags.Float64("duration")
selector := args.Flags.String("selector")
format := args.Flags.String("format")
state := lifx.State{Power: "on", Duration: duration}
if format == "" && args.Config.OutputFormat != "" {
format = args.Config.OutputFormat
}
r, err := c.SetState(selector, state)
if err != nil {
return ExitFailure, err
}
PrintResults(r.Results)
switch format {
case "table":
PrintResultsTable(r.Results)
default:
PrintResults(r.Results)
}
return ExitSuccess, nil
}