Compare commits
No commits in common. "4ea3545ea7a50d3ad90f0bd403c9c0efbe160b30" and "7c7b06e89333b0dc76cf79a001f06970d95afe5f" have entirely different histories.
4ea3545ea7
...
7c7b06e893
@ -19,7 +19,6 @@ type Flags struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Command struct {
|
type Command struct {
|
||||||
Name string
|
|
||||||
Func func(CmdArgs) int
|
Func func(CmdArgs) int
|
||||||
Flags *flag.FlagSet
|
Flags *flag.FlagSet
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func LsCmd(args CmdArgs) int {
|
|||||||
selector := args.Flags.String("selector")
|
selector := args.Flags.String("selector")
|
||||||
lights, err := c.ListLights(selector)
|
lights, err := c.ListLights(selector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("fatal: %s\n", err)
|
fmt.Println(err)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
PrintLights(lights)
|
PrintLights(lights)
|
||||||
|
@ -47,7 +47,7 @@ func main() {
|
|||||||
|
|
||||||
cmd, ok := lumecmd.GetCommand(command)
|
cmd, ok := lumecmd.GetCommand(command)
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Printf("lume: '%s' is not lume command. See 'lume' --help.'\n", command)
|
fmt.Println("ERROR")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fs := cmd.Flags
|
fs := cmd.Flags
|
||||||
|
@ -1,86 +0,0 @@
|
|||||||
package lumecmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.kill0.net/chill9/go-lifx"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
var cmdName string = "set-state"
|
|
||||||
|
|
||||||
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
|
|
||||||
|
|
||||||
selector := fs.String("selector", "all", "Set the selector")
|
|
||||||
fs.StringVar(selector, "s", "all", "Set the selector")
|
|
||||||
|
|
||||||
power := fs.String("power", "", "power state")
|
|
||||||
fs.StringVar(power, "p", "", "power state")
|
|
||||||
|
|
||||||
color := fs.String("color", "", "color state")
|
|
||||||
fs.StringVar(color, "c", "", "color state")
|
|
||||||
|
|
||||||
brightness := fs.String("brightness", "", "brightness state")
|
|
||||||
fs.StringVar(brightness, "b", "", "brightness state")
|
|
||||||
|
|
||||||
duration := fs.Float64("duration", 1.0, "duration state")
|
|
||||||
fs.Float64Var(duration, "d", 1.0, "duration state")
|
|
||||||
|
|
||||||
infrared := fs.String("infrared", "", "infrared state")
|
|
||||||
fs.StringVar(infrared, "i", "", "infrared state")
|
|
||||||
|
|
||||||
fast := fs.Bool("fast", false, "fast state")
|
|
||||||
fs.BoolVar(fast, "f", false, "fast state")
|
|
||||||
|
|
||||||
RegisterCommand(cmdName, Command{
|
|
||||||
Func: SetStateCmd,
|
|
||||||
Flags: fs,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetStateCmd(args CmdArgs) int {
|
|
||||||
c := args.Client
|
|
||||||
state := lifx.State{}
|
|
||||||
selector := args.Flags.String("selector")
|
|
||||||
|
|
||||||
power := args.Flags.String("power")
|
|
||||||
if power != "" {
|
|
||||||
state.Power = power
|
|
||||||
}
|
|
||||||
|
|
||||||
color := args.Flags.String("color")
|
|
||||||
if color != "" {
|
|
||||||
state.Color = lifx.NamedColor(color)
|
|
||||||
}
|
|
||||||
|
|
||||||
brightnessFlag := args.Flags.String("brightness")
|
|
||||||
if brightnessFlag != "" {
|
|
||||||
brightness := args.Flags.Float64("brightness")
|
|
||||||
state.Brightness = brightness
|
|
||||||
}
|
|
||||||
|
|
||||||
duration := args.Flags.Float64("duration")
|
|
||||||
state.Duration = duration
|
|
||||||
|
|
||||||
infraredFlag := args.Flags.String("infrared")
|
|
||||||
if infraredFlag != "" {
|
|
||||||
infrared := args.Flags.Float64("infrared")
|
|
||||||
state.Infrared = infrared
|
|
||||||
}
|
|
||||||
|
|
||||||
fast := args.Flags.Bool("fast")
|
|
||||||
state.Fast = fast
|
|
||||||
|
|
||||||
r, err := c.SetState(selector, state)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("fatal: %s\n", err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if !fast {
|
|
||||||
PrintResults(r.Results)
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
@ -24,7 +24,7 @@ func ToggleCmd(args CmdArgs) int {
|
|||||||
selector := args.Flags.String("selector")
|
selector := args.Flags.String("selector")
|
||||||
r, err := c.Toggle(selector, duration)
|
r, err := c.Toggle(selector, duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("fatal: %s\n", err)
|
fmt.Println(err)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
PrintResults(r.Results)
|
PrintResults(r.Results)
|
||||||
|
@ -3,7 +3,7 @@ package lifx
|
|||||||
import (
|
import (
|
||||||
//"crypto/tls"
|
//"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -97,7 +97,7 @@ func NewApiError(resp *http.Response) error {
|
|||||||
if err = json.NewDecoder(resp.Body).Decode(&s); err != nil {
|
if err = json.NewDecoder(resp.Body).Decode(&s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return errors.New(s.Error)
|
return fmt.Errorf("fatal: %s", s.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsApiError(resp *http.Response) bool {
|
func IsApiError(resp *http.Response) bool {
|
||||||
@ -120,10 +120,6 @@ func (c *Client) SetState(selector string, state State) (*Response, error) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if IsApiError(resp) {
|
|
||||||
return nil, NewApiError(resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
if state.Fast && resp.StatusCode == http.StatusAccepted {
|
if state.Fast && resp.StatusCode == http.StatusAccepted {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user