Compare commits
	
		
			65 Commits
		
	
	
		
			518e304948
			...
			develop
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						dd1ea7c276
	
				 | 
					
					
						|||
| 
						
						
							
						
						8c9af693e7
	
				 | 
					
					
						|||
| 
						
						
							
						
						23210af0c3
	
				 | 
					
					
						|||
| 
						
						
							
						
						8133953bb1
	
				 | 
					
					
						|||
| 
						
						
							
						
						8cc556024f
	
				 | 
					
					
						|||
| 
						
						
							
						
						c01c342945
	
				 | 
					
					
						|||
| 
						
						
							
						
						8b232c5ef5
	
				 | 
					
					
						|||
| 
						
						
							
						
						d6ca2d7921
	
				 | 
					
					
						|||
| 
						
						
							
						
						f79de85d43
	
				 | 
					
					
						|||
| 
						
						
							
						
						05f445ddf2
	
				 | 
					
					
						|||
| 
						
						
							
						
						baf7daa1bb
	
				 | 
					
					
						|||
| 
						
						
							
						
						43b0c0a399
	
				 | 
					
					
						|||
| 
						
						
							
						
						7ac2cab082
	
				 | 
					
					
						|||
| 
						
						
							
						
						cee0af195e
	
				 | 
					
					
						|||
| 
						
						
							
						
						01a0601652
	
				 | 
					
					
						|||
| 
						
						
							
						
						ffe2c08a35
	
				 | 
					
					
						|||
| 
						
						
							
						
						5b1bdefacd
	
				 | 
					
					
						|||
| 
						
						
							
						
						d38a5df36f
	
				 | 
					
					
						|||
| 
						
						
							
						
						55dd8d743d
	
				 | 
					
					
						|||
| 
						
						
							
						
						7e6249bc3c
	
				 | 
					
					
						|||
| 
						
						
							
						
						adbda33078
	
				 | 
					
					
						|||
| 
						
						
							
						
						693ac6e677
	
				 | 
					
					
						|||
| 
						
						
							
						
						953b1009d3
	
				 | 
					
					
						|||
| 
						
						
							
						
						11053571d5
	
				 | 
					
					
						|||
| 
						
						
							
						
						86720c72f9
	
				 | 
					
					
						|||
| 
						
						
							
						
						0df1524976
	
				 | 
					
					
						|||
| 
						
						
							
						
						965b1b4339
	
				 | 
					
					
						|||
| 
						
						
							
						
						a9936a0f1b
	
				 | 
					
					
						|||
| 
						
						
							
						
						c229df8506
	
				 | 
					
					
						|||
| 
						
						
							
						
						9c92d7945d
	
				 | 
					
					
						|||
| 
						
						
							
						
						a4c305c2e9
	
				 | 
					
					
						|||
| 
						
						
							
						
						e66f6358a9
	
				 | 
					
					
						|||
| 
						
						
							
						
						100b585663
	
				 | 
					
					
						|||
| 
						
						
							
						
						f0cf3e12b6
	
				 | 
					
					
						|||
| 
						
						
							
						
						ce5f14db5d
	
				 | 
					
					
						|||
| 
						
						
							
						
						9b20413d64
	
				 | 
					
					
						|||
| 
						
						
							
						
						9c024454f2
	
				 | 
					
					
						|||
| 
						
						
							
						
						05db35cdfe
	
				 | 
					
					
						|||
| 
						
						
							
						
						bb95abdec6
	
				 | 
					
					
						|||
| 
						
						
							
						
						de93716b20
	
				 | 
					
					
						|||
| 
						
						
							
						
						53bc7fa320
	
				 | 
					
					
						|||
| 
						
						
							
						
						77c5f5ce18
	
				 | 
					
					
						|||
| 
						
						
							
						
						cf30eaae9b
	
				 | 
					
					
						|||
| 
						
						
							
						
						9338631de9
	
				 | 
					
					
						|||
| 
						
						
							
						
						a4638db773
	
				 | 
					
					
						|||
| 
						
						
							
						
						3c0254c9a1
	
				 | 
					
					
						|||
| 
						
						
							
						
						b1a5844b6b
	
				 | 
					
					
						|||
| 
						
						
							
						
						1ef900c44c
	
				 | 
					
					
						|||
| 
						
						
							
						
						29552f7a69
	
				 | 
					
					
						|||
| 
						
						
							
						
						57983b5a52
	
				 | 
					
					
						|||
| 
						
						
							
						
						88d7d7a0b4
	
				 | 
					
					
						|||
| 
						
						
							
						
						1f87c72e34
	
				 | 
					
					
						|||
| 
						
						
							
						
						454bfbf61d
	
				 | 
					
					
						|||
| 
						
						
							
						
						d5db68dbfa
	
				 | 
					
					
						|||
| 
						
						
							
						
						dfa5d41a6d
	
				 | 
					
					
						|||
| 
						
						
							
						
						32bce4eaba
	
				 | 
					
					
						|||
| 
						
						
							
						
						e86ce1aeaf
	
				 | 
					
					
						|||
| 
						
						
							
						
						b3a6dfbe07
	
				 | 
					
					
						|||
| 
						
						
							
						
						804ec99021
	
				 | 
					
					
						|||
| 
						
						
							
						
						ff05f8e2f3
	
				 | 
					
					
						|||
| 
						
						
							
						
						94cc596afa
	
				 | 
					
					
						|||
| 
						
						
							
						
						1a7b665376
	
				 | 
					
					
						|||
| 
						
						
							
						
						2d2efd4431
	
				 | 
					
					
						|||
| 
						
						
							
						
						3c9137816d
	
				 | 
					
					
						|||
| 
						
						
							
						
						40851c6a62
	
				 | 
					
					
						
							
								
								
									
										5
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -6,6 +6,8 @@
 | 
				
			|||||||
*.so
 | 
					*.so
 | 
				
			||||||
*.dylib
 | 
					*.dylib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/bin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Test binary, built with `go test -c`
 | 
					# Test binary, built with `go test -c`
 | 
				
			||||||
*.test
 | 
					*.test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,3 +21,6 @@
 | 
				
			|||||||
.vscode/configurationCache.log
 | 
					.vscode/configurationCache.log
 | 
				
			||||||
.vscode/dryrun.log
 | 
					.vscode/dryrun.log
 | 
				
			||||||
.vscode/targets.log
 | 
					.vscode/targets.log
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# packaging
 | 
				
			||||||
 | 
					/build
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										97
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										97
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,25 +1,108 @@
 | 
				
			|||||||
V ?= 0
 | 
					V ?= 0
 | 
				
			||||||
Q = $(if $(filter 1, $V),, @)
 | 
					Q = $(if $(filter 1, $V),, @)
 | 
				
			||||||
 | 
					BINDIR=$(CURDIR)/bin
 | 
				
			||||||
 | 
					PREFIX=/usr
 | 
				
			||||||
 | 
					DESTDIR=bin
 | 
				
			||||||
 | 
					BUILDDIR=$(CURDIR)/build
 | 
				
			||||||
 | 
					MANDIR=$(PREFIX)/share/man/man1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PKGREVISION=1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEBBUILDDIR=$(BUILDDIR)/deb
 | 
				
			||||||
 | 
					DEBTMPLDIR=$(CURDIR)/packaging/debian
 | 
				
			||||||
 | 
					DEBDATE=$(shell date -R)
 | 
				
			||||||
 | 
					DEBORIGSRC=lume_$(DEBVERSION).orig.tar.xz
 | 
				
			||||||
 | 
					DEBORIGSRCDIR=lume-$(DEBVERSION)
 | 
				
			||||||
 | 
					DEBREVISION=$(PKGREVISION)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RPMVERSION=$(subst -,_,$(LUME_VERSION))
 | 
				
			||||||
 | 
					RPMBUILDDIR=$(BUILDDIR)/rpm
 | 
				
			||||||
 | 
					RPMTMPLDIR=$(CURDIR)/packaging/rpm
 | 
				
			||||||
 | 
					RPMDATE=$(shell date "+%a %b %d %Y")
 | 
				
			||||||
 | 
					RPMORIGSRC=lume-$(RPMVERSION).tar.xz
 | 
				
			||||||
 | 
					RPMORIGSRCDIR=lume-$(RPMVERSION)
 | 
				
			||||||
 | 
					RPMREVISION=$(PKGREVISION)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ifeq ($(OS), Windows_NT)
 | 
					ifeq ($(OS), Windows_NT)
 | 
				
			||||||
    EXE=lume.exe
 | 
					    EXE=$(BINDIR)/lume.exe
 | 
				
			||||||
	RM=del /f /q
 | 
						RM=del /f /q
 | 
				
			||||||
	BUILD_DATE=$(shell powershell Get-Date -Format "yyyy-MM-ddThh:mm:sszzz")
 | 
						BUILD_DATE=$(shell powershell Get-Date -Format "yyyy-MM-ddThh:mm:sszzz")
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
    EXE=lume
 | 
					    EXE=$(BINDIR)/lume
 | 
				
			||||||
    EXE=rm -f
 | 
					    RM=rm -f
 | 
				
			||||||
	BUILD_DATE=$(shell date --iso-8601=seconds)
 | 
						BUILD_DATE=$(shell date --iso-8601=seconds)
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LUME_VERSION ?= $(shell git describe --tags --always)
 | 
					LUME_VERSION ?= $(shell git describe --tags --always)
 | 
				
			||||||
LDFLAGS := $(LDFLAGS) \
 | 
					GIT_COMMIT := $(shell git rev-parse --short HEAD)
 | 
				
			||||||
 | 
					GIT_TAG=$(shell git describe --tags --abbrev=0)
 | 
				
			||||||
 | 
					LDFLAGS = \
 | 
				
			||||||
	-X git.kill0.net/chill9/lume/cmd.Version=$(LUME_VERSION) \
 | 
						-X git.kill0.net/chill9/lume/cmd.Version=$(LUME_VERSION) \
 | 
				
			||||||
	-X git.kill0.net/chill9/lume/cmd.BuildDate=$(BUILD_DATE)
 | 
						-X git.kill0.net/chill9/lume/cmd.BuildDate=$(BUILD_DATE) \
 | 
				
			||||||
 | 
						-X git.kill0.net/chill9/lume/cmd.GitCommit=$(GIT_COMMIT)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ifneq (,$(findstring -,$(LUME_VERSION)))
 | 
				
			||||||
 | 
						DEBVERSION=$(GIT_TAG)+git$(shell date +%Y%m%d)+$(GIT_COMMIT)
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
						DEBVERSION=$(LUME_VERSION)
 | 
				
			||||||
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: build
 | 
					.PHONY: build
 | 
				
			||||||
build:
 | 
					build:
 | 
				
			||||||
	$(Q) go build -o $(EXE) -ldflags="$(LDFLAGS)" ./cmd/lume
 | 
						$(Q) go build -o $(EXE) -ldflags="$(LDFLAGS)" ./cmd/lume
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean
 | 
					.PHONY: clean
 | 
				
			||||||
clean:
 | 
					clean: deb-clean rpm-clean
 | 
				
			||||||
	$(RM) $(EXE)
 | 
						$(Q) $(RM) $(EXE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					install-man:
 | 
				
			||||||
 | 
						install -p -D -m 0644 lume.1 $(DESTDIR)$(MANDIR)/lume.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PHONY: install
 | 
				
			||||||
 | 
					install: install-man
 | 
				
			||||||
 | 
						$(Q) install -p -D -m 0755 $(EXE) $(DESTDIR)${PREFIX}/bin/lume
 | 
				
			||||||
 | 
						$(Q) install -p -D -m 0644 .lumerc.sample $(DESTDIR)${PREFIX}/share/lume/lumerc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PHONY: deb
 | 
				
			||||||
 | 
					deb: deb-clean
 | 
				
			||||||
 | 
						$(Q) mkdir -p $(DEBBUILDDIR)
 | 
				
			||||||
 | 
						$(Q) git archive --format tar --prefix lume-$(DEBVERSION)/ $(LUME_VERSION) | xz > $(DEBBUILDDIR)/$(DEBORIGSRC)
 | 
				
			||||||
 | 
						$(Q) tar xf $(DEBBUILDDIR)/$(DEBORIGSRC) -C $(DEBBUILDDIR)
 | 
				
			||||||
 | 
						$(Q) mkdir $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian
 | 
				
			||||||
 | 
						$(Q) mkdir $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/source
 | 
				
			||||||
 | 
						$(Q) sed -e 's/__VERSION__/$(DEBVERSION)/g' -e 's/__REVISION__/$(DEBREVISION)/g' $(DEBTMPLDIR)/rules > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/rules
 | 
				
			||||||
 | 
						$(Q) chmod 0755 $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/rules
 | 
				
			||||||
 | 
						$(Q) sed -e 's/__VERSION__/$(DEBVERSION)/g' -e 's/__DATE__/$(DEBDATE)/g' -e 's/__REVISION__/$(DEBREVISION)/g' $(DEBTMPLDIR)/changelog > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/changelog
 | 
				
			||||||
 | 
						$(Q) echo 10 > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/compat
 | 
				
			||||||
 | 
						$(Q) echo "3.0 (quilt)" > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/source/format
 | 
				
			||||||
 | 
						$(Q) cp $(DEBTMPLDIR)/control $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/control
 | 
				
			||||||
 | 
						$(Q) cp $(DEBTMPLDIR)/copyright $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/copyright
 | 
				
			||||||
 | 
						$(Q) cp $(DEBTMPLDIR)/lume.manpages $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/lume.manpages
 | 
				
			||||||
 | 
						$(Q) cd $(DEBBUILDDIR)/$(DEBORIGSRCDIR) && dpkg-buildpackage -us -uc
 | 
				
			||||||
 | 
						$(Q) mv $(DEBBUILDDIR)/*.dsc $(BUILDDIR)
 | 
				
			||||||
 | 
						$(Q) mv $(DEBBUILDDIR)/*.changes $(BUILDDIR)
 | 
				
			||||||
 | 
						$(Q) mv $(DEBBUILDDIR)/*.buildinfo $(BUILDDIR)
 | 
				
			||||||
 | 
						$(Q) mv $(DEBBUILDDIR)/*.deb $(BUILDDIR)
 | 
				
			||||||
 | 
						$(Q) mv $(DEBBUILDDIR)/*.tar.* $(BUILDDIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PHONY: rpm
 | 
				
			||||||
 | 
					rpm: rpm-clean
 | 
				
			||||||
 | 
						$(Q) mkdir -p $(RPMBUILDDIR)/SPECS
 | 
				
			||||||
 | 
						$(Q) mkdir -p $(RPMBUILDDIR)/SOURCES
 | 
				
			||||||
 | 
						$(Q) sed -e 's/__VERSION__/$(RPMVERSION)/g' -e 's/__DATE__/$(RPMDATE)/g' -e 's/__REVISION__/$(RPMREVISION)/g' $(RPMTMPLDIR)/lume.spec > $(RPMBUILDDIR)/SPECS/lume.spec
 | 
				
			||||||
 | 
						$(Q) git archive --format tar --prefix $(RPMORIGSRCDIR)/ $(LUME_VERSION) | xz > $(RPMBUILDDIR)/SOURCES/$(RPMORIGSRC)
 | 
				
			||||||
 | 
						$(Q) rpmbuild --define "_topdir $(RPMBUILDDIR)"  -ba $(RPMBUILDDIR)/SPECS/lume.spec
 | 
				
			||||||
 | 
						$(Q) mv $(RPMBUILDDIR)/RPMS/*/*.rpm $(BUILDDIR)
 | 
				
			||||||
 | 
						$(Q) mv $(RPMBUILDDIR)/SRPMS/*.rpm $(BUILDDIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					deb-clean:
 | 
				
			||||||
 | 
						$(Q) rm -rf $(DEBBUILDDIR)
 | 
				
			||||||
 | 
						$(Q) rm -f $(BUILDDIR)/*.dsc
 | 
				
			||||||
 | 
						$(Q) rm -f $(BUILDDIR)/*.changes
 | 
				
			||||||
 | 
						$(Q) rm -f $(BUILDDIR)/*.buildinfo
 | 
				
			||||||
 | 
						$(Q) rm -f $(BUILDDIR)/*.deb
 | 
				
			||||||
 | 
						$(Q) rm -f $(BUILDDIR)/*.tar.*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rpm-clean:
 | 
				
			||||||
 | 
						$(Q) rm -rf $(RPMBUILDDIR)
 | 
				
			||||||
 | 
						$(Q) rm -f $(BUILDDIR)/*.rpm
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										109
									
								
								cmd/breathe.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								cmd/breathe.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,109 @@
 | 
				
			|||||||
 | 
					package lumecmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"flag"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.kill0.net/chill9/lifx-go"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewCmdBreathe() Command {
 | 
				
			||||||
 | 
						return Command{
 | 
				
			||||||
 | 
							Name: "breathe",
 | 
				
			||||||
 | 
							Func: BreatheCmd,
 | 
				
			||||||
 | 
							Flags: func() *flag.FlagSet {
 | 
				
			||||||
 | 
								fs := flag.NewFlagSet("breathe", flag.ExitOnError)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								selector := fs.String("selector", defaultSelector, "Set the selector")
 | 
				
			||||||
 | 
								fs.StringVar(selector, "s", defaultSelector, "Set the selector")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								color := fs.String("color", defaultColor, "The color to use for the breathe effect")
 | 
				
			||||||
 | 
								fs.StringVar(color, "c", defaultColor, "The color to use for the breathe effect")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								fs.String("from-color", defaultColor, "The color to start the effect from")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								fs.Float64("period", lifx.DefaultBreathePeriod, "The time in seconds for one cycle of the effect")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								fs.Float64("cycles", lifx.DefaultBreatheCycles, "The number of times to repeat the effect")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								fs.Bool("persist", lifx.DefaultBreathePersist, "If false set the light back to its previous value when effect ends, if true leave the last effect color")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								fs.Bool("power-on", lifx.DefaultBreathePowerOn, "If true, turn the bulb on if it is not already on")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								fs.Float64("peak", lifx.DefaultBreathePeak, "Defines where in a period the target color is at its maximum (min: 0.0, max: 1.0)")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return fs
 | 
				
			||||||
 | 
							}(),
 | 
				
			||||||
 | 
							Use:   "[--selector <selector>] --color <color> [--from-color <color>] [--period <period>] [--cycles <cycles>] [--persist <persist>] [--power-on] [--peak <peak>]",
 | 
				
			||||||
 | 
							Short: "The breathe effect",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func BreatheCmd(ctx Context) (int, error) {
 | 
				
			||||||
 | 
						var p Printer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						c := ctx.Client
 | 
				
			||||||
 | 
						breathe := lifx.NewBreathe()
 | 
				
			||||||
 | 
						selector := ctx.Flags.String("selector")
 | 
				
			||||||
 | 
						format, err := getOutputFormatFromFlags(ctx.Flags)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if format == "" && ctx.Config.OutputFormat != "" {
 | 
				
			||||||
 | 
							format = ctx.Config.OutputFormat
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						color := ctx.Flags.String("color")
 | 
				
			||||||
 | 
						if color != "" {
 | 
				
			||||||
 | 
							breathe.Color = lifx.NamedColor(color)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						from_color := ctx.Flags.String("from-color")
 | 
				
			||||||
 | 
						if from_color != "" {
 | 
				
			||||||
 | 
							breathe.FromColor = lifx.NamedColor(from_color)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						periodFlag := ctx.Flags.String("period")
 | 
				
			||||||
 | 
						if periodFlag != "" {
 | 
				
			||||||
 | 
							period := ctx.Flags.Float64("period")
 | 
				
			||||||
 | 
							breathe.Period = period
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cyclesFlag := ctx.Flags.String("cycles")
 | 
				
			||||||
 | 
						if cyclesFlag != "" {
 | 
				
			||||||
 | 
							cycles := ctx.Flags.Float64("cycles")
 | 
				
			||||||
 | 
							breathe.Cycles = cycles
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						persist := ctx.Flags.Bool("persist")
 | 
				
			||||||
 | 
						breathe.Persist = persist
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						power_on := ctx.Flags.Bool("power-on")
 | 
				
			||||||
 | 
						breathe.PowerOn = power_on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						peakFlag := ctx.Flags.String("peak")
 | 
				
			||||||
 | 
						if peakFlag != "" {
 | 
				
			||||||
 | 
							peak := ctx.Flags.Float64("peak")
 | 
				
			||||||
 | 
							breathe.Peak = peak
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if color == "" {
 | 
				
			||||||
 | 
							printCmdHelp(ctx.Name)
 | 
				
			||||||
 | 
							return ExitFailure, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := breathe.Valid(); err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						r, err := c.Breathe(selector, breathe)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						p = NewPrinter(format)
 | 
				
			||||||
 | 
						fmt.Print(p.Results(r.Results))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return ExitSuccess, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -14,12 +14,7 @@ const (
 | 
				
			|||||||
	ExitFailure
 | 
						ExitFailure
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Config struct {
 | 
					type Context struct {
 | 
				
			||||||
	AccessToken string               `toml:"access_token"`
 | 
					 | 
				
			||||||
	Colors      map[string][]float32 `toml:"colors"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type CmdArgs struct {
 | 
					 | 
				
			||||||
	Flags  Flags
 | 
						Flags  Flags
 | 
				
			||||||
	Args   []string
 | 
						Args   []string
 | 
				
			||||||
	Client *lifx.Client
 | 
						Client *lifx.Client
 | 
				
			||||||
@@ -33,7 +28,7 @@ type Flags struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type Command struct {
 | 
					type Command struct {
 | 
				
			||||||
	Name  string
 | 
						Name  string
 | 
				
			||||||
	Func  func(CmdArgs) (int, error)
 | 
						Func  func(Context) (int, error)
 | 
				
			||||||
	Flags *flag.FlagSet
 | 
						Flags *flag.FlagSet
 | 
				
			||||||
	Use   string
 | 
						Use   string
 | 
				
			||||||
	Short string
 | 
						Short string
 | 
				
			||||||
@@ -43,19 +38,20 @@ type Command struct {
 | 
				
			|||||||
var commandRegistry = make(map[string]Command)
 | 
					var commandRegistry = make(map[string]Command)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
	defaultSelector    string  = "all"
 | 
						defaultSelector     string  = "all"
 | 
				
			||||||
	defaultDuration    float64 = 1.0
 | 
						defaultDuration     float64 = 1.0
 | 
				
			||||||
	defaultPower       string  = ""
 | 
						defaultPower        string  = ""
 | 
				
			||||||
	defaultColor       string  = ""
 | 
						defaultColor        string  = ""
 | 
				
			||||||
	defaultBrightness  string  = ""
 | 
						defaultBrightness   string  = ""
 | 
				
			||||||
	defaultInfrared    string  = ""
 | 
						defaultInfrared     string  = ""
 | 
				
			||||||
	defaultFast        bool    = false
 | 
						defaultFast         bool    = false
 | 
				
			||||||
	defaultWhiteKelvin string  = ""
 | 
						defaultWhiteKelvin  string  = ""
 | 
				
			||||||
	defaultWhiteName   string  = ""
 | 
						defaultWhiteName    string  = ""
 | 
				
			||||||
	defaultHue         string  = ""
 | 
						defaultHue          string  = ""
 | 
				
			||||||
	defaultSaturation  string  = ""
 | 
						defaultSaturation   string  = ""
 | 
				
			||||||
	defaultRGB         string  = ""
 | 
						defaultRGB          string  = ""
 | 
				
			||||||
	defaultName        string  = ""
 | 
						defaultName         string  = ""
 | 
				
			||||||
 | 
						defaultOutputFormat string  = ""
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (f Flags) String(name string) string {
 | 
					func (f Flags) String(name string) string {
 | 
				
			||||||
@@ -86,6 +82,13 @@ func RegisterCommand(cmd Command) error {
 | 
				
			|||||||
	if _, ok := commandRegistry[cmd.Name]; ok {
 | 
						if _, ok := commandRegistry[cmd.Name]; ok {
 | 
				
			||||||
		return fmt.Errorf("%s command is already registered")
 | 
							return fmt.Errorf("%s command is already registered")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if cmd.Flags == nil {
 | 
				
			||||||
 | 
							cmd.Flags = flag.NewFlagSet(cmd.Name, flag.ExitOnError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mergeGlobalFlags(cmd.Flags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	commandRegistry[cmd.Name] = cmd
 | 
						commandRegistry[cmd.Name] = cmd
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -95,37 +98,25 @@ func GetCommand(name string) (Command, bool) {
 | 
				
			|||||||
	return cmd, ok
 | 
						return cmd, ok
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Validate configuration struct
 | 
					func mergeGlobalFlags(fs *flag.FlagSet) {
 | 
				
			||||||
func (c *Config) Validate() error {
 | 
						fs.Bool("debug", false, "Enable debug mode")
 | 
				
			||||||
	var err error
 | 
					 | 
				
			||||||
	if c.AccessToken == "" {
 | 
					 | 
				
			||||||
		err = errors.New("access_token is not set")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = c.validateColors(); err != nil {
 | 
						formatTable := fs.Bool("table", false, "Format output as an ASCII table")
 | 
				
			||||||
		return err
 | 
						fs.BoolVar(formatTable, "t", false, "Format output as an ASCII table")
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return err
 | 
						fs.Bool("simple", false, "Format output simply")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Config) validateColors() (err error) {
 | 
					func getOutputFormatFromFlags(fs Flags) (string, error) {
 | 
				
			||||||
	if len(c.Colors) > 0 {
 | 
						formatSimple := fs.Bool("simple")
 | 
				
			||||||
		for name, hsb := range c.Colors {
 | 
						formatTable := fs.Bool("table")
 | 
				
			||||||
			if len(hsb) != 3 {
 | 
					
 | 
				
			||||||
				return fmt.Errorf("color '%s' needs three values", name)
 | 
						switch {
 | 
				
			||||||
			}
 | 
						case formatSimple && formatTable:
 | 
				
			||||||
			h, s, b := hsb[0], hsb[1], hsb[2]
 | 
							return "", errors.New("only one output format permitted")
 | 
				
			||||||
			if h < 0 || h > 360 {
 | 
						case formatTable:
 | 
				
			||||||
				return fmt.Errorf("color '%s' hue value must be between 0.0-360.0", name)
 | 
							return "table", nil
 | 
				
			||||||
			}
 | 
						default:
 | 
				
			||||||
			if s < 0 || b > 1 {
 | 
							return "simple", nil
 | 
				
			||||||
				return fmt.Errorf("color '%s' saturation value must be between 0.0-1.0", name)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if b < 0 || b > 1 {
 | 
					 | 
				
			||||||
				return fmt.Errorf("color '%s' brightness value must be between 0.0-1.0", name)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return err
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										157
									
								
								cmd/config.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										157
									
								
								cmd/config.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,157 @@
 | 
				
			|||||||
 | 
					package lumecmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"path"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/BurntSushi/toml"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const lumercFile string = ".lumerc"
 | 
				
			||||||
 | 
					const lumeConfigFile string = "lume.conf"
 | 
				
			||||||
 | 
					const defaultPowerIndicator rune = '●'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Config struct {
 | 
				
			||||||
 | 
						AccessToken  string               `toml:"access_token"`
 | 
				
			||||||
 | 
						OutputFormat string               `toml:"output_format"`
 | 
				
			||||||
 | 
						Colors       map[string][]float32 `toml:"colors"`
 | 
				
			||||||
 | 
						userAgent    string
 | 
				
			||||||
 | 
						Debug        bool   `toml:"debug"`
 | 
				
			||||||
 | 
						Indicator    string `toml:"indicator"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var (
 | 
				
			||||||
 | 
						DefaultConfig = Config{
 | 
				
			||||||
 | 
							userAgent: initUserAgent(),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						globalConfig *Config = NewConfig()
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewConfig() *Config {
 | 
				
			||||||
 | 
						c := new(Config)
 | 
				
			||||||
 | 
						c.userAgent = initUserAgent()
 | 
				
			||||||
 | 
						c.Debug = false
 | 
				
			||||||
 | 
						c.OutputFormat = "simple"
 | 
				
			||||||
 | 
						c.Indicator = string(defaultPowerIndicator)
 | 
				
			||||||
 | 
						return c
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetConfig() *Config {
 | 
				
			||||||
 | 
						return globalConfig
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Validate configuration struct
 | 
				
			||||||
 | 
					func (c *Config) Validate() error {
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if c.AccessToken == "" {
 | 
				
			||||||
 | 
							return errors.New("access_token is not set")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len([]rune(c.Indicator)) != 1 {
 | 
				
			||||||
 | 
							return errors.New("indicator must be a single rune")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err = c.validateColors(); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (c *Config) validateColors() (err error) {
 | 
				
			||||||
 | 
						if len(c.Colors) > 0 {
 | 
				
			||||||
 | 
							for name, hsb := range c.Colors {
 | 
				
			||||||
 | 
								if len(hsb) != 3 {
 | 
				
			||||||
 | 
									return fmt.Errorf("color '%s' needs three values", name)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								h, s, b := hsb[0], hsb[1], hsb[2]
 | 
				
			||||||
 | 
								if h < 0 || h > 360 {
 | 
				
			||||||
 | 
									return fmt.Errorf("color '%s' hue value must be between 0.0-360.0", name)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if s < 0 || b > 1 {
 | 
				
			||||||
 | 
									return fmt.Errorf("color '%s' saturation value must be between 0.0-1.0", name)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if b < 0 || b > 1 {
 | 
				
			||||||
 | 
									return fmt.Errorf("color '%s' brightness value must be between 0.0-1.0", name)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (c *Config) MergeWithEnv() {
 | 
				
			||||||
 | 
						envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN")
 | 
				
			||||||
 | 
						if envAccessToken != "" {
 | 
				
			||||||
 | 
							c.AccessToken = envAccessToken
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func LoadConfig(s string) (*Config, error) {
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
						var c *Config = GetConfig()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := toml.Decode(s, &c); err != nil {
 | 
				
			||||||
 | 
							err = fmt.Errorf("fatal: failed to parse; %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func LoadConfigFile(configPath string) (*Config, error) {
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var c *Config = GetConfig()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := toml.DecodeFile(configPath, &c); err != nil {
 | 
				
			||||||
 | 
							err = fmt.Errorf("fatal: failed to parse %s; %w", configPath, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getConfigPath() string {
 | 
				
			||||||
 | 
						var tryPath, configPath, homeDir, cwd string
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// ~/.lumerc
 | 
				
			||||||
 | 
						homeDir, err = os.UserHomeDir()
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							tryPath = path.Join(homeDir, lumercFile)
 | 
				
			||||||
 | 
							if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
 | 
				
			||||||
 | 
								configPath = tryPath
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// ~/.config/lume/lume.conf
 | 
				
			||||||
 | 
						homeDir, err = os.UserHomeDir()
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							tryPath = path.Join(homeDir, ".config/lume", lumeConfigFile)
 | 
				
			||||||
 | 
							if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
 | 
				
			||||||
 | 
								configPath = tryPath
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// ./.lumerc
 | 
				
			||||||
 | 
						cwd, err = os.Getwd()
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							tryPath = path.Join(cwd, lumercFile)
 | 
				
			||||||
 | 
							if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
 | 
				
			||||||
 | 
								configPath = tryPath
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return configPath
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func initUserAgent() string {
 | 
				
			||||||
 | 
						var b strings.Builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						b.WriteString("lume")
 | 
				
			||||||
 | 
						b.WriteRune('/')
 | 
				
			||||||
 | 
						b.WriteString(Version)
 | 
				
			||||||
 | 
						return b.String()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										52
									
								
								cmd/help.go
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								cmd/help.go
									
									
									
									
									
								
							@@ -3,6 +3,7 @@ package lumecmd
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewCmdHelp() Command {
 | 
					func NewCmdHelp() Command {
 | 
				
			||||||
@@ -14,17 +15,23 @@ func NewCmdHelp() Command {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func HelpCmd(args CmdArgs) (int, error) {
 | 
					func HelpCmd(ctx Context) (int, error) {
 | 
				
			||||||
	if len(args.Args) == 0 {
 | 
						if len(ctx.Args) == 0 {
 | 
				
			||||||
		printHelp(commandRegistry)
 | 
							fmt.Print(printHelp(commandRegistry))
 | 
				
			||||||
	} else if len(args.Args) >= 1 {
 | 
						} else if len(ctx.Args) >= 1 {
 | 
				
			||||||
		printCmdHelp(args.Args[0])
 | 
							if cmdHelp, err := printCmdHelp(ctx.Args[0]); err == nil {
 | 
				
			||||||
 | 
								fmt.Print(cmdHelp)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								fmt.Print(err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ExitSuccess, nil
 | 
						return ExitSuccess, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func printHelp(commands map[string]Command) {
 | 
					func printHelp(commands map[string]Command) string {
 | 
				
			||||||
 | 
						var b strings.Builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var maxLen, cmdLen int
 | 
						var maxLen, cmdLen int
 | 
				
			||||||
	var keys []string
 | 
						var keys []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -36,34 +43,45 @@ func printHelp(commands map[string]Command) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fmt.Printf("usage:\n  lume <command> [<args...>]")
 | 
						fmt.Fprintf(&b, "usage:\n  lume <command> [<args...>]")
 | 
				
			||||||
	fmt.Println()
 | 
						fmt.Fprintln(&b)
 | 
				
			||||||
	fmt.Println("\ncommands:")
 | 
						fmt.Fprintln(&b, "\ncommands:")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sort.Strings(keys)
 | 
						sort.Strings(keys)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, k := range keys {
 | 
						for _, k := range keys {
 | 
				
			||||||
		c := commands[k]
 | 
							c := commands[k]
 | 
				
			||||||
		fmt.Printf("  %-*s    %s\n", maxLen, c.Name, c.Short)
 | 
							fmt.Fprintf(&b, "  %-*s    %s\n", maxLen, c.Name, c.Short)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return b.String()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func printCmdHelp(name string) error {
 | 
					func printCmdHelp(name string) (string, error) {
 | 
				
			||||||
 | 
						var b strings.Builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	subCmd, ok := commandRegistry[name]
 | 
						subCmd, ok := commandRegistry[name]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		return fmt.Errorf("unknown commnnd: %s\n", name)
 | 
							return "", fmt.Errorf("unknown commnnd: %s\n", name)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if subCmd.Use != "" {
 | 
						if subCmd.Use != "" {
 | 
				
			||||||
		fmt.Printf("usage:\n  lume %s %s\n", subCmd.Name, subCmd.Use)
 | 
							fmt.Fprintf(&b, "usage:\n  lume %s %s\n", subCmd.Name, subCmd.Use)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		fmt.Printf("usage:\n  lume %s\n", subCmd.Name)
 | 
							fmt.Fprintf(&b, "usage:\n  lume %s\n", subCmd.Name)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if subCmd.Flags != nil {
 | 
						if subCmd.Flags != nil {
 | 
				
			||||||
		fmt.Println()
 | 
							out := subCmd.Flags.Output()
 | 
				
			||||||
		fmt.Print("flags:\n")
 | 
							defer subCmd.Flags.SetOutput(out)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							fmt.Fprintln(&b)
 | 
				
			||||||
 | 
							fmt.Fprint(&b, "flags:\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							subCmd.Flags.SetOutput(&b)
 | 
				
			||||||
		subCmd.Flags.PrintDefaults()
 | 
							subCmd.Flags.PrintDefaults()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return b.String(), nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										30
									
								
								cmd/ls.go
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								cmd/ls.go
									
									
									
									
									
								
							@@ -1,6 +1,9 @@
 | 
				
			|||||||
package lumecmd
 | 
					package lumecmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "flag"
 | 
					import (
 | 
				
			||||||
 | 
						"flag"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewCmdLs() Command {
 | 
					func NewCmdLs() Command {
 | 
				
			||||||
	return Command{
 | 
						return Command{
 | 
				
			||||||
@@ -19,13 +22,28 @@ func NewCmdLs() Command {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func LsCmd(args CmdArgs) (int, error) {
 | 
					func LsCmd(ctx Context) (int, error) {
 | 
				
			||||||
	c := args.Client
 | 
						var p Printer
 | 
				
			||||||
	selector := args.Flags.String("selector")
 | 
					
 | 
				
			||||||
	lights, err := c.ListLights(selector)
 | 
						c := ctx.Client
 | 
				
			||||||
 | 
						selector := ctx.Flags.String("selector")
 | 
				
			||||||
 | 
						format, err := getOutputFormatFromFlags(ctx.Flags)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return ExitFailure, err
 | 
							return ExitFailure, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	PrintLights(lights)
 | 
					
 | 
				
			||||||
 | 
						if format == "" && ctx.Config.OutputFormat != "" {
 | 
				
			||||||
 | 
							format = ctx.Config.OutputFormat
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						lights, err := c.ListLights(selector)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						p = NewPrinter(format)
 | 
				
			||||||
 | 
						fmt.Print(p.Lights(lights))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ExitSuccess, nil
 | 
						return ExitSuccess, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										76
									
								
								cmd/main.go
									
									
									
									
									
								
							
							
						
						
									
										76
									
								
								cmd/main.go
									
									
									
									
									
								
							@@ -4,19 +4,11 @@ import (
 | 
				
			|||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"path"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.kill0.net/chill9/lifx-go"
 | 
						"git.kill0.net/chill9/lifx-go"
 | 
				
			||||||
	"github.com/BurntSushi/toml"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var userAgent string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
	userAgent = initUserAgent()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	RegisterCommand(NewCmdHelp())
 | 
						RegisterCommand(NewCmdHelp())
 | 
				
			||||||
	RegisterCommand(NewCmdLs())
 | 
						RegisterCommand(NewCmdLs())
 | 
				
			||||||
	RegisterCommand(NewCmdPoweroff())
 | 
						RegisterCommand(NewCmdPoweroff())
 | 
				
			||||||
@@ -27,17 +19,20 @@ func init() {
 | 
				
			|||||||
	RegisterCommand(NewCmdShow())
 | 
						RegisterCommand(NewCmdShow())
 | 
				
			||||||
	RegisterCommand(NewCmdToggle())
 | 
						RegisterCommand(NewCmdToggle())
 | 
				
			||||||
	RegisterCommand(NewCmdVersion())
 | 
						RegisterCommand(NewCmdVersion())
 | 
				
			||||||
 | 
						RegisterCommand(NewCmdBreathe())
 | 
				
			||||||
 | 
						RegisterCommand(NewCmdValidate())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var Version string = "0.1.0-pre"
 | 
					var Version string
 | 
				
			||||||
var BuildDate string
 | 
					var BuildDate string
 | 
				
			||||||
 | 
					var GitCommit string
 | 
				
			||||||
const lumercFile string = ".lumerc"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Main(args []string) (int, error) {
 | 
					func Main(args []string) (int, error) {
 | 
				
			||||||
	var config Config
 | 
						var config *Config = GetConfig()
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						flag.Parse()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(args) == 1 {
 | 
						if len(args) == 1 {
 | 
				
			||||||
		args = append(args, "help")
 | 
							args = append(args, "help")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -48,32 +43,26 @@ func Main(args []string) (int, error) {
 | 
				
			|||||||
		return ExitFailure, err
 | 
							return ExitFailure, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if _, err := toml.DecodeFile(configPath, &config); err != nil {
 | 
						if config, err = LoadConfigFile(configPath); err != nil {
 | 
				
			||||||
		err = fmt.Errorf("fatal: failed to parse %s; %w", configPath, err)
 | 
					 | 
				
			||||||
		return ExitFailure, err
 | 
							return ExitFailure, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						config.MergeWithEnv()
 | 
				
			||||||
	envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN")
 | 
					 | 
				
			||||||
	if envAccessToken != "" {
 | 
					 | 
				
			||||||
		config.AccessToken = envAccessToken
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = config.Validate(); err != nil {
 | 
						if err = config.Validate(); err != nil {
 | 
				
			||||||
		return ExitFailure, fmt.Errorf("fatal: %s", err)
 | 
							return ExitFailure, fmt.Errorf("fatal: %s", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flag.Parse()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	command := args[1]
 | 
						command := args[1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c := lifx.NewClient(
 | 
						c := lifx.NewClient(
 | 
				
			||||||
		config.AccessToken,
 | 
							config.AccessToken,
 | 
				
			||||||
		lifx.WithUserAgent(userAgent),
 | 
							lifx.WithUserAgent(config.userAgent),
 | 
				
			||||||
 | 
							lifx.WithDebug(config.Debug),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cmdArgs := CmdArgs{
 | 
						ctx := Context{
 | 
				
			||||||
		Client: c,
 | 
							Client: c,
 | 
				
			||||||
		Config: config,
 | 
							Config: *config,
 | 
				
			||||||
		Args:   args[2:],
 | 
							Args:   args[2:],
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -86,47 +75,14 @@ func Main(args []string) (int, error) {
 | 
				
			|||||||
	fs := cmd.Flags
 | 
						fs := cmd.Flags
 | 
				
			||||||
	if fs != nil {
 | 
						if fs != nil {
 | 
				
			||||||
		fs.Parse(args[2:])
 | 
							fs.Parse(args[2:])
 | 
				
			||||||
		cmdArgs.Flags = Flags{FlagSet: fs}
 | 
							ctx.Flags = Flags{FlagSet: fs}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	cmdArgs.Name = command
 | 
						ctx.Name = command
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	exitCode, err := cmd.Func(cmdArgs)
 | 
						exitCode, err := cmd.Func(ctx)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		err = fmt.Errorf("fatal: %s", err)
 | 
							err = fmt.Errorf("fatal: %s", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return exitCode, err
 | 
						return exitCode, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func getConfigPath() string {
 | 
					 | 
				
			||||||
	var tryPath, configPath string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// ~/.lumerc
 | 
					 | 
				
			||||||
	homeDir, err := os.UserHomeDir()
 | 
					 | 
				
			||||||
	if err == nil {
 | 
					 | 
				
			||||||
		tryPath = path.Join(homeDir, lumercFile)
 | 
					 | 
				
			||||||
		if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
 | 
					 | 
				
			||||||
			configPath = tryPath
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// ./.lumerc
 | 
					 | 
				
			||||||
	cwd, err := os.Getwd()
 | 
					 | 
				
			||||||
	if err == nil {
 | 
					 | 
				
			||||||
		tryPath = path.Join(cwd, lumercFile)
 | 
					 | 
				
			||||||
		if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
 | 
					 | 
				
			||||||
			configPath = tryPath
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return configPath
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func initUserAgent() string {
 | 
					 | 
				
			||||||
	var b strings.Builder
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	b.WriteString("lume")
 | 
					 | 
				
			||||||
	b.WriteRune('/')
 | 
					 | 
				
			||||||
	b.WriteString(Version)
 | 
					 | 
				
			||||||
	return b.String()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ package lumecmd
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.kill0.net/chill9/lifx-go"
 | 
						"git.kill0.net/chill9/lifx-go"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -26,16 +27,29 @@ func NewCmdPoweroff() Command {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func PoweroffCmd(args CmdArgs) (int, error) {
 | 
					func PoweroffCmd(ctx Context) (int, error) {
 | 
				
			||||||
	c := args.Client
 | 
						var p Printer
 | 
				
			||||||
	duration := args.Flags.Float64("duration")
 | 
					
 | 
				
			||||||
	selector := args.Flags.String("selector")
 | 
						c := ctx.Client
 | 
				
			||||||
 | 
						duration := ctx.Flags.Float64("duration")
 | 
				
			||||||
 | 
						selector := ctx.Flags.String("selector")
 | 
				
			||||||
	state := lifx.State{Power: "off", Duration: duration}
 | 
						state := lifx.State{Power: "off", Duration: duration}
 | 
				
			||||||
 | 
						format, err := getOutputFormatFromFlags(ctx.Flags)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if format == "" && ctx.Config.OutputFormat != "" {
 | 
				
			||||||
 | 
							format = ctx.Config.OutputFormat
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	r, err := c.SetState(selector, state)
 | 
						r, err := c.SetState(selector, state)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return ExitFailure, err
 | 
							return ExitFailure, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	PrintResults(r.Results)
 | 
					
 | 
				
			||||||
 | 
						p = NewPrinter(format)
 | 
				
			||||||
 | 
						fmt.Print(p.Results(r.Results))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ExitSuccess, nil
 | 
						return ExitSuccess, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ package lumecmd
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.kill0.net/chill9/lifx-go"
 | 
						"git.kill0.net/chill9/lifx-go"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -26,16 +27,29 @@ func NewCmdPoweron() Command {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func PoweronCmd(args CmdArgs) (int, error) {
 | 
					func PoweronCmd(ctx Context) (int, error) {
 | 
				
			||||||
	c := args.Client
 | 
						var p Printer
 | 
				
			||||||
	duration := args.Flags.Float64("duration")
 | 
					
 | 
				
			||||||
	selector := args.Flags.String("selector")
 | 
						c := ctx.Client
 | 
				
			||||||
 | 
						duration := ctx.Flags.Float64("duration")
 | 
				
			||||||
 | 
						selector := ctx.Flags.String("selector")
 | 
				
			||||||
	state := lifx.State{Power: "on", Duration: duration}
 | 
						state := lifx.State{Power: "on", Duration: duration}
 | 
				
			||||||
 | 
						format, err := getOutputFormatFromFlags(ctx.Flags)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if format == "" && ctx.Config.OutputFormat != "" {
 | 
				
			||||||
 | 
							format = ctx.Config.OutputFormat
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	r, err := c.SetState(selector, state)
 | 
						r, err := c.SetState(selector, state)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return ExitFailure, err
 | 
							return ExitFailure, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	PrintResults(r.Results)
 | 
					
 | 
				
			||||||
 | 
						p = NewPrinter(format)
 | 
				
			||||||
 | 
						fmt.Print(p.Results(r.Results))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ExitSuccess, nil
 | 
						return ExitSuccess, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										195
									
								
								cmd/print.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										195
									
								
								cmd/print.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,195 @@
 | 
				
			|||||||
 | 
					package lumecmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.kill0.net/chill9/lifx-go"
 | 
				
			||||||
 | 
						"github.com/fatih/color"
 | 
				
			||||||
 | 
						"github.com/olekukonko/tablewriter"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Printer interface {
 | 
				
			||||||
 | 
						Results(results []lifx.Result) string
 | 
				
			||||||
 | 
						Lights(lights []lifx.Light) string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type defaultPrinter struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type tablePrinter struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewPrinter(format string) Printer {
 | 
				
			||||||
 | 
						switch format {
 | 
				
			||||||
 | 
						case "table":
 | 
				
			||||||
 | 
							return &tablePrinter{}
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return &defaultPrinter{}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (dp *defaultPrinter) Results(results []lifx.Result) string {
 | 
				
			||||||
 | 
						var b strings.Builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sortResults(results)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						table := tablewriter.NewWriter(&b)
 | 
				
			||||||
 | 
						_, rows := makeResultsTable(results)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, v := range rows {
 | 
				
			||||||
 | 
							table.Append(v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Fprintf(&b, "total %d\n", len(results))
 | 
				
			||||||
 | 
						table.SetAlignment(tablewriter.ALIGN_LEFT)
 | 
				
			||||||
 | 
						table.SetAutoWrapText(false)
 | 
				
			||||||
 | 
						table.SetBorder(false)
 | 
				
			||||||
 | 
						table.SetCenterSeparator("")
 | 
				
			||||||
 | 
						table.SetColumnSeparator("")
 | 
				
			||||||
 | 
						table.SetHeaderLine(false)
 | 
				
			||||||
 | 
						table.SetNoWhiteSpace(true)
 | 
				
			||||||
 | 
						table.SetRowSeparator("")
 | 
				
			||||||
 | 
						table.SetTablePadding(" ")
 | 
				
			||||||
 | 
						table.Render()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return b.String()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (tp *tablePrinter) Results(results []lifx.Result) string {
 | 
				
			||||||
 | 
						var b strings.Builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sortResults(results)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						table := tablewriter.NewWriter(&b)
 | 
				
			||||||
 | 
						hdr, rows := makeResultsTable(results)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, v := range rows {
 | 
				
			||||||
 | 
							table.Append(v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						table.SetHeader(hdr)
 | 
				
			||||||
 | 
						table.Render()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return b.String()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (dp *defaultPrinter) Lights(lights []lifx.Light) string {
 | 
				
			||||||
 | 
						var b strings.Builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sortLights(lights)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						table := tablewriter.NewWriter(&b)
 | 
				
			||||||
 | 
						_, rows := makeLightsTable(lights)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, v := range rows {
 | 
				
			||||||
 | 
							table.Append(v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Fprintf(&b, "total %d\n", len(lights))
 | 
				
			||||||
 | 
						table.SetAlignment(tablewriter.ALIGN_LEFT)
 | 
				
			||||||
 | 
						table.SetAutoWrapText(false)
 | 
				
			||||||
 | 
						table.SetBorder(false)
 | 
				
			||||||
 | 
						table.SetCenterSeparator("")
 | 
				
			||||||
 | 
						table.SetColumnSeparator("")
 | 
				
			||||||
 | 
						table.SetHeaderLine(false)
 | 
				
			||||||
 | 
						table.SetNoWhiteSpace(true)
 | 
				
			||||||
 | 
						table.SetRowSeparator("")
 | 
				
			||||||
 | 
						table.SetTablePadding(" ")
 | 
				
			||||||
 | 
						table.Render()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return b.String()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (tp *tablePrinter) Lights(lights []lifx.Light) string {
 | 
				
			||||||
 | 
						var b strings.Builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sortLights(lights)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						table := tablewriter.NewWriter(&b)
 | 
				
			||||||
 | 
						hdr, rows := makeLightsTable(lights)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, v := range rows {
 | 
				
			||||||
 | 
							table.Append(v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						table.SetHeader(hdr)
 | 
				
			||||||
 | 
						table.Render()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return b.String()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ColorizeIndicator(s string) string {
 | 
				
			||||||
 | 
						c := color.New(color.FgRed)
 | 
				
			||||||
 | 
						if s == "on" {
 | 
				
			||||||
 | 
							c = color.New(color.FgGreen)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.Sprint(GetConfig().Indicator)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ColorizePower(s string) string {
 | 
				
			||||||
 | 
						c := color.New(color.FgRed)
 | 
				
			||||||
 | 
						if s == "on" {
 | 
				
			||||||
 | 
							c = color.New(color.FgGreen)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.Sprint(s)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ColorizeStatus(s lifx.Status) string {
 | 
				
			||||||
 | 
						c := color.New(color.FgRed)
 | 
				
			||||||
 | 
						if s == "ok" {
 | 
				
			||||||
 | 
							c = color.New(color.FgGreen)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.Sprint(s)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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...)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func FprintfWithIndent(w io.Writer, indent int, format string, a ...interface{}) (n int, err error) {
 | 
				
			||||||
 | 
						format = fmt.Sprintf("%*s%s", indent, "", format)
 | 
				
			||||||
 | 
						return fmt.Fprintf(w, format, a...)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func makeLightsTable(lights []lifx.Light) (hdr []string, rows [][]string) {
 | 
				
			||||||
 | 
						hdr = []string{"", "ID", "Location", "Group", "Label", "Last Seen", "Power"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, l := range lights {
 | 
				
			||||||
 | 
							rows = append(rows, []string{
 | 
				
			||||||
 | 
								fmt.Sprint(ColorizeIndicator(l.Power)),
 | 
				
			||||||
 | 
								fmt.Sprint(l.Id),
 | 
				
			||||||
 | 
								fmt.Sprint(l.Location.Name),
 | 
				
			||||||
 | 
								fmt.Sprint(l.Group.Name),
 | 
				
			||||||
 | 
								fmt.Sprint(l.Label),
 | 
				
			||||||
 | 
								fmt.Sprint(l.LastSeen.Local().Format(time.RFC3339)),
 | 
				
			||||||
 | 
								fmt.Sprint(ColorizePower(l.Power)),
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func makeResultsTable(results []lifx.Result) (hdr []string, rows [][]string) {
 | 
				
			||||||
 | 
						hdr = []string{"ID", "Label", "Status"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, r := range results {
 | 
				
			||||||
 | 
							rows = append(rows, []string{
 | 
				
			||||||
 | 
								fmt.Sprint(r.Id),
 | 
				
			||||||
 | 
								fmt.Sprint(r.Label),
 | 
				
			||||||
 | 
								fmt.Sprint(ColorizeStatus(r.Status)),
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -48,23 +48,33 @@ func NewCmdSetColor() Command {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SetColorCmd(args CmdArgs) (int, error) {
 | 
					func SetColorCmd(ctx Context) (int, error) {
 | 
				
			||||||
	c := args.Client
 | 
						var p Printer
 | 
				
			||||||
	state := lifx.State{}
 | 
					 | 
				
			||||||
	selector := args.Flags.String("selector")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	power := args.Flags.String("power")
 | 
						c := ctx.Client
 | 
				
			||||||
 | 
						state := lifx.State{}
 | 
				
			||||||
 | 
						selector := ctx.Flags.String("selector")
 | 
				
			||||||
 | 
						format, err := getOutputFormatFromFlags(ctx.Flags)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if format == "" && ctx.Config.OutputFormat != "" {
 | 
				
			||||||
 | 
							format = ctx.Config.OutputFormat
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						power := ctx.Flags.String("power")
 | 
				
			||||||
	if power != "" {
 | 
						if power != "" {
 | 
				
			||||||
		state.Power = power
 | 
							state.Power = power
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	hueFlag := args.Flags.String("hue")
 | 
						hueFlag := ctx.Flags.String("hue")
 | 
				
			||||||
	saturationFlag := args.Flags.String("saturation")
 | 
						saturationFlag := ctx.Flags.String("saturation")
 | 
				
			||||||
	rgbFlag := args.Flags.String("rgb")
 | 
						rgbFlag := ctx.Flags.String("rgb")
 | 
				
			||||||
	name := args.Flags.String("name")
 | 
						name := ctx.Flags.String("name")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (hueFlag == "" || saturationFlag == "") && rgbFlag == "" && name == "" {
 | 
						if (hueFlag == "" || saturationFlag == "") && rgbFlag == "" && name == "" {
 | 
				
			||||||
		printCmdHelp(args.Name)
 | 
							printCmdHelp(ctx.Name)
 | 
				
			||||||
		return ExitFailure, nil
 | 
							return ExitFailure, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -72,12 +82,12 @@ func SetColorCmd(args CmdArgs) (int, error) {
 | 
				
			|||||||
		color := lifx.HSBKColor{}
 | 
							color := lifx.HSBKColor{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if hueFlag != "" {
 | 
							if hueFlag != "" {
 | 
				
			||||||
			hue := args.Flags.Float32("hue")
 | 
								hue := ctx.Flags.Float32("hue")
 | 
				
			||||||
			color.H = lifx.Float32Ptr(hue)
 | 
								color.H = lifx.Float32Ptr(hue)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if saturationFlag != "" {
 | 
							if saturationFlag != "" {
 | 
				
			||||||
			saturation := args.Flags.Float32("saturation")
 | 
								saturation := ctx.Flags.Float32("saturation")
 | 
				
			||||||
			color.S = lifx.Float32Ptr(saturation)
 | 
								color.S = lifx.Float32Ptr(saturation)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		state.Color = color
 | 
							state.Color = color
 | 
				
			||||||
@@ -89,7 +99,7 @@ func SetColorCmd(args CmdArgs) (int, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		state.Color = color
 | 
							state.Color = color
 | 
				
			||||||
	} else if name != "" {
 | 
						} else if name != "" {
 | 
				
			||||||
		hsb, ok := args.Config.Colors[name]
 | 
							hsb, ok := ctx.Config.Colors[name]
 | 
				
			||||||
		if !ok {
 | 
							if !ok {
 | 
				
			||||||
			return ExitFailure, fmt.Errorf("%s is not a defined color", name)
 | 
								return ExitFailure, fmt.Errorf("%s is not a defined color", name)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -100,16 +110,16 @@ func SetColorCmd(args CmdArgs) (int, error) {
 | 
				
			|||||||
		state.Color = color
 | 
							state.Color = color
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	brightnessFlag := args.Flags.String("brightness")
 | 
						brightnessFlag := ctx.Flags.String("brightness")
 | 
				
			||||||
	if brightnessFlag != "" {
 | 
						if brightnessFlag != "" {
 | 
				
			||||||
		brightness := args.Flags.Float64("brightness")
 | 
							brightness := ctx.Flags.Float64("brightness")
 | 
				
			||||||
		state.Brightness = brightness
 | 
							state.Brightness = brightness
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	duration := args.Flags.Float64("duration")
 | 
						duration := ctx.Flags.Float64("duration")
 | 
				
			||||||
	state.Duration = duration
 | 
						state.Duration = duration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fast := args.Flags.Bool("fast")
 | 
						fast := ctx.Flags.Bool("fast")
 | 
				
			||||||
	state.Fast = fast
 | 
						state.Fast = fast
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	r, err := c.SetState(selector, state)
 | 
						r, err := c.SetState(selector, state)
 | 
				
			||||||
@@ -119,7 +129,8 @@ func SetColorCmd(args CmdArgs) (int, error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !fast {
 | 
						if !fast {
 | 
				
			||||||
		PrintResults(r.Results)
 | 
							p = NewPrinter(format)
 | 
				
			||||||
 | 
							fmt.Print(p.Results(r.Results))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ExitSuccess, nil
 | 
						return ExitSuccess, nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ package lumecmd
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.kill0.net/chill9/lifx-go"
 | 
						"git.kill0.net/chill9/lifx-go"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -41,41 +42,51 @@ func NewCmdSetState() Command {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SetStateCmd(args CmdArgs) (int, error) {
 | 
					func SetStateCmd(ctx Context) (int, error) {
 | 
				
			||||||
	c := args.Client
 | 
						var p Printer
 | 
				
			||||||
	state := lifx.State{}
 | 
					 | 
				
			||||||
	selector := args.Flags.String("selector")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	power := args.Flags.String("power")
 | 
						c := ctx.Client
 | 
				
			||||||
 | 
						state := lifx.State{}
 | 
				
			||||||
 | 
						selector := ctx.Flags.String("selector")
 | 
				
			||||||
 | 
						format, err := getOutputFormatFromFlags(ctx.Flags)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if format == "" && ctx.Config.OutputFormat != "" {
 | 
				
			||||||
 | 
							format = ctx.Config.OutputFormat
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						power := ctx.Flags.String("power")
 | 
				
			||||||
	if power != "" {
 | 
						if power != "" {
 | 
				
			||||||
		state.Power = power
 | 
							state.Power = power
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	color := args.Flags.String("color")
 | 
						color := ctx.Flags.String("color")
 | 
				
			||||||
	if color != "" {
 | 
						if color != "" {
 | 
				
			||||||
		state.Color = lifx.NamedColor(color)
 | 
							state.Color = lifx.NamedColor(color)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	brightnessFlag := args.Flags.String("brightness")
 | 
						brightnessFlag := ctx.Flags.String("brightness")
 | 
				
			||||||
	if brightnessFlag != "" {
 | 
						if brightnessFlag != "" {
 | 
				
			||||||
		brightness := args.Flags.Float64("brightness")
 | 
							brightness := ctx.Flags.Float64("brightness")
 | 
				
			||||||
		state.Brightness = brightness
 | 
							state.Brightness = brightness
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	duration := args.Flags.Float64("duration")
 | 
						duration := ctx.Flags.Float64("duration")
 | 
				
			||||||
	state.Duration = duration
 | 
						state.Duration = duration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	infraredFlag := args.Flags.String("infrared")
 | 
						infraredFlag := ctx.Flags.String("infrared")
 | 
				
			||||||
	if infraredFlag != "" {
 | 
						if infraredFlag != "" {
 | 
				
			||||||
		infrared := args.Flags.Float64("infrared")
 | 
							infrared := ctx.Flags.Float64("infrared")
 | 
				
			||||||
		state.Infrared = infrared
 | 
							state.Infrared = infrared
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fast := args.Flags.Bool("fast")
 | 
						fast := ctx.Flags.Bool("fast")
 | 
				
			||||||
	state.Fast = fast
 | 
						state.Fast = fast
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if power == "" && color == "" && brightnessFlag == "" && infraredFlag == "" {
 | 
						if power == "" && color == "" && brightnessFlag == "" && infraredFlag == "" {
 | 
				
			||||||
		printCmdHelp(args.Name)
 | 
							printCmdHelp(ctx.Name)
 | 
				
			||||||
		return ExitFailure, nil
 | 
							return ExitFailure, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -85,7 +96,8 @@ func SetStateCmd(args CmdArgs) (int, error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !fast {
 | 
						if !fast {
 | 
				
			||||||
		PrintResults(r.Results)
 | 
							p = NewPrinter(format)
 | 
				
			||||||
 | 
							fmt.Print(p.Results(r.Results))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ExitSuccess, nil
 | 
						return ExitSuccess, nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ package lumecmd
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.kill0.net/chill9/lifx-go"
 | 
						"git.kill0.net/chill9/lifx-go"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -44,19 +45,29 @@ func NewCmdSetWhite() Command {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SetWhiteCmd(args CmdArgs) (int, error) {
 | 
					func SetWhiteCmd(ctx Context) (int, error) {
 | 
				
			||||||
	c := args.Client
 | 
						var p Printer
 | 
				
			||||||
	state := lifx.State{}
 | 
					 | 
				
			||||||
	selector := args.Flags.String("selector")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	power := args.Flags.String("power")
 | 
						c := ctx.Client
 | 
				
			||||||
 | 
						state := lifx.State{}
 | 
				
			||||||
 | 
						selector := ctx.Flags.String("selector")
 | 
				
			||||||
 | 
						format, err := getOutputFormatFromFlags(ctx.Flags)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if format == "" && ctx.Config.OutputFormat != "" {
 | 
				
			||||||
 | 
							format = ctx.Config.OutputFormat
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						power := ctx.Flags.String("power")
 | 
				
			||||||
	if power != "" {
 | 
						if power != "" {
 | 
				
			||||||
		state.Power = power
 | 
							state.Power = power
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	kelvinFlag := args.Flags.String("kelvin")
 | 
						kelvinFlag := ctx.Flags.String("kelvin")
 | 
				
			||||||
	if kelvinFlag != "" {
 | 
						if kelvinFlag != "" {
 | 
				
			||||||
		kelvin := args.Flags.Int16("kelvin")
 | 
							kelvin := ctx.Flags.Int16("kelvin")
 | 
				
			||||||
		color, err := lifx.NewWhite(kelvin)
 | 
							color, err := lifx.NewWhite(kelvin)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return ExitFailure, err
 | 
								return ExitFailure, err
 | 
				
			||||||
@@ -64,9 +75,9 @@ func SetWhiteCmd(args CmdArgs) (int, error) {
 | 
				
			|||||||
		state.Color = color
 | 
							state.Color = color
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	name := args.Flags.String("name")
 | 
						name := ctx.Flags.String("name")
 | 
				
			||||||
	if name != "" {
 | 
						if name != "" {
 | 
				
			||||||
		name := args.Flags.String("name")
 | 
							name := ctx.Flags.String("name")
 | 
				
			||||||
		color, err := lifx.NewWhiteString(name)
 | 
							color, err := lifx.NewWhiteString(name)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return ExitFailure, err
 | 
								return ExitFailure, err
 | 
				
			||||||
@@ -74,26 +85,26 @@ func SetWhiteCmd(args CmdArgs) (int, error) {
 | 
				
			|||||||
		state.Color = color
 | 
							state.Color = color
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	brightnessFlag := args.Flags.String("brightness")
 | 
						brightnessFlag := ctx.Flags.String("brightness")
 | 
				
			||||||
	if brightnessFlag != "" {
 | 
						if brightnessFlag != "" {
 | 
				
			||||||
		brightness := args.Flags.Float64("brightness")
 | 
							brightness := ctx.Flags.Float64("brightness")
 | 
				
			||||||
		state.Brightness = brightness
 | 
							state.Brightness = brightness
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	duration := args.Flags.Float64("duration")
 | 
						duration := ctx.Flags.Float64("duration")
 | 
				
			||||||
	state.Duration = duration
 | 
						state.Duration = duration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	infraredFlag := args.Flags.String("infrared")
 | 
						infraredFlag := ctx.Flags.String("infrared")
 | 
				
			||||||
	if infraredFlag != "" {
 | 
						if infraredFlag != "" {
 | 
				
			||||||
		infrared := args.Flags.Float64("infrared")
 | 
							infrared := ctx.Flags.Float64("infrared")
 | 
				
			||||||
		state.Infrared = infrared
 | 
							state.Infrared = infrared
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fast := args.Flags.Bool("fast")
 | 
						fast := ctx.Flags.Bool("fast")
 | 
				
			||||||
	state.Fast = fast
 | 
						state.Fast = fast
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if power == "" && kelvinFlag == "" && name == "" && brightnessFlag == "" && infraredFlag == "" {
 | 
						if power == "" && kelvinFlag == "" && name == "" && brightnessFlag == "" && infraredFlag == "" {
 | 
				
			||||||
		printCmdHelp(args.Name)
 | 
							printCmdHelp(ctx.Name)
 | 
				
			||||||
		return ExitFailure, nil
 | 
							return ExitFailure, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -103,7 +114,8 @@ func SetWhiteCmd(args CmdArgs) (int, error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !fast {
 | 
						if !fast {
 | 
				
			||||||
		PrintResults(r.Results)
 | 
							p = NewPrinter(format)
 | 
				
			||||||
 | 
							fmt.Print(p.Results(r.Results))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ExitSuccess, nil
 | 
						return ExitSuccess, nil
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										73
									
								
								cmd/show.go
									
									
									
									
									
								
							
							
						
						
									
										73
									
								
								cmd/show.go
									
									
									
									
									
								
							@@ -3,6 +3,7 @@ package lumecmd
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const Tabstop int = 2
 | 
					const Tabstop int = 2
 | 
				
			||||||
@@ -24,10 +25,12 @@ func NewCmdShow() Command {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ShowCmd(args CmdArgs) (int, error) {
 | 
					func ShowCmd(ctx Context) (int, error) {
 | 
				
			||||||
	var indent int
 | 
						var indent int
 | 
				
			||||||
	c := args.Client
 | 
						var b strings.Builder
 | 
				
			||||||
	selector := args.Flags.String("selector")
 | 
					
 | 
				
			||||||
 | 
						c := ctx.Client
 | 
				
			||||||
 | 
						selector := ctx.Flags.String("selector")
 | 
				
			||||||
	lights, err := c.ListLights(selector)
 | 
						lights, err := c.ListLights(selector)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -38,48 +41,52 @@ func ShowCmd(args CmdArgs) (int, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	for i, l := range lights {
 | 
						for i, l := range lights {
 | 
				
			||||||
		indent = 0
 | 
							indent = 0
 | 
				
			||||||
		fmt.Printf(
 | 
							fmt.Fprintf(
 | 
				
			||||||
			"Light ID: %s, %s, Power: %s\n",
 | 
								&b,
 | 
				
			||||||
 | 
								"%s Light ID: %s, %s, Power: %s\n",
 | 
				
			||||||
 | 
								ColorizeIndicator(l.Power),
 | 
				
			||||||
			l.Id,
 | 
								l.Id,
 | 
				
			||||||
			connected(l.Connected),
 | 
								connected(l.Connected),
 | 
				
			||||||
			powerColor(l.Power),
 | 
								ColorizePower(l.Power),
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
		indent += Tabstop
 | 
							indent += Tabstop + 2
 | 
				
			||||||
		PrintfWithIndent(indent, "Label: %s, ID: %s\n", l.Label, l.Id)
 | 
							FprintfWithIndent(&b, indent, "Label: %s, ID: %s\n", l.Label, l.Id)
 | 
				
			||||||
		PrintfWithIndent(indent, "UUID: %s\n", l.UUID)
 | 
							FprintfWithIndent(&b, indent, "UUID: %s\n", l.UUID)
 | 
				
			||||||
		PrintfWithIndent(indent, "Location: %s, ID: %s\n", l.Location.Name, l.Location.Id)
 | 
							FprintfWithIndent(&b, 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)
 | 
							FprintfWithIndent(&b, indent, "Group: %s, ID: %s\n", l.Group.Name, l.Group.Id)
 | 
				
			||||||
		PrintfWithIndent(indent, "Color: Hue: %.1f, Saturation: %.1f%%, Kelvin: %d\n",
 | 
							FprintfWithIndent(&b, indent, "Color: Hue: %.1f, Saturation: %.1f%%, Kelvin: %d\n",
 | 
				
			||||||
			*l.Color.H, *l.Color.S, *l.Color.K)
 | 
								*l.Color.H, *l.Color.S, *l.Color.K)
 | 
				
			||||||
		PrintfWithIndent(indent, "Brightness: %.1f%%\n", l.Brightness*100)
 | 
							FprintfWithIndent(&b, indent, "Brightness: %.1f%%\n", l.Brightness*100)
 | 
				
			||||||
		if l.Effect != "" {
 | 
							if l.Effect != "" {
 | 
				
			||||||
			PrintfWithIndent(indent, "Effect: %s\n", l.Effect)
 | 
								FprintfWithIndent(&b, indent, "Effect: %s\n", l.Effect)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		PrintfWithIndent(indent, "Product: %s\n", l.Product.Name)
 | 
							FprintfWithIndent(&b, indent, "Product: %s\n", l.Product.Name)
 | 
				
			||||||
		PrintfWithIndent(indent, "Capabilities: ")
 | 
							FprintfWithIndent(&b, indent, "Capabilities: ")
 | 
				
			||||||
		fmt.Printf("Color: %s, ", YesNo(l.Product.Capabilities.HasColor))
 | 
							fmt.Fprintf(&b, "Color: %s, ", YesNo(l.Product.Capabilities.HasColor))
 | 
				
			||||||
		fmt.Printf("Variable Color Temp: %s, ", YesNo(l.Product.Capabilities.HasVariableColorTemp))
 | 
							fmt.Fprintf(&b, "Variable Color Temp: %s, ", YesNo(l.Product.Capabilities.HasVariableColorTemp))
 | 
				
			||||||
		fmt.Printf("IR: %s, ", YesNo(l.Product.Capabilities.HasIR))
 | 
							fmt.Fprintf(&b, "IR: %s, ", YesNo(l.Product.Capabilities.HasIR))
 | 
				
			||||||
		fmt.Printf("Chain: %s, ", YesNo(l.Product.Capabilities.HasChain))
 | 
							fmt.Fprintf(&b, "Chain: %s, ", YesNo(l.Product.Capabilities.HasChain))
 | 
				
			||||||
		fmt.Printf("Multizone: %s, ", YesNo(l.Product.Capabilities.HasMultizone))
 | 
							fmt.Fprintf(&b, "Multizone: %s, ", YesNo(l.Product.Capabilities.HasMultizone))
 | 
				
			||||||
		fmt.Printf("Min Kelvin: %.1f, ", l.Product.Capabilities.MinKelvin)
 | 
							fmt.Fprintf(&b, "Min Kelvin: %.1f, ", l.Product.Capabilities.MinKelvin)
 | 
				
			||||||
		fmt.Printf("Max Kelvin: %.1f ", l.Product.Capabilities.MaxKelvin)
 | 
							fmt.Fprintf(&b, "Max Kelvin: %.1f ", l.Product.Capabilities.MaxKelvin)
 | 
				
			||||||
		fmt.Println()
 | 
							fmt.Fprintln(&b)
 | 
				
			||||||
		// List applicable selectors (most to least specific)
 | 
							// List applicable selectors (most to least specific)
 | 
				
			||||||
		PrintfWithIndent(indent, "Selectors:\n")
 | 
							FprintfWithIndent(&b, indent, "Selectors:\n")
 | 
				
			||||||
		indent += Tabstop
 | 
							indent += Tabstop
 | 
				
			||||||
		PrintfWithIndent(indent, "id:%s\n", l.Id)
 | 
							FprintfWithIndent(&b, indent, "id:%s\n", l.Id)
 | 
				
			||||||
		PrintfWithIndent(indent, "label:%s\n", l.Label)
 | 
							FprintfWithIndent(&b, indent, "label:%s\n", l.Label)
 | 
				
			||||||
		PrintfWithIndent(indent, "group_id:%s\n", l.Group.Id)
 | 
							FprintfWithIndent(&b, indent, "group_id:%s\n", l.Group.Id)
 | 
				
			||||||
		PrintfWithIndent(indent, "group:%s\n", l.Group.Name)
 | 
							FprintfWithIndent(&b, indent, "group:%s\n", l.Group.Name)
 | 
				
			||||||
		PrintfWithIndent(indent, "location_id:%s\n", l.Location.Id)
 | 
							FprintfWithIndent(&b, indent, "location_id:%s\n", l.Location.Id)
 | 
				
			||||||
		PrintfWithIndent(indent, "location:%s\n", l.Location.Name)
 | 
							FprintfWithIndent(&b, indent, "location:%s\n", l.Location.Name)
 | 
				
			||||||
		indent -= Tabstop
 | 
							indent -= Tabstop
 | 
				
			||||||
		PrintfWithIndent(indent, "Last Seen: %s (%.1fs ago)\n", l.LastSeen, l.SecondsLastSeen)
 | 
							FprintfWithIndent(&b, indent, "Last Seen: %s (%.1fs ago)\n", l.LastSeen, l.SecondsLastSeen)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if i < len(lights)-1 {
 | 
							if i < len(lights)-1 {
 | 
				
			||||||
			fmt.Println()
 | 
								fmt.Fprintln(&b)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							fmt.Print(b.String())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return ExitSuccess, nil
 | 
						return ExitSuccess, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ package lumecmd
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewCmdToggle() Command {
 | 
					func NewCmdToggle() Command {
 | 
				
			||||||
@@ -24,14 +25,28 @@ func NewCmdToggle() Command {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ToggleCmd(args CmdArgs) (int, error) {
 | 
					func ToggleCmd(ctx Context) (int, error) {
 | 
				
			||||||
	c := args.Client
 | 
						var p Printer
 | 
				
			||||||
	duration := args.Flags.Float64("duration")
 | 
					
 | 
				
			||||||
	selector := args.Flags.String("selector")
 | 
						c := ctx.Client
 | 
				
			||||||
 | 
						duration := ctx.Flags.Float64("duration")
 | 
				
			||||||
 | 
						selector := ctx.Flags.String("selector")
 | 
				
			||||||
 | 
						format, err := getOutputFormatFromFlags(ctx.Flags)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if format == "" && ctx.Config.OutputFormat != "" {
 | 
				
			||||||
 | 
							format = ctx.Config.OutputFormat
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	r, err := c.Toggle(selector, duration)
 | 
						r, err := c.Toggle(selector, duration)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return ExitFailure, err
 | 
							return ExitFailure, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	PrintResults(r.Results)
 | 
					
 | 
				
			||||||
 | 
						p = NewPrinter(format)
 | 
				
			||||||
 | 
						fmt.Print(p.Results(r.Results))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ExitSuccess, nil
 | 
						return ExitSuccess, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										117
									
								
								cmd/util.go
									
									
									
									
									
								
							
							
						
						
									
										117
									
								
								cmd/util.go
									
									
									
									
									
								
							@@ -6,116 +6,10 @@ import (
 | 
				
			|||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.kill0.net/chill9/lifx-go"
 | 
						"git.kill0.net/chill9/lifx-go"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func powerColor(s string) string {
 | 
					 | 
				
			||||||
	fs := "\033[1;31m%s\033[0m"
 | 
					 | 
				
			||||||
	if s == "on" {
 | 
					 | 
				
			||||||
		fs = "\033[1;32m%s\033[0m"
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return fmt.Sprintf(fs, s)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func statusColor(s lifx.Status) string {
 | 
					 | 
				
			||||||
	fs := "\033[1;31m%s\033[0m"
 | 
					 | 
				
			||||||
	if s == "ok" {
 | 
					 | 
				
			||||||
		fs = "\033[1;32m%s\033[0m"
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return fmt.Sprintf(fs, s)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func PrintResults(res []lifx.Result) {
 | 
					 | 
				
			||||||
	var length int
 | 
					 | 
				
			||||||
	var widths map[string]int
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	widths = make(map[string]int)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for _, r := range res {
 | 
					 | 
				
			||||||
		length = len(r.Id)
 | 
					 | 
				
			||||||
		if widths["id"] < length {
 | 
					 | 
				
			||||||
			widths["id"] = length
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		length = len(r.Label)
 | 
					 | 
				
			||||||
		if widths["label"] < length {
 | 
					 | 
				
			||||||
			widths["label"] = length
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		length = len(r.Status)
 | 
					 | 
				
			||||||
		if widths["status"] < length {
 | 
					 | 
				
			||||||
			widths["status"] = length
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	sortResults(res)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for _, r := range res {
 | 
					 | 
				
			||||||
		fmt.Printf("%*s %*s %*s\n",
 | 
					 | 
				
			||||||
			widths["id"], r.Id,
 | 
					 | 
				
			||||||
			widths["label"], r.Label,
 | 
					 | 
				
			||||||
			widths["status"], statusColor(r.Status))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func PrintLights(lights []lifx.Light) {
 | 
					 | 
				
			||||||
	var length int
 | 
					 | 
				
			||||||
	var widths map[string]int
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	widths = make(map[string]int)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for _, l := range lights {
 | 
					 | 
				
			||||||
		length = len(l.Id)
 | 
					 | 
				
			||||||
		if widths["id"] < length {
 | 
					 | 
				
			||||||
			widths["id"] = length
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		length = len(l.Location.Name)
 | 
					 | 
				
			||||||
		if widths["location"] < length {
 | 
					 | 
				
			||||||
			widths["location"] = length
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		length = len(l.Group.Name)
 | 
					 | 
				
			||||||
		if widths["group"] < length {
 | 
					 | 
				
			||||||
			widths["group"] = length
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		length = len(l.Label)
 | 
					 | 
				
			||||||
		if widths["label"] < length {
 | 
					 | 
				
			||||||
			widths["label"] = length
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		length = len(l.LastSeen.Local().Format(time.RFC3339))
 | 
					 | 
				
			||||||
		if widths["last_seen"] < length {
 | 
					 | 
				
			||||||
			widths["last_seen"] = length
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		length = len(l.Power)
 | 
					 | 
				
			||||||
		if widths["power"] < length {
 | 
					 | 
				
			||||||
			widths["power"] = length
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	sortLights(lights)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fmt.Printf("total %d\n", len(lights))
 | 
					 | 
				
			||||||
	for _, l := range lights {
 | 
					 | 
				
			||||||
		fmt.Printf(
 | 
					 | 
				
			||||||
			"%*s %*s %*s %*s %*s %-*s\n",
 | 
					 | 
				
			||||||
			widths["id"], l.Id,
 | 
					 | 
				
			||||||
			widths["loction"], l.Location.Name,
 | 
					 | 
				
			||||||
			widths["group"], l.Group.Name,
 | 
					 | 
				
			||||||
			widths["label"], l.Label,
 | 
					 | 
				
			||||||
			widths["last_seen"], l.LastSeen.Local().Format(time.RFC3339),
 | 
					 | 
				
			||||||
			widths["power"], powerColor(l.Power),
 | 
					 | 
				
			||||||
		)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func parseRGB(s string) (lifx.RGBColor, error) {
 | 
					func parseRGB(s string) (lifx.RGBColor, error) {
 | 
				
			||||||
	var c lifx.RGBColor
 | 
						var c lifx.RGBColor
 | 
				
			||||||
	rgb := strings.SplitN(s, ",", 3)
 | 
						rgb := strings.SplitN(s, ",", 3)
 | 
				
			||||||
@@ -167,11 +61,8 @@ func YesNo(v bool) string {
 | 
				
			|||||||
	return "no"
 | 
						return "no"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func PrintWithIndent(indent int, s string) {
 | 
					func Debugf(format string, a ...interface{}) {
 | 
				
			||||||
	fmt.Printf("%*s%s", indent, "", s)
 | 
						if GetConfig().Debug {
 | 
				
			||||||
}
 | 
							fmt.Printf(format, a...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
func PrintfWithIndent(indent int, format string, a ...interface{}) (n int, err error) {
 | 
					 | 
				
			||||||
	format = fmt.Sprintf("%*s%s", indent, "", format)
 | 
					 | 
				
			||||||
	return fmt.Printf(format, a...)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										51
									
								
								cmd/validate.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								cmd/validate.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
				
			|||||||
 | 
					package lumecmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"flag"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.kill0.net/chill9/lifx-go"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewCmdValidate() Command {
 | 
				
			||||||
 | 
						return Command{
 | 
				
			||||||
 | 
							Name: "validate",
 | 
				
			||||||
 | 
							Func: ValidateCmd,
 | 
				
			||||||
 | 
							Flags: func() *flag.FlagSet {
 | 
				
			||||||
 | 
								fs := flag.NewFlagSet("validate", flag.ExitOnError)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return fs
 | 
				
			||||||
 | 
							}(),
 | 
				
			||||||
 | 
							Use:   "<command>",
 | 
				
			||||||
 | 
							Short: "Validate a color string",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ValidateCmd(ctx Context) (int, error) {
 | 
				
			||||||
 | 
						var b strings.Builder
 | 
				
			||||||
 | 
						c := ctx.Client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(ctx.Args) != 1 {
 | 
				
			||||||
 | 
							fmt.Print(printCmdHelp(ctx.Name))
 | 
				
			||||||
 | 
							return ExitFailure, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						color := lifx.NamedColor(ctx.Args[0])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						i, err := c.ValidateColor(color)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ExitFailure, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if validColor, ok := i.(*lifx.HSBKColor); ok {
 | 
				
			||||||
 | 
							fmt.Fprintln(&b, validColor)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return ExitFailure, errors.New("go type %T but wanted *HSBKColor")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Print(b.String())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return ExitSuccess, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -3,6 +3,7 @@ package lumecmd
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewCmdVersion() Command {
 | 
					func NewCmdVersion() Command {
 | 
				
			||||||
@@ -15,12 +16,23 @@ func NewCmdVersion() Command {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func VersionCmd(args CmdArgs) (int, error) {
 | 
					func VersionCmd(ctx Context) (int, error) {
 | 
				
			||||||
	fmt.Printf("lume %s\n", Version)
 | 
						var b strings.Builder
 | 
				
			||||||
	fmt.Printf("  os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
 | 
					
 | 
				
			||||||
	fmt.Printf("  go version: %s\n", runtime.Version())
 | 
						fmt.Fprintf(&b, "lume, version %s\n", Version)
 | 
				
			||||||
	if BuildDate != "" {
 | 
					
 | 
				
			||||||
		fmt.Printf("  build date: %s\n", BuildDate)
 | 
						if GitCommit != "" {
 | 
				
			||||||
 | 
							fmt.Fprintf(&b, "  revision:   %s\n", GitCommit)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if BuildDate != "" {
 | 
				
			||||||
 | 
							fmt.Fprintf(&b, "  build date: %s\n", BuildDate)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Fprintf(&b, "  go version: %s\n", runtime.Version())
 | 
				
			||||||
 | 
						fmt.Fprintf(&b, "  platform:   %s/%s\n", runtime.GOOS, runtime.GOARCH)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Print(b.String())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ExitSuccess, nil
 | 
						return ExitSuccess, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										8
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								go.mod
									
									
									
									
									
								
							@@ -3,7 +3,11 @@ module git.kill0.net/chill9/lume
 | 
				
			|||||||
go 1.15
 | 
					go 1.15
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	git.kill0.net/chill9/lifx-go v0.0.0-20210215004437-f86c28b0a5ef
 | 
						git.kill0.net/chill9/lifx-go v0.0.0-20210418161634-4c1678b62c73
 | 
				
			||||||
	github.com/BurntSushi/toml v0.3.1
 | 
						github.com/BurntSushi/toml v0.3.1
 | 
				
			||||||
	golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061
 | 
						github.com/fatih/color v1.10.0
 | 
				
			||||||
 | 
						github.com/mattn/go-runewidth v0.0.10 // indirect
 | 
				
			||||||
 | 
						github.com/olekukonko/tablewriter v0.0.5
 | 
				
			||||||
 | 
						github.com/rivo/uniseg v0.2.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/sys v0.0.0-20210326220804-49726bf1d181
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										27
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								go.sum
									
									
									
									
									
								
							@@ -1,6 +1,33 @@
 | 
				
			|||||||
git.kill0.net/chill9/lifx-go v0.0.0-20210215004437-f86c28b0a5ef h1:8yyXAk+qiRvrowTeHHAOBZqGXXCr8SxWFydez61ZGp8=
 | 
					git.kill0.net/chill9/lifx-go v0.0.0-20210215004437-f86c28b0a5ef h1:8yyXAk+qiRvrowTeHHAOBZqGXXCr8SxWFydez61ZGp8=
 | 
				
			||||||
git.kill0.net/chill9/lifx-go v0.0.0-20210215004437-f86c28b0a5ef/go.mod h1:ZFKIcwdJ4Nqlrkn/eUHbeLt0NVhFsfxBREkVoA+jzUc=
 | 
					git.kill0.net/chill9/lifx-go v0.0.0-20210215004437-f86c28b0a5ef/go.mod h1:ZFKIcwdJ4Nqlrkn/eUHbeLt0NVhFsfxBREkVoA+jzUc=
 | 
				
			||||||
 | 
					git.kill0.net/chill9/lifx-go v0.0.0-20210323044657-dbe1c40e1621 h1:koWq2W08HjmvsNm4D8kD0OjMZKCJ/3681P9XFMTj77I=
 | 
				
			||||||
 | 
					git.kill0.net/chill9/lifx-go v0.0.0-20210323044657-dbe1c40e1621/go.mod h1:jInpjEqTBhrFpQKk7zPIWISvgjjfS2djXeKB3yB/8dY=
 | 
				
			||||||
 | 
					git.kill0.net/chill9/lifx-go v0.0.0-20210329222320-2107a0586447 h1:tN+zR5aszesrZRrhS3uOqAIWLcADCIH7GFJ6SOQS9r0=
 | 
				
			||||||
 | 
					git.kill0.net/chill9/lifx-go v0.0.0-20210329222320-2107a0586447/go.mod h1:jInpjEqTBhrFpQKk7zPIWISvgjjfS2djXeKB3yB/8dY=
 | 
				
			||||||
 | 
					git.kill0.net/chill9/lifx-go v0.0.0-20210418161634-4c1678b62c73 h1:fteCAelwAcfam2Q8eeJFyK4+sXGOpR6Me5YMKBi+MYY=
 | 
				
			||||||
 | 
					git.kill0.net/chill9/lifx-go v0.0.0-20210418161634-4c1678b62c73/go.mod h1:jInpjEqTBhrFpQKk7zPIWISvgjjfS2djXeKB3yB/8dY=
 | 
				
			||||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
 | 
					github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
 | 
				
			||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 | 
					github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 | 
				
			||||||
 | 
					github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
 | 
				
			||||||
 | 
					github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
 | 
				
			||||||
 | 
					github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
 | 
				
			||||||
 | 
					github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
 | 
				
			||||||
 | 
					github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
 | 
				
			||||||
 | 
					github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
 | 
				
			||||||
 | 
					github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
 | 
				
			||||||
 | 
					github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
 | 
				
			||||||
 | 
					github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
 | 
				
			||||||
 | 
					github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
 | 
				
			||||||
 | 
					github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
 | 
				
			||||||
 | 
					github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
 | 
				
			||||||
 | 
					github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
 | 
				
			||||||
 | 
					github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
 | 
				
			||||||
 | 
					github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061 h1:DQmQoKxQWtyybCtX/3dIuDBcAhFszqq8YiNeS6sNu1c=
 | 
					golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061 h1:DQmQoKxQWtyybCtX/3dIuDBcAhFszqq8YiNeS6sNu1c=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 h1:EZ2mChiOa8udjfp6rRmswTbtZN/QzUQp4ptM4rnjHvc=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20210326220804-49726bf1d181 h1:64ChN/hjER/taL4YJuA+gpLfIMT+/NFherRZixbxOhg=
 | 
				
			||||||
 | 
					golang.org/x/sys v0.0.0-20210326220804-49726bf1d181/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										186
									
								
								lume.1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										186
									
								
								lume.1
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,186 @@
 | 
				
			|||||||
 | 
					.Dd $Mdocdate$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.Dt lume \&1 "User Commands"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.Sh NAME
 | 
				
			||||||
 | 
					.Nm lume
 | 
				
			||||||
 | 
					.Nd CLI tool for the LIFX HTTP API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.Sh SYNOPSIS
 | 
				
			||||||
 | 
					.Nm lume
 | 
				
			||||||
 | 
					.Ar COMMAND
 | 
				
			||||||
 | 
					.Op Ar OPTIONS ...
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.Sh COMMANDS
 | 
				
			||||||
 | 
					.Bl -tag -width Ds
 | 
				
			||||||
 | 
					.It Xo Ic breathe
 | 
				
			||||||
 | 
					.Op Fl s Ar selector | Fl Fl selector Ns = Ns Ar selector
 | 
				
			||||||
 | 
					.Fl c | Fl Fl color
 | 
				
			||||||
 | 
					.Op Fl Fl from-color Ns = Ns Ar color
 | 
				
			||||||
 | 
					.Op Fl Fl cycles Ns = Ns Ar cycles
 | 
				
			||||||
 | 
					.Op Fl Fl peak Ns = Ns Ar peak
 | 
				
			||||||
 | 
					.Op Fl Fl period Ns = Ns Ar period
 | 
				
			||||||
 | 
					.Op Fl Fl persist
 | 
				
			||||||
 | 
					.Op Fl Fl power-on
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					.It Xo Ic help
 | 
				
			||||||
 | 
					.Op Ar COMMAND
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					Print the help message. If a command is specified, then show the subcommand's help message.
 | 
				
			||||||
 | 
					.It Xo Ic ls
 | 
				
			||||||
 | 
					.Op Fl s Ar selector | Fl Fl selector Ns = Ns Ar selector
 | 
				
			||||||
 | 
					.Op Fl Fl simple | Fl Fl table
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					List the lights and their basic state
 | 
				
			||||||
 | 
					.It Xo Ic poweroff
 | 
				
			||||||
 | 
					.Op Fl s Ar selector | Fl Fl selector Ns = Ns Ar selector
 | 
				
			||||||
 | 
					.Op Fl Fl simple | Fl Fl table
 | 
				
			||||||
 | 
					.Op Fl d | Fl Fl duration
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					Power off lights
 | 
				
			||||||
 | 
					.It Xo Ic poweron
 | 
				
			||||||
 | 
					.Op Fl s Ar selector | Fl Fl selector Ns = Ns Ar selector
 | 
				
			||||||
 | 
					.Op Fl Fl simple | Fl Fl table
 | 
				
			||||||
 | 
					.Op Fl d | Fl Fl duration
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					Power off lights
 | 
				
			||||||
 | 
					.It Xo Ic set-color
 | 
				
			||||||
 | 
					.Op Fl b Ar brightness | Fl Fl brightness Ns = Ns Ar brightness
 | 
				
			||||||
 | 
					.Op Fl d | Fl Fl duration
 | 
				
			||||||
 | 
					.Op Fl f Ar fast | Fl Fl fast Ns = Ns Ar fast
 | 
				
			||||||
 | 
					.Op Fl H Ar hue | Fl Fl hue Ns = Ns Ar hue
 | 
				
			||||||
 | 
					.Op Fl n Ar name | Fl Fl name Ns = Ns Ar name
 | 
				
			||||||
 | 
					.Op Fl p Ar power | Fl Fl power Ns = Ns Ar power
 | 
				
			||||||
 | 
					.Op Fl r Ar rgb | Fl Fl rgb Ns = Ns Ar rgb
 | 
				
			||||||
 | 
					.Op Fl S Ar saturation | Fl Fl saturation Ns = Ns Ar saturation
 | 
				
			||||||
 | 
					.Op Fl s Ar selector | Fl Fl selector Ns = Ns Ar selector
 | 
				
			||||||
 | 
					.Op Fl Fl simple | Fl Fl table
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					Set light color
 | 
				
			||||||
 | 
					.It Xo Ic set-state
 | 
				
			||||||
 | 
					.Op Fl b Ar brightness | Fl Fl brightness Ns = Ns Ar brightness
 | 
				
			||||||
 | 
					.Op Fl c | Fl Fl color
 | 
				
			||||||
 | 
					.Op Fl d | Fl Fl duration
 | 
				
			||||||
 | 
					.Op Fl f Ar fast | Fl Fl fast Ns = Ns Ar fast
 | 
				
			||||||
 | 
					.Op Fl i Ar infrared | Fl Fl infrared Ns = Ns Ar infrared
 | 
				
			||||||
 | 
					.Op Fl p Ar power | Fl Fl power Ns = Ns Ar power
 | 
				
			||||||
 | 
					.Op Fl s Ar selector | Fl Fl selector Ns = Ns Ar selector
 | 
				
			||||||
 | 
					.Op Fl Fl simple | Fl Fl table
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					Set light properties
 | 
				
			||||||
 | 
					.It Xo Ic set-white
 | 
				
			||||||
 | 
					.Op Fl b Ar brightness | Fl Fl brightness Ns = Ns Ar brightness
 | 
				
			||||||
 | 
					.Op Fl d | Fl Fl duration
 | 
				
			||||||
 | 
					.Op Fl f Ar fast | Fl Fl fast Ns = Ns Ar fast
 | 
				
			||||||
 | 
					.Op Fl i Ar infrared | Fl Fl infrared Ns = Ns Ar infrared
 | 
				
			||||||
 | 
					.Op Fl k Ar kelvin | Fl Fl kelvin Ns = Ns Ar kelvin
 | 
				
			||||||
 | 
					.Op Fl n Ar name | Fl Fl name Ns = Ns Ar name
 | 
				
			||||||
 | 
					.Op Fl p Ar power | Fl Fl power Ns = Ns Ar power
 | 
				
			||||||
 | 
					.Op Fl s Ar selector | Fl Fl selector Ns = Ns Ar selector
 | 
				
			||||||
 | 
					.Op Fl Fl simple | Fl Fl table
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					Set light white levels
 | 
				
			||||||
 | 
					.It Xo Ic show
 | 
				
			||||||
 | 
					.Op Fl s Ar selector | Fl Fl selector Ns = Ns Ar selector
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					Show extended details about the lights
 | 
				
			||||||
 | 
					.It Xo Ic toggle
 | 
				
			||||||
 | 
					.Op Fl d | Fl Fl duration
 | 
				
			||||||
 | 
					.Op Fl s Ar selector | Fl Fl selector Ns = Ns Ar selector
 | 
				
			||||||
 | 
					.Op Fl Fl simple | Fl Fl table
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					Toggle the power
 | 
				
			||||||
 | 
					.It Xo Ic validate
 | 
				
			||||||
 | 
					.Ar color_string
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					Validate a color string
 | 
				
			||||||
 | 
					.It Xo Ic version
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
 | 
					Print the version
 | 
				
			||||||
 | 
					.El
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.Sh OPTIONS 
 | 
				
			||||||
 | 
					.Bl -tag -width Ds
 | 
				
			||||||
 | 
					.It Fl b , Fl Fl brightness Ns = Ns Ar brightness
 | 
				
			||||||
 | 
					The brightness level from 0.0 to 1.0. Overrides any brightness set in color (if any)
 | 
				
			||||||
 | 
					.It Fl c , Fl Fl color Ns = Ns Ar color
 | 
				
			||||||
 | 
					This color to use for the action.
 | 
				
			||||||
 | 
					.Pp
 | 
				
			||||||
 | 
					When used with the
 | 
				
			||||||
 | 
					.Nm breathe
 | 
				
			||||||
 | 
					effect, this
 | 
				
			||||||
 | 
					is the "to" color.
 | 
				
			||||||
 | 
					.It Fl Fl cycles Ns = Ns Ar cycles
 | 
				
			||||||
 | 
					The number of times to repeat the effect. Defaults to 1.0 cycle.
 | 
				
			||||||
 | 
					.It Fl d , Fl Fl duration Ns = Ns Ar duration
 | 
				
			||||||
 | 
					The time in seconds to spend performing the action. Range: 0.0 – 3155760000.0 (100 years).
 | 
				
			||||||
 | 
					.It Fl f , Fl Fl fast
 | 
				
			||||||
 | 
					Execute the action fast without any state checks or waiting for the result from the HTTP API
 | 
				
			||||||
 | 
					.It Fl Fl from-color Ns = Ns Ar color
 | 
				
			||||||
 | 
					The color to start the
 | 
				
			||||||
 | 
					.Nm breathe
 | 
				
			||||||
 | 
					effect from. If this parameter is omitted
 | 
				
			||||||
 | 
					then the color the bulb is currently set to is used instead.
 | 
				
			||||||
 | 
					.It Fl H , Fl Fl hue Ns = Ns Ar hue
 | 
				
			||||||
 | 
					Sets the hue. Range 0 - 360.
 | 
				
			||||||
 | 
					.It Fl i , Fl Fl infrared Ns = Ns Ar infrared
 | 
				
			||||||
 | 
					Sets the maximum  brightness of the infrared channel from 0.0 to 1.0.
 | 
				
			||||||
 | 
					.It Fl k , Fl Fl kelvin Ns = Ns Ar kelvin
 | 
				
			||||||
 | 
					Set the kelvin value. The saturation is automatically set to 0.
 | 
				
			||||||
 | 
					.It Fl n , Fl Fl name Ns = Ns Ar name
 | 
				
			||||||
 | 
					Set the color using a named color from
 | 
				
			||||||
 | 
					.Pa lumerc
 | 
				
			||||||
 | 
					.It Fl Fl peak Ns = Ns Ar peak
 | 
				
			||||||
 | 
					Defines where in a period the target color is at its maximum. Minimum 0.0,
 | 
				
			||||||
 | 
					maximum 1.0. Defaults to 0.5.
 | 
				
			||||||
 | 
					.It Fl Fl period Ns = Ns Ar period
 | 
				
			||||||
 | 
					The time in seconds for one cycle of the
 | 
				
			||||||
 | 
					.Nm breathe
 | 
				
			||||||
 | 
					effect. Defaults to 1.0
 | 
				
			||||||
 | 
					second.
 | 
				
			||||||
 | 
					.It Fl Fl persist
 | 
				
			||||||
 | 
					If false set the light back to its previous value when effect ends, if true
 | 
				
			||||||
 | 
					leave the last effect color.
 | 
				
			||||||
 | 
					.It Fl p , Fl Fl power Ns = Ns Ar [ on | off ]
 | 
				
			||||||
 | 
					Set the power state
 | 
				
			||||||
 | 
					.It Fl Fl power-on
 | 
				
			||||||
 | 
					If true, turn the bulb on if it is not already on.
 | 
				
			||||||
 | 
					.It Fl r , Fl Fl rgb Ns = Ns Ar R,G,B
 | 
				
			||||||
 | 
					Set the color via a comma delimited R,G,B string. Values range from 0 - 255.
 | 
				
			||||||
 | 
					.It Fl S , Fl Fl saturation Ns = Ns Ar saturation
 | 
				
			||||||
 | 
					Set the saturation. Range 0.0 - 1.0.
 | 
				
			||||||
 | 
					.It Fl s , Fl Fl selector Ns = Ns Ar selector
 | 
				
			||||||
 | 
					The selector is used to group lights together belonging in the same account
 | 
				
			||||||
 | 
					.Pp
 | 
				
			||||||
 | 
					Selectors can be in the following format: all, label:[value], id:[value], group_id:[value], group:[value], location_id:[value], location:[value], scene_id:[value]
 | 
				
			||||||
 | 
					.Pp
 | 
				
			||||||
 | 
					The default selector is "all"
 | 
				
			||||||
 | 
					.Sh FILES
 | 
				
			||||||
 | 
					.Bl -tag -width "~/.config/lume/lume.conf" -compact
 | 
				
			||||||
 | 
					.It Pa ~/.lumerc
 | 
				
			||||||
 | 
					Default
 | 
				
			||||||
 | 
					.Nm
 | 
				
			||||||
 | 
					configuration file
 | 
				
			||||||
 | 
					.It Pa ~/.config/lume/lume.conf
 | 
				
			||||||
 | 
					XDG config home
 | 
				
			||||||
 | 
					.Nm
 | 
				
			||||||
 | 
					configuration file
 | 
				
			||||||
 | 
					.Sh EXAMPLES
 | 
				
			||||||
 | 
					Sample
 | 
				
			||||||
 | 
					.Pa lumerc
 | 
				
			||||||
 | 
					file:
 | 
				
			||||||
 | 
					.Bd -literal -offset indent
 | 
				
			||||||
 | 
					access_token = "token"
 | 
				
			||||||
 | 
					# indicator = "●"
 | 
				
			||||||
 | 
					# output_format = "table"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[colors]
 | 
				
			||||||
 | 
					purple_candy = [ 280.0, 0.29, 0.71 ]
 | 
				
			||||||
 | 
					wasabi = [ 120.0, 1.0, 0.7 ]
 | 
				
			||||||
 | 
					honeydew = [ 120.0, 1.0, 0.97 ]
 | 
				
			||||||
 | 
					green_mist = [ 92.0, 0.72, 0.75 ]
 | 
				
			||||||
 | 
					pea = [ 90.0, 0.42, 0.47 ]
 | 
				
			||||||
 | 
					cat_eye = [ 76.0, 0.74, 0.61 ]
 | 
				
			||||||
 | 
					seagreen = [ 160.0, 1.0, 0.50 ]
 | 
				
			||||||
 | 
					blue_mist = [ 202.0, 0.97, 0.75 ]
 | 
				
			||||||
 | 
					.Ed
 | 
				
			||||||
							
								
								
									
										12
									
								
								lume.code-workspace
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								lume.code-workspace
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
						"folders": [
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"path": "."
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"name": "lifx-go",
 | 
				
			||||||
 | 
								"path": "..\\lifx-go"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						"settings": {}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										5
									
								
								packaging/debian/changelog
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								packaging/debian/changelog
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					lume (__VERSION__-__REVISION__) unstable; urgency=medium
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  * Package generated with make deb
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 -- Ryan Cavicchioni <ryan@cavi.cc>  __DATE__
 | 
				
			||||||
							
								
								
									
										14
									
								
								packaging/debian/control
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								packaging/debian/control
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					Source: lume
 | 
				
			||||||
 | 
					Section: unknown
 | 
				
			||||||
 | 
					Priority: optional
 | 
				
			||||||
 | 
					Maintainer: Ryan Cavicchioni <ryan@cavi.cc>
 | 
				
			||||||
 | 
					Build-Depends: debhelper (>= 10)
 | 
				
			||||||
 | 
					Standards-Version: 4.1.2
 | 
				
			||||||
 | 
					Homepage: https://git.kill0.net/chill9/lume
 | 
				
			||||||
 | 
					Vcs-Git: https://git.kill0.net/chill9/lume.git
 | 
				
			||||||
 | 
					Vcs-Browser: https://git.kill0.net/chill9/lume.git
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Package: lume
 | 
				
			||||||
 | 
					Architecture: any
 | 
				
			||||||
 | 
					Depends: ${shlibs:Depends}, ${misc:Depends}
 | 
				
			||||||
 | 
					Description: A CLI tool for the LIFX HTTP API
 | 
				
			||||||
							
								
								
									
										28
									
								
								packaging/debian/copyright
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								packaging/debian/copyright
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
 | 
				
			||||||
 | 
					Upstream-Name: lume
 | 
				
			||||||
 | 
					Source: https://git.kill0.net/chill9/lume
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Files: *
 | 
				
			||||||
 | 
					Copyright: 2021 Ryan Cavicchioni <ryan@cavi.cc>
 | 
				
			||||||
 | 
					License: MPL-2.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					License: MPL-2.0
 | 
				
			||||||
 | 
					 Licensed under the Mozilla Public License License, Version 2.0 (the "License");
 | 
				
			||||||
 | 
					 you may not use this file except in compliance with the License.  You may
 | 
				
			||||||
 | 
					 obtain a copy of the License at
 | 
				
			||||||
 | 
					 .
 | 
				
			||||||
 | 
					 https://www.mozilla.org/en-US/MPL/2.0/
 | 
				
			||||||
 | 
					 .
 | 
				
			||||||
 | 
					 Unless required by applicable law or agreed to in writing, software
 | 
				
			||||||
 | 
					 distributed under the License is distributed on an "AS IS" BASIS,
 | 
				
			||||||
 | 
					 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
				
			||||||
 | 
					 See the License for the specific language governing permissions and
 | 
				
			||||||
 | 
					 limitations under the License.
 | 
				
			||||||
 | 
					 .
 | 
				
			||||||
 | 
					 On Debian systems, the complete text of the Mozilla Public License version 2.0
 | 
				
			||||||
 | 
					 license can be found in "/usr/share/common-licenses/MPL-2.0".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Please also look if there are files or directories which have a
 | 
				
			||||||
 | 
					# different copyright/license attached and list them here.
 | 
				
			||||||
 | 
					# Please avoid picking licenses with terms that are more restrictive than the
 | 
				
			||||||
 | 
					# packaged work, as it may make Debian's contributions unacceptable upstream.
 | 
				
			||||||
							
								
								
									
										1
									
								
								packaging/debian/lume.manpages
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								packaging/debian/lume.manpages
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					lume.1
 | 
				
			||||||
							
								
								
									
										19
									
								
								packaging/debian/rules
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										19
									
								
								packaging/debian/rules
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/make -f
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DISTRIBUTION = $(shell lsb_release -sr)
 | 
				
			||||||
 | 
					VERSION = __VERSION__
 | 
				
			||||||
 | 
					REVISION = __REVISION__
 | 
				
			||||||
 | 
					PACKAGEVERSION = $(VERSION)-$(REVISION)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%:
 | 
				
			||||||
 | 
						dh $@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					override_dh_auto_clean:
 | 
				
			||||||
 | 
					override_dh_auto_test:
 | 
				
			||||||
 | 
					override_dh_auto_build:
 | 
				
			||||||
 | 
						make
 | 
				
			||||||
 | 
					override_dh_auto_install:
 | 
				
			||||||
 | 
						make install DESTDIR=debian/lume
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					override_dh_gencontrol:
 | 
				
			||||||
 | 
						dh_gencontrol -- -v$(PACKAGEVERSION)
 | 
				
			||||||
							
								
								
									
										33
									
								
								packaging/rpm/lume.spec
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								packaging/rpm/lume.spec
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					Name:           lume
 | 
				
			||||||
 | 
					Version:        __VERSION__
 | 
				
			||||||
 | 
					Release:        __REVISION__%{?dist}
 | 
				
			||||||
 | 
					Summary:        A CLI tool for the LIFX HTTP API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					License:        MPL
 | 
				
			||||||
 | 
					URL:            https://git.kill0.net/chill9/lume
 | 
				
			||||||
 | 
					Source:         %{name}-%{version}.tar.xz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%global debug_package %{nil}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%description
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%prep
 | 
				
			||||||
 | 
					%setup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%build
 | 
				
			||||||
 | 
					%make_build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%install
 | 
				
			||||||
 | 
					%make_install DESTDIR=%{buildroot}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%files
 | 
				
			||||||
 | 
					%{_bindir}/lume
 | 
				
			||||||
 | 
					%license LICENSE
 | 
				
			||||||
 | 
					/usr/share/lume/lumerc
 | 
				
			||||||
 | 
					%doc %{_mandir}/man1/lume.1.*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%changelog
 | 
				
			||||||
 | 
					* __DATE__ Ryan Cavicchioni <ryan@cavi.cc>
 | 
				
			||||||
 | 
					- lume __VERSION__
 | 
				
			||||||
		Reference in New Issue
	
	Block a user