-
-
Save nasa9084/2be5e22485ff2ad91fdb3e5a0f2a01b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"errors" | |
"flag" | |
"fmt" | |
"log" | |
"github.com/nasa9084/go-switchbot" | |
) | |
var ( | |
openToken = flag.String("t", "", "") | |
) | |
func main() { | |
flag.Parse() | |
if err := execute(); err != nil { | |
log.Fatal(err) | |
} | |
} | |
func execute() error { | |
if *openToken == "" { | |
return errors.New("-t option is required") | |
} | |
c := switchbot.New(*openToken) | |
devices, _, err := c.Device().List(context.Background()) | |
if err != nil { | |
return fmt.Errorf("gettng device list") | |
} | |
for _, device := range devices { | |
fmt.Printf("%s %s\n", device.Name, device.ID) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment