go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/experiments/huectl/pkg/command/set_light_on.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  	"github.com/urfave/cli/v2"
    12  )
    13  
    14  // SetLightOn returns a command.
    15  func SetLightOn() *cli.Command {
    16  	return &cli.Command{
    17  		Name:  "set-light-on",
    18  		Usage: "Set a given light on.",
    19  		Flags: append(
    20  			DefaultFlags,
    21  			LightFlags...,
    22  		),
    23  		Action: func(c *cli.Context) error {
    24  			light, _, err := lightHelper(c)
    25  			if err != nil {
    26  				return err
    27  			}
    28  			if err = light.On(c.Context); err != nil {
    29  				return err
    30  			}
    31  			printf(c, "light %q turned on\n", light.Name)
    32  			return nil
    33  		},
    34  	}
    35  }