Compare commits
	
		
			2 Commits
		
	
	
		
			01086e3c22
			...
			c9e4d9af80
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c9e4d9af80 | |||
| dd0bf763a3 | 
| @@ -81,12 +81,11 @@ func (f Flags) Bool(name string) bool { | ||||
| 	return val | ||||
| } | ||||
|  | ||||
| func RegisterCommand(name string, cmd Command) error { | ||||
| 	if _, ok := commandRegistry[name]; ok { | ||||
| func RegisterCommand(cmd Command) error { | ||||
| 	if _, ok := commandRegistry[cmd.Name]; ok { | ||||
| 		return fmt.Errorf("%s command is already registered") | ||||
| 	} | ||||
| 	cmd.Name = name | ||||
| 	commandRegistry[name] = cmd | ||||
| 	commandRegistry[cmd.Name] = cmd | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										15
									
								
								cmd/help.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								cmd/help.go
									
									
									
									
									
								
							| @@ -1,10 +1,25 @@ | ||||
| package lumecmd | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"sort" | ||||
| ) | ||||
|  | ||||
| func NewCmdHelp() Command { | ||||
| 	return Command{ | ||||
| 		Name: "help", | ||||
| 		Func: HelpCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("help", flag.ExitOnError) | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "<command>", | ||||
| 		Short: "Show help for a command", | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func HelpCmd(args CmdArgs) (int, error) { | ||||
| 	argv := args.Flags.Args() | ||||
|  | ||||
|   | ||||
							
								
								
									
										19
									
								
								cmd/ls.go
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								cmd/ls.go
									
									
									
									
									
								
							| @@ -1,5 +1,24 @@ | ||||
| package lumecmd | ||||
|  | ||||
| import "flag" | ||||
|  | ||||
| func NewCmdLs() Command { | ||||
| 	return Command{ | ||||
| 		Name: "ls", | ||||
| 		Func: LsCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("ls", flag.ExitOnError) | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector=<selector>]", | ||||
| 		Short: "List the lights", | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func LsCmd(args CmdArgs) (int, error) { | ||||
| 	c := args.Client | ||||
| 	selector := args.Flags.String("selector") | ||||
|   | ||||
							
								
								
									
										195
									
								
								cmd/main.go
									
									
									
									
									
								
							
							
						
						
									
										195
									
								
								cmd/main.go
									
									
									
									
									
								
							| @@ -17,192 +17,15 @@ var userAgent string | ||||
| func init() { | ||||
| 	userAgent = initUserAgent() | ||||
|  | ||||
| 	RegisterCommand("help", Command{ | ||||
| 		Func: HelpCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("help", flag.ExitOnError) | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "<command>", | ||||
| 		Short: "Show help for a command", | ||||
| 	}) | ||||
| 	RegisterCommand("ls", Command{ | ||||
| 		Func: LsCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("ls", flag.ExitOnError) | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector=<selector>]", | ||||
| 		Short: "List the lights", | ||||
| 	}) | ||||
| 	RegisterCommand("poweroff", Command{ | ||||
| 		Func: PoweroffCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("poweroff", flag.ExitOnError) | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "Set the duration") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "Set the duration") | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--duration <sec>]", | ||||
| 		Short: "Power on", | ||||
| 	}) | ||||
| 	RegisterCommand("poweron", Command{ | ||||
| 		Func: PoweronCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("poweron", flag.ExitOnError) | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "Set the duration") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "Set the duration") | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--duration <sec>]", | ||||
| 		Short: "Power on", | ||||
| 	}) | ||||
| 	RegisterCommand("set-color", Command{ | ||||
| 		Func: SetColorCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("set-color", flag.ExitOnError) | ||||
|  | ||||
| 			selector := fs.String("selector", "all", "the selector") | ||||
| 			fs.StringVar(selector, "s", "all", "the selector") | ||||
|  | ||||
| 			power := fs.String("power", defaultPower, "power state") | ||||
| 			fs.StringVar(power, "p", defaultPower, "power state") | ||||
|  | ||||
| 			hue := fs.String("hue", defaultHue, "hue level") | ||||
| 			fs.StringVar(hue, "H", defaultHue, "hue level") | ||||
|  | ||||
| 			saturation := fs.String("saturation", defaultSaturation, "saturation level") | ||||
| 			fs.StringVar(saturation, "S", defaultSaturation, "saturation level") | ||||
|  | ||||
| 			rgb := fs.String("rgb", defaultRGB, "RGB value") | ||||
| 			fs.StringVar(rgb, "r", defaultRGB, "RGB value") | ||||
|  | ||||
| 			name := fs.String("name", defaultName, "named color") | ||||
| 			fs.StringVar(name, "n", defaultName, "named color") | ||||
|  | ||||
| 			brightness := fs.String("brightness", defaultBrightness, "brightness state") | ||||
| 			fs.StringVar(brightness, "b", defaultBrightness, "brightness state") | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "duration state") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "duration state") | ||||
|  | ||||
| 			fast := fs.Bool("fast", defaultFast, "fast state") | ||||
| 			fs.BoolVar(fast, "f", defaultFast, "fast state") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--power (on|off)] [--hue <hue>] [--saturation <saturation>] [--rgb <rbg>] [--name <color>] [--brightness <brightness>] [--duration <sec>] [--fast]", | ||||
| 		Short: "Set the color", | ||||
| 	}) | ||||
| 	RegisterCommand("set-state", Command{ | ||||
| 		Func: SetStateCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("set-state", flag.ExitOnError) | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			power := fs.String("power", defaultPower, "power state") | ||||
| 			fs.StringVar(power, "p", defaultPower, "power state") | ||||
|  | ||||
| 			color := fs.String("color", defaultColor, "color state") | ||||
| 			fs.StringVar(color, "c", defaultColor, "color state") | ||||
|  | ||||
| 			brightness := fs.String("brightness", defaultBrightness, "brightness state") | ||||
| 			fs.StringVar(brightness, "b", defaultBrightness, "brightness state") | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "duration state") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "duration state") | ||||
|  | ||||
| 			infrared := fs.String("infrared", defaultInfrared, "infrared state") | ||||
| 			fs.StringVar(infrared, "i", defaultInfrared, "infrared state") | ||||
|  | ||||
| 			fast := fs.Bool("fast", defaultFast, "fast state") | ||||
| 			fs.BoolVar(fast, "f", defaultFast, "fast state") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--power (on|off)] [--color <color>] [--brightness <brightness>] [--duration <sec>] [--infrared <infrared>] [--fast]", | ||||
| 		Short: "Set various state attributes", | ||||
| 	}) | ||||
| 	RegisterCommand("set-white", Command{ | ||||
| 		Func: SetWhiteCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("set-white", flag.ExitOnError) | ||||
|  | ||||
| 			selector := fs.String("selector", "all", "the selector") | ||||
| 			fs.StringVar(selector, "s", "all", "the selector") | ||||
|  | ||||
| 			power := fs.String("power", defaultPower, "power state") | ||||
| 			fs.StringVar(power, "p", defaultPower, "power state") | ||||
|  | ||||
| 			kelvin := fs.String("kelvin", defaultWhiteKelvin, "kelvin level") | ||||
| 			fs.StringVar(kelvin, "k", defaultWhiteKelvin, "kelvin level") | ||||
|  | ||||
| 			name := fs.String("name", defaultWhiteName, "named white level") | ||||
| 			fs.StringVar(name, "n", defaultWhiteName, "named white level") | ||||
|  | ||||
| 			brightness := fs.String("brightness", defaultBrightness, "brightness state") | ||||
| 			fs.StringVar(brightness, "b", defaultBrightness, "brightness state") | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "duration state") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "duration state") | ||||
|  | ||||
| 			infrared := fs.String("infrared", defaultInfrared, "infrared state") | ||||
| 			fs.StringVar(infrared, "i", defaultInfrared, "infrared state") | ||||
|  | ||||
| 			fast := fs.Bool("fast", defaultFast, "fast state") | ||||
| 			fs.BoolVar(fast, "f", defaultFast, "fast state") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--power (on|off)] [--kelvin <kelvin>] [--name <color>] [--brightness <brightness>] [--duration <sec>] [--infrared] [--fast]", | ||||
| 		Short: "Set the white level", | ||||
| 	}) | ||||
| 	RegisterCommand("show", Command{ | ||||
| 		Func: ShowCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("show", flag.ExitOnError) | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector=<selector>]", | ||||
| 		Short: "Show details about the lights", | ||||
| 	}) | ||||
| 	RegisterCommand("toggle", Command{ | ||||
| 		Func: ToggleCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("toggle", flag.ExitOnError) | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "Set the duration") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "Set the duration") | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--duration <sec>]", | ||||
| 		Short: "Toggle the power on/off", | ||||
| 	}) | ||||
| 	RegisterCommand(NewCmdHelp()) | ||||
| 	RegisterCommand(NewCmdLs()) | ||||
| 	RegisterCommand(NewCmdPoweroff()) | ||||
| 	RegisterCommand(NewCmdPoweron()) | ||||
| 	RegisterCommand(NewCmdSetColor()) | ||||
| 	RegisterCommand(NewCmdSetState()) | ||||
| 	RegisterCommand(NewCmdSetWhite()) | ||||
| 	RegisterCommand(NewCmdShow()) | ||||
| 	RegisterCommand(NewCmdToggle()) | ||||
| } | ||||
|  | ||||
| const lumercFile string = ".lumerc" | ||||
|   | ||||
| @@ -1,9 +1,31 @@ | ||||
| package lumecmd | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
|  | ||||
| 	"git.kill0.net/chill9/lifx-go" | ||||
| ) | ||||
|  | ||||
| func NewCmdPoweroff() Command { | ||||
| 	return Command{ | ||||
| 		Name: "poweroff", | ||||
| 		Func: PoweroffCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("poweroff", flag.ExitOnError) | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "Set the duration") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "Set the duration") | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--duration <sec>]", | ||||
| 		Short: "Power on", | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func PoweroffCmd(args CmdArgs) (int, error) { | ||||
| 	c := args.Client | ||||
| 	duration := args.Flags.Float64("duration") | ||||
|   | ||||
| @@ -1,9 +1,31 @@ | ||||
| package lumecmd | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
|  | ||||
| 	"git.kill0.net/chill9/lifx-go" | ||||
| ) | ||||
|  | ||||
| func NewCmdPoweron() Command { | ||||
| 	return Command{ | ||||
| 		Name: "poweron", | ||||
| 		Func: PoweronCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("poweron", flag.ExitOnError) | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "Set the duration") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "Set the duration") | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--duration <sec>]", | ||||
| 		Short: "Power on", | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func PoweronCmd(args CmdArgs) (int, error) { | ||||
| 	c := args.Client | ||||
| 	duration := args.Flags.Float64("duration") | ||||
|   | ||||
| @@ -1,11 +1,53 @@ | ||||
| package lumecmd | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
|  | ||||
| 	"git.kill0.net/chill9/lifx-go" | ||||
| ) | ||||
|  | ||||
| func NewCmdSetColor() Command { | ||||
| 	return Command{ | ||||
| 		Name: "set-color", | ||||
| 		Func: SetColorCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("set-color", flag.ExitOnError) | ||||
|  | ||||
| 			selector := fs.String("selector", "all", "the selector") | ||||
| 			fs.StringVar(selector, "s", "all", "the selector") | ||||
|  | ||||
| 			power := fs.String("power", defaultPower, "power state") | ||||
| 			fs.StringVar(power, "p", defaultPower, "power state") | ||||
|  | ||||
| 			hue := fs.String("hue", defaultHue, "hue level") | ||||
| 			fs.StringVar(hue, "H", defaultHue, "hue level") | ||||
|  | ||||
| 			saturation := fs.String("saturation", defaultSaturation, "saturation level") | ||||
| 			fs.StringVar(saturation, "S", defaultSaturation, "saturation level") | ||||
|  | ||||
| 			rgb := fs.String("rgb", defaultRGB, "RGB value") | ||||
| 			fs.StringVar(rgb, "r", defaultRGB, "RGB value") | ||||
|  | ||||
| 			name := fs.String("name", defaultName, "named color") | ||||
| 			fs.StringVar(name, "n", defaultName, "named color") | ||||
|  | ||||
| 			brightness := fs.String("brightness", defaultBrightness, "brightness state") | ||||
| 			fs.StringVar(brightness, "b", defaultBrightness, "brightness state") | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "duration state") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "duration state") | ||||
|  | ||||
| 			fast := fs.Bool("fast", defaultFast, "fast state") | ||||
| 			fs.BoolVar(fast, "f", defaultFast, "fast state") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--power (on|off)] [--hue <hue>] [--saturation <saturation>] [--rgb <rbg>] [--name <color>] [--brightness <brightness>] [--duration <sec>] [--fast]", | ||||
| 		Short: "Set the color", | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func SetColorCmd(args CmdArgs) (int, error) { | ||||
| 	c := args.Client | ||||
| 	state := lifx.State{} | ||||
|   | ||||
| @@ -1,9 +1,46 @@ | ||||
| package lumecmd | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
|  | ||||
| 	"git.kill0.net/chill9/lifx-go" | ||||
| ) | ||||
|  | ||||
| func NewCmdSetState() Command { | ||||
| 	return Command{ | ||||
| 		Name: "set-state", | ||||
| 		Func: SetStateCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("set-state", flag.ExitOnError) | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			power := fs.String("power", defaultPower, "power state") | ||||
| 			fs.StringVar(power, "p", defaultPower, "power state") | ||||
|  | ||||
| 			color := fs.String("color", defaultColor, "color state") | ||||
| 			fs.StringVar(color, "c", defaultColor, "color state") | ||||
|  | ||||
| 			brightness := fs.String("brightness", defaultBrightness, "brightness state") | ||||
| 			fs.StringVar(brightness, "b", defaultBrightness, "brightness state") | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "duration state") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "duration state") | ||||
|  | ||||
| 			infrared := fs.String("infrared", defaultInfrared, "infrared state") | ||||
| 			fs.StringVar(infrared, "i", defaultInfrared, "infrared state") | ||||
|  | ||||
| 			fast := fs.Bool("fast", defaultFast, "fast state") | ||||
| 			fs.BoolVar(fast, "f", defaultFast, "fast state") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--power (on|off)] [--color <color>] [--brightness <brightness>] [--duration <sec>] [--infrared <infrared>] [--fast]", | ||||
| 		Short: "Set various state attributes", | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func SetStateCmd(args CmdArgs) (int, error) { | ||||
| 	c := args.Client | ||||
| 	state := lifx.State{} | ||||
|   | ||||
| @@ -1,9 +1,49 @@ | ||||
| package lumecmd | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
|  | ||||
| 	"git.kill0.net/chill9/lifx-go" | ||||
| ) | ||||
|  | ||||
| func NewCmdSetWhite() Command { | ||||
| 	return Command{ | ||||
| 		Name: "set-white", | ||||
| 		Func: SetWhiteCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("set-white", flag.ExitOnError) | ||||
|  | ||||
| 			selector := fs.String("selector", "all", "the selector") | ||||
| 			fs.StringVar(selector, "s", "all", "the selector") | ||||
|  | ||||
| 			power := fs.String("power", defaultPower, "power state") | ||||
| 			fs.StringVar(power, "p", defaultPower, "power state") | ||||
|  | ||||
| 			kelvin := fs.String("kelvin", defaultWhiteKelvin, "kelvin level") | ||||
| 			fs.StringVar(kelvin, "k", defaultWhiteKelvin, "kelvin level") | ||||
|  | ||||
| 			name := fs.String("name", defaultWhiteName, "named white level") | ||||
| 			fs.StringVar(name, "n", defaultWhiteName, "named white level") | ||||
|  | ||||
| 			brightness := fs.String("brightness", defaultBrightness, "brightness state") | ||||
| 			fs.StringVar(brightness, "b", defaultBrightness, "brightness state") | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "duration state") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "duration state") | ||||
|  | ||||
| 			infrared := fs.String("infrared", defaultInfrared, "infrared state") | ||||
| 			fs.StringVar(infrared, "i", defaultInfrared, "infrared state") | ||||
|  | ||||
| 			fast := fs.Bool("fast", defaultFast, "fast state") | ||||
| 			fs.BoolVar(fast, "f", defaultFast, "fast state") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--power (on|off)] [--kelvin <kelvin>] [--name <color>] [--brightness <brightness>] [--duration <sec>] [--infrared] [--fast]", | ||||
| 		Short: "Set the white level", | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func SetWhiteCmd(args CmdArgs) (int, error) { | ||||
| 	c := args.Client | ||||
| 	state := lifx.State{} | ||||
|   | ||||
							
								
								
									
										63
									
								
								cmd/show.go
									
									
									
									
									
								
							
							
						
						
									
										63
									
								
								cmd/show.go
									
									
									
									
									
								
							| @@ -1,8 +1,31 @@ | ||||
| package lumecmd | ||||
|  | ||||
| import "fmt" | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| ) | ||||
|  | ||||
| const Tabstop int = 2 | ||||
|  | ||||
| func NewCmdShow() Command { | ||||
| 	return Command{ | ||||
| 		Name: "show", | ||||
| 		Func: ShowCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("show", flag.ExitOnError) | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector=<selector>]", | ||||
| 		Short: "Show details about the lights", | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func ShowCmd(args CmdArgs) (int, error) { | ||||
| 	var indent int | ||||
| 	c := args.Client | ||||
| 	selector := args.Flags.String("selector") | ||||
| 	lights, err := c.ListLights(selector) | ||||
| @@ -14,24 +37,26 @@ func ShowCmd(args CmdArgs) (int, error) { | ||||
| 	sortLights(lights) | ||||
|  | ||||
| 	for i, l := range lights { | ||||
| 		indent = 0 | ||||
| 		fmt.Printf( | ||||
| 			"Light ID: %s, %s, Power: %s\n", | ||||
| 			l.Id, | ||||
| 			connected(l.Connected), | ||||
| 			powerColor(l.Power), | ||||
| 		) | ||||
| 		fmt.Printf("  Label: %s, ID: %s\n", l.Label, l.Id) | ||||
| 		fmt.Printf("  UUID: %s\n", l.UUID) | ||||
| 		fmt.Printf("  Location: %s, ID: %s\n", l.Location.Name, l.Location.Id) | ||||
| 		fmt.Printf("  Group: %s, ID: %s\n", l.Group.Name, l.Group.Id) | ||||
| 		fmt.Printf("  Color: Hue: %.1f, Saturation: %.1f%%, Kelvin: %d\n", | ||||
| 		indent += Tabstop | ||||
| 		PrintfWithIndent(indent, "Label: %s, ID: %s\n", l.Label, l.Id) | ||||
| 		PrintfWithIndent(indent, "UUID: %s\n", l.UUID) | ||||
| 		PrintfWithIndent(indent, "Location: %s, ID: %s\n", l.Location.Name, l.Location.Id) | ||||
| 		PrintfWithIndent(indent, "Group: %s, ID: %s\n", l.Group.Name, l.Group.Id) | ||||
| 		PrintfWithIndent(indent, "Color: Hue: %.1f, Saturation: %.1f%%, Kelvin: %d\n", | ||||
| 			*l.Color.H, *l.Color.S, *l.Color.K) | ||||
| 		fmt.Printf("  Brightness: %.1f%%\n", l.Brightness*100) | ||||
| 		PrintfWithIndent(indent, "Brightness: %.1f%%\n", l.Brightness*100) | ||||
| 		if l.Effect != "" { | ||||
| 			fmt.Printf("  Effect: %s\n", l.Effect) | ||||
| 			PrintfWithIndent(indent, "Effect: %s\n", l.Effect) | ||||
| 		} | ||||
| 		fmt.Printf("  Product: %s\n", l.Product.Name) | ||||
| 		fmt.Printf("  Capabilities: ") | ||||
| 		PrintfWithIndent(indent, "Product: %s\n", l.Product.Name) | ||||
| 		PrintfWithIndent(indent, "Capabilities: ") | ||||
| 		fmt.Printf("Color: %s, ", YesNo(l.Product.Capabilities.HasColor)) | ||||
| 		fmt.Printf("Variable Color Temp: %s, ", YesNo(l.Product.Capabilities.HasVariableColorTemp)) | ||||
| 		fmt.Printf("IR: %s, ", YesNo(l.Product.Capabilities.HasIR)) | ||||
| @@ -41,14 +66,16 @@ func ShowCmd(args CmdArgs) (int, error) { | ||||
| 		fmt.Printf("Max Kelvin: %.1f ", l.Product.Capabilities.MaxKelvin) | ||||
| 		fmt.Println() | ||||
| 		// List applicable selectors (most to least specific) | ||||
| 		fmt.Printf("  Selectors:\n") | ||||
| 		fmt.Printf("    id:%s\n", l.Id) | ||||
| 		fmt.Printf("    label:%s\n", l.Label) | ||||
| 		fmt.Printf("    group_id:%s\n", l.Group.Id) | ||||
| 		fmt.Printf("    group:%s\n", l.Group.Name) | ||||
| 		fmt.Printf("    location_id:%s\n", l.Location.Id) | ||||
| 		fmt.Printf("    location:%s\n", l.Location.Name) | ||||
| 		fmt.Printf("  Last Seen: %s (%.1fs ago)\n", l.LastSeen, l.SecondsLastSeen) | ||||
| 		PrintfWithIndent(indent, "Selectors:\n") | ||||
| 		indent += Tabstop | ||||
| 		PrintfWithIndent(indent, "id:%s\n", l.Id) | ||||
| 		PrintfWithIndent(indent, "label:%s\n", l.Label) | ||||
| 		PrintfWithIndent(indent, "group_id:%s\n", l.Group.Id) | ||||
| 		PrintfWithIndent(indent, "group:%s\n", l.Group.Name) | ||||
| 		PrintfWithIndent(indent, "location_id:%s\n", l.Location.Id) | ||||
| 		PrintfWithIndent(indent, "location:%s\n", l.Location.Name) | ||||
| 		indent -= Tabstop | ||||
| 		PrintfWithIndent(indent, "Last Seen: %s (%.1fs ago)\n", l.LastSeen, l.SecondsLastSeen) | ||||
|  | ||||
| 		if i < len(lights)-1 { | ||||
| 			fmt.Println() | ||||
|   | ||||
| @@ -1,5 +1,29 @@ | ||||
| package lumecmd | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| ) | ||||
|  | ||||
| func NewCmdToggle() Command { | ||||
| 	return Command{ | ||||
| 		Name: "toggle", | ||||
| 		Func: ToggleCmd, | ||||
| 		Flags: func() *flag.FlagSet { | ||||
| 			fs := flag.NewFlagSet("toggle", flag.ExitOnError) | ||||
|  | ||||
| 			duration := fs.Float64("duration", defaultDuration, "Set the duration") | ||||
| 			fs.Float64Var(duration, "d", defaultDuration, "Set the duration") | ||||
|  | ||||
| 			selector := fs.String("selector", defaultSelector, "Set the selector") | ||||
| 			fs.StringVar(selector, "s", defaultSelector, "Set the selector") | ||||
|  | ||||
| 			return fs | ||||
| 		}(), | ||||
| 		Use:   "[--selector <selector>] [--duration <sec>]", | ||||
| 		Short: "Toggle the power on/off", | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func ToggleCmd(args CmdArgs) (int, error) { | ||||
| 	c := args.Client | ||||
| 	duration := args.Flags.Float64("duration") | ||||
|   | ||||
| @@ -169,4 +169,9 @@ func YesNo(v bool) string { | ||||
|  | ||||
| func PrintWithIndent(indent int, s string) { | ||||
| 	fmt.Printf("%*s%s", indent, "", s) | ||||
| } | ||||
| } | ||||
|  | ||||
| func PrintfWithIndent(indent int, format string, a ...interface{}) (n int, err error) { | ||||
| 	format = fmt.Sprintf("%*s%s", indent, "", format) | ||||
| 	return fmt.Printf(format, a...) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user