go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/experiments/huectl/pkg/command/set_group_scene.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package command 9 10 import ( 11 "fmt" 12 13 "github.com/urfave/cli/v2" 14 ) 15 16 // SetGroupScene returns a command. 17 func SetGroupScene() *cli.Command { 18 const ( 19 flagSceneID = "scene-id" 20 flagSceneName = "scene-name" 21 ) 22 23 return &cli.Command{ 24 Name: "set-group-scene", 25 Usage: "Set given group's scene.", 26 Flags: append(DefaultFlags, append( 27 GroupFlags, 28 &cli.StringFlag{ 29 Name: flagSceneID, 30 Usage: "The `ID` field of the scene to set the group to", 31 }, 32 &cli.StringFlag{ 33 Name: flagSceneName, 34 Usage: "The `Name` field of the scene to set the group to", 35 }, 36 )...), 37 Action: func(c *cli.Context) error { 38 group, b, err := groupHelper(c) 39 if err != nil { 40 return err 41 } 42 43 if c.Int(flagSceneID) > 0 && c.String(flagSceneName) != "" { 44 return fmt.Errorf("please specify one of --scene-id or --scene-name") 45 } 46 47 scene, err := getScene(c, b, getSceneArgs{ 48 ID: c.String(flagSceneID), 49 Name: c.String(flagSceneName), 50 }) 51 if err != nil { 52 return err 53 } 54 55 if err = group.Scene(c.Context, scene.ID); err != nil { 56 return err 57 } 58 printf(c, "group %q set to scene %s\n", group.Name, scene.ID) 59 return nil 60 }, 61 } 62 }