Compare commits
18 Commits
e66f6358a9
...
cee0af195e
Author | SHA1 | Date | |
---|---|---|---|
cee0af195e | |||
01a0601652 | |||
ffe2c08a35 | |||
5b1bdefacd | |||
d38a5df36f | |||
55dd8d743d | |||
7e6249bc3c | |||
adbda33078 | |||
693ac6e677 | |||
953b1009d3 | |||
11053571d5 | |||
86720c72f9 | |||
0df1524976 | |||
965b1b4339 | |||
a9936a0f1b | |||
c229df8506 | |||
9c92d7945d | |||
a4c305c2e9 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -21,3 +21,6 @@
|
||||
.vscode/configurationCache.log
|
||||
.vscode/dryrun.log
|
||||
.vscode/targets.log
|
||||
|
||||
# packaging
|
||||
/build
|
||||
|
76
Makefile
76
Makefile
@ -1,29 +1,95 @@
|
||||
V ?= 0
|
||||
Q = $(if $(filter 1, $V),, @)
|
||||
BINDIR=$(CURDIR)/bin
|
||||
PREFIX=/usr
|
||||
DESTDIR=bin
|
||||
BUILDDIR=$(CURDIR)/build
|
||||
|
||||
BIN_DIR=./bin
|
||||
DEBBUILDDIR=$(BUILDDIR)/deb
|
||||
DEBTMPLDIR=$(CURDIR)/packaging/debian
|
||||
DEBDATE=$(shell date -R)
|
||||
DEBORIGSRC=lume_$(DEBVERSION).orig.tar.xz
|
||||
DEBORIGSRCDIR=lume-$(DEBVERSION)
|
||||
|
||||
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)
|
||||
|
||||
ifeq ($(OS), Windows_NT)
|
||||
EXE=$(BIN_DIR)/lume.exe
|
||||
EXE=$(BINDIR)/lume.exe
|
||||
RM=del /f /q
|
||||
BUILD_DATE=$(shell powershell Get-Date -Format "yyyy-MM-ddThh:mm:sszzz")
|
||||
else
|
||||
EXE=$(BIN_DIR)/lume
|
||||
EXE=$(BINDIR)/lume
|
||||
RM=rm -f
|
||||
BUILD_DATE=$(shell date --iso-8601=seconds)
|
||||
endif
|
||||
|
||||
LUME_VERSION ?= $(shell git describe --tags --always)
|
||||
GIT_COMMIT := $(shell git rev-parse --short HEAD)
|
||||
LDFLAGS := $(LDFLAGS) \
|
||||
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.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
|
||||
build:
|
||||
$(Q) go build -o $(EXE) -ldflags="$(LDFLAGS)" ./cmd/lume
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
clean: deb-clean rpm-clean
|
||||
$(Q) $(RM) $(EXE)
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
$(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:
|
||||
$(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) sed -e 's/__VERSION__/$(DEBVERSION)/g' $(DEBTMPLDIR)/rules > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/rules
|
||||
$(Q) sed -e 's/__VERSION__/$(DEBVERSION)/g' -e 's/__DATE__/$(DEBDATE)/g' $(DEBTMPLDIR)/changelog > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/changelog
|
||||
$(Q) echo 9 > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/compat
|
||||
$(Q) cp $(DEBTMPLDIR)/control $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/control
|
||||
$(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:
|
||||
$(Q) mkdir -p $(RPMBUILDDIR)/SPECS
|
||||
$(Q) mkdir -p $(RPMBUILDDIR)/SOURCES
|
||||
$(Q) sed -e 's/__VERSION__/$(RPMVERSION)/g' -e 's/__DATE__/$(RPMDATE)/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
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
|
||||
const lumercFile string = ".lumerc"
|
||||
const lumeConfigFile string = "lume.conf"
|
||||
const defaultPowerIndicator rune = '●'
|
||||
|
||||
type Config struct {
|
||||
AccessToken string `toml:"access_token"`
|
||||
@ -19,6 +20,7 @@ type Config struct {
|
||||
Colors map[string][]float32 `toml:"colors"`
|
||||
userAgent string
|
||||
Debug bool `toml:"debug"`
|
||||
Indicator string `toml:"indicator"`
|
||||
}
|
||||
|
||||
var (
|
||||
@ -33,6 +35,7 @@ func NewConfig() *Config {
|
||||
c.userAgent = initUserAgent()
|
||||
c.Debug = false
|
||||
c.OutputFormat = "simple"
|
||||
c.Indicator = string(defaultPowerIndicator)
|
||||
return c
|
||||
}
|
||||
|
||||
@ -48,6 +51,10 @@ func (c *Config) Validate() error {
|
||||
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
|
||||
}
|
||||
@ -87,8 +94,6 @@ func LoadConfig(s string) (*Config, error) {
|
||||
var err error
|
||||
var c *Config = GetConfig()
|
||||
|
||||
*c = DefaultConfig
|
||||
|
||||
if _, err := toml.Decode(s, &c); err != nil {
|
||||
err = fmt.Errorf("fatal: failed to parse; %w", err)
|
||||
}
|
||||
@ -101,8 +106,6 @@ func LoadConfigFile(configPath string) (*Config, error) {
|
||||
|
||||
var c *Config = GetConfig()
|
||||
|
||||
*c = DefaultConfig
|
||||
|
||||
if _, err := toml.DecodeFile(configPath, &c); err != nil {
|
||||
err = fmt.Errorf("fatal: failed to parse %s; %w", configPath, err)
|
||||
}
|
||||
|
12
cmd/print.go
12
cmd/print.go
@ -102,6 +102,15 @@ func (tp *tablePrinter) Lights(lights []lifx.Light) {
|
||||
table.Render()
|
||||
}
|
||||
|
||||
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" {
|
||||
@ -130,10 +139,11 @@ func PrintfWithIndent(indent int, format string, a ...interface{}) (n int, err e
|
||||
}
|
||||
|
||||
func makeLightsTable(lights []lifx.Light) (hdr []string, rows [][]string) {
|
||||
hdr = []string{"ID", "Location", "Group", "Label", "Last Seen", "Power"}
|
||||
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),
|
||||
|
@ -39,12 +39,13 @@ func ShowCmd(ctx Context) (int, error) {
|
||||
for i, l := range lights {
|
||||
indent = 0
|
||||
fmt.Printf(
|
||||
"Light ID: %s, %s, Power: %s\n",
|
||||
"%s Light ID: %s, %s, Power: %s\n",
|
||||
ColorizeIndicator(l.Power),
|
||||
l.Id,
|
||||
connected(l.Connected),
|
||||
ColorizePower(l.Power),
|
||||
)
|
||||
indent += Tabstop
|
||||
indent += Tabstop + 2
|
||||
PrintfWithIndent(indent, "Label: %s, ID: %s\n", l.Label, l.Id)
|
||||
PrintfWithIndent(indent, "UUID: %s\n", l.UUID)
|
||||
PrintfWithIndent(indent, "Location: %s, ID: %s\n", l.Location.Name, l.Location.Id)
|
||||
|
5
packaging/debian/changelog
Normal file
5
packaging/debian/changelog
Normal file
@ -0,0 +1,5 @@
|
||||
lume (__VERSION__) UNRELEASED; urgency=medium
|
||||
|
||||
* Package generated with make deb
|
||||
|
||||
-- Ryan Cavicchioni <ryan@cavi.cc> __DATE__
|
1
packaging/debian/compat
Normal file
1
packaging/debian/compat
Normal file
@ -0,0 +1 @@
|
||||
9
|
7
packaging/debian/control
Normal file
7
packaging/debian/control
Normal file
@ -0,0 +1,7 @@
|
||||
Source: lume
|
||||
Maintainer: Ryan Cavicchioni <ryan@cavi.cc>
|
||||
|
||||
Package: lume
|
||||
Architecture: any
|
||||
Depends: ${misc:Depends}, ${shlibs:Depends}
|
||||
Description: A CLI tool for the LIFX HTTP API
|
18
packaging/debian/rules
Executable file
18
packaging/debian/rules
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
DISTRIBUTION = $(shell lsb_release -sr)
|
||||
VERSION = __VERSION__
|
||||
PACKAGEVERSION = $(VERSION)
|
||||
|
||||
%:
|
||||
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)
|
32
packaging/rpm/lume.spec
Normal file
32
packaging/rpm/lume.spec
Normal file
@ -0,0 +1,32 @@
|
||||
Name: lume
|
||||
Version: __VERSION__
|
||||
Release: 1%{?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
|
||||
|
||||
|
||||
%changelog
|
||||
* __DATE__ Ryan Cavicchioni <ryan@cavi.cc>
|
||||
- lume __VERSION__
|
Loading…
Reference in New Issue
Block a user