Skip to content

Commit

Permalink
Breaking changes:
Browse files Browse the repository at this point in the history
- Use UTC timezone by default (instead of local)
- *Delta* builtin templates now print string deltas
- .tar.gz releases for osx and linux instead of .zip

Additions:

- ISO8601 builtin time format
- DeltaColor builtin template
- *DeltaNanos* builtin templates that print nanoseconds (like *Delta* did previously)
- 32-bit and ARM releases
  • Loading branch information
sgreben committed Apr 28, 2018
1 parent 7b30343 commit fdf7108
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 53 deletions.
96 changes: 69 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,92 @@
VERSION = 6.0.2
VERSION = 7.0.0

APP := tj
PACKAGES := $(shell go list -f {{.Dir}} ./...)
GOFILES := $(addsuffix /*.go,$(PACKAGES))
GOFILES := $(wildcard $(GOFILES))

.PHONY: clean release docker docker-latest
.PHONY: clean release release-ci release-manual docker docker-latest README.md

clean:
rm -rf binaries/
rm -rf release/

release-ci: README.md zip

release: README.md
git reset
git add README.md
git add Makefile
git commit -am "Release $(VERSION)" || true
git tag "$(VERSION)"
git push
git push origin "$(VERSION)"

# go get -u github.com/github/hub
release: zip
release-manual: README.md zip
git push
hub release delete $(VERSION) || true
hub release create $(VERSION) -m "$(VERSION)" -a release/tj_$(VERSION)_osx_x86_64.zip -a release/tj_$(VERSION)_windows_x86_64.zip -a release/tj_$(VERSION)_linux_x86_64.zip
hub release create $(VERSION) -m "$(VERSION)" -a release/$(APP)_$(VERSION)_osx_x86_64.tar.gz -a release/$(APP)_$(VERSION)_windows_x86_64.zip -a release/$(APP)_$(VERSION)_linux_x86_64.tar.gz -a release/$(APP)_$(VERSION)_osx_x86_32.tar.gz -a release/$(APP)_$(VERSION)_windows_x86_32.zip -a release/$(APP)_$(VERSION)_linux_x86_32.tar.gz -a release/$(APP)_$(VERSION)_linux_arm64.tar.gz

README.md:
sed "s/\$${VERSION}/$(VERSION)/g;s/\$${APP}/$(APP)/g;" README.template.md > README.md

docker: binaries/linux_x86_64/tj
docker build -t quay.io/sergey_grebenshchikov/tj:v$(VERSION) .
docker push quay.io/sergey_grebenshchikov/tj:v$(VERSION)
docker: binaries/linux_x86_64/$(APP)
docker build -t quay.io/sergey_grebenshchikov/$(APP):v$(VERSION) .
docker push quay.io/sergey_grebenshchikov/$(APP):v$(VERSION)

docker-latest: docker
docker tag quay.io/sergey_grebenshchikov/tj:v$(VERSION) quay.io/sergey_grebenshchikov/tj:latest
docker push quay.io/sergey_grebenshchikov/tj:latest
docker tag quay.io/sergey_grebenshchikov/$(APP):v$(VERSION) quay.io/sergey_grebenshchikov/$(APP):latest
docker push quay.io/sergey_grebenshchikov/$(APP):latest

zip: release/tj_$(VERSION)_osx_x86_64.zip release/tj_$(VERSION)_windows_x86_64.zip release/tj_$(VERSION)_linux_x86_64.zip
zip: release/$(APP)_$(VERSION)_osx_x86_64.tar.gz release/$(APP)_$(VERSION)_windows_x86_64.zip release/$(APP)_$(VERSION)_linux_x86_64.tar.gz release/$(APP)_$(VERSION)_osx_x86_32.tar.gz release/$(APP)_$(VERSION)_windows_x86_32.zip release/$(APP)_$(VERSION)_linux_x86_32.tar.gz release/$(APP)_$(VERSION)_linux_arm64.tar.gz

binaries: binaries/osx_x86_64/tj binaries/windows_x86_64/tj.exe binaries/linux_x86_64/tj
binaries: binaries/osx_x86_64/$(APP) binaries/windows_x86_64/$(APP).exe binaries/linux_x86_64/$(APP) binaries/osx_x86_32/$(APP) binaries/windows_x86_32/$(APP).exe binaries/linux_x86_32/$(APP)

clean:
rm -rf binaries/
rm -rf release/
release/$(APP)_$(VERSION)_osx_x86_64.tar.gz: binaries/osx_x86_64/$(APP)
mkdir -p release
tar cfz release/$(APP)_$(VERSION)_osx_x86_64.tar.gz -C binaries/osx_x86_64 $(APP)

binaries/osx_x86_64/$(APP): $(GOFILES)
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o binaries/osx_x86_64/$(APP) ./cmd/$(APP)

release/$(APP)_$(VERSION)_windows_x86_64.zip: binaries/windows_x86_64/$(APP).exe
mkdir -p release
cd ./binaries/windows_x86_64 && zip -r -D ../../release/$(APP)_$(VERSION)_windows_x86_64.zip $(APP).exe

binaries/windows_x86_64/$(APP).exe: $(GOFILES)
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o binaries/windows_x86_64/$(APP).exe ./cmd/$(APP)

release/$(APP)_$(VERSION)_linux_x86_64.tar.gz: binaries/linux_x86_64/$(APP)
mkdir -p release
tar cfz release/$(APP)_$(VERSION)_linux_x86_64.tar.gz -C binaries/linux_x86_64 $(APP)

binaries/linux_x86_64/$(APP): $(GOFILES)
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o binaries/linux_x86_64/$(APP) ./cmd/$(APP)

release/$(APP)_$(VERSION)_osx_x86_32.tar.gz: binaries/osx_x86_32/$(APP)
mkdir -p release
tar cfz release/$(APP)_$(VERSION)_osx_x86_32.tar.gz -C binaries/osx_x86_32 $(APP)

binaries/osx_x86_32/$(APP): $(GOFILES)
GOOS=darwin GOARCH=386 go build -ldflags "-X main.version=$(VERSION)" -o binaries/osx_x86_32/$(APP) ./cmd/$(APP)

release/tj_$(VERSION)_osx_x86_64.zip: binaries/osx_x86_64/tj
release/$(APP)_$(VERSION)_windows_x86_32.zip: binaries/windows_x86_32/$(APP).exe
mkdir -p release
cd ./binaries/osx_x86_64 && zip -r -D ../../release/tj_$(VERSION)_osx_x86_64.zip tj
cd ./binaries/windows_x86_32 && zip -r -D ../../release/$(APP)_$(VERSION)_windows_x86_32.zip $(APP).exe

binaries/osx_x86_64/tj: $(GOFILES)
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o binaries/osx_x86_64/tj ./cmd/tj
binaries/windows_x86_32/$(APP).exe: $(GOFILES)
GOOS=windows GOARCH=386 go build -ldflags "-X main.version=$(VERSION)" -o binaries/windows_x86_32/$(APP).exe ./cmd/$(APP)

release/tj_$(VERSION)_windows_x86_64.zip: binaries/windows_x86_64/tj.exe
release/$(APP)_$(VERSION)_linux_x86_32.tar.gz: binaries/linux_x86_32/$(APP)
mkdir -p release
cd ./binaries/windows_x86_64 && zip -r -D ../../release/tj_$(VERSION)_windows_x86_64.zip tj.exe
tar cfz release/$(APP)_$(VERSION)_linux_x86_32.tar.gz -C binaries/linux_x86_32 $(APP)

binaries/windows_x86_64/tj.exe: $(GOFILES)
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o binaries/windows_x86_64/tj.exe ./cmd/tj
binaries/linux_x86_32/$(APP): $(GOFILES)
GOOS=linux GOARCH=386 go build -ldflags "-X main.version=$(VERSION)" -o binaries/linux_x86_32/$(APP) ./cmd/$(APP)

release/tj_$(VERSION)_linux_x86_64.zip: binaries/linux_x86_64/tj
release/$(APP)_$(VERSION)_linux_arm64.tar.gz: binaries/linux_arm64/$(APP)
mkdir -p release
cd ./binaries/linux_x86_64 && zip -r -D ../../release/tj_$(VERSION)_linux_x86_64.zip tj
tar cfz release/$(APP)_$(VERSION)_linux_arm64.tar.gz -C binaries/linux_arm64 $(APP)

binaries/linux_x86_64/tj: $(GOFILES)
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o binaries/linux_x86_64/tj ./cmd/tj
binaries/linux_arm64/$(APP): $(GOFILES)
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.version=$(VERSION)" -o binaries/linux_arm64/$(APP) ./cmd/$(APP)
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@ Using go get:
go get -u github.com/sgreben/tj/cmd/tj
```

Or [download the binary](https://github.com/sgreben/tj/releases/latest) from the releases page.

Also available as a [docker image](https://quay.io/repository/sergey_grebenshchikov/tj?tab=tags):
Or [download the binary](https://github.com/sgreben/tj/releases/latest) from the releases page:

```bash
docker pull quay.io/sergey_grebenshchikov/tj
# Linux
curl -L https://github.com/sgreben/tj/releases/download/7.0.0/tj_7.0.0_linux_x86_64.tar.gz | tar xz

# OS X
curl -L https://github.com/sgreben/tj/releases/download/7.0.0/tj_7.0.0_osx_x86_64.tar.gz | tar xz

# Windows
curl -LO https://github.com/sgreben/tj/releases/download/7.0.0/tj_7.0.0_windows_x86_64.zip
unzip tj_7.0.0_windows_x86_64.zip
```

Or using [docker-get](https://github.com/32b/docker-get):
Also available as a [docker image](https://quay.io/repository/sergey_grebenshchikov/tj?tab=tags):

```bash
docker-get https://github.com/sgreben/tj
docker pull quay.io/sergey_grebenshchikov/tj
```

## Use it
Expand All @@ -49,7 +55,7 @@ Usage of tj:
-time-format string
either a go time format string or one of the predefined format names (https://golang.org/pkg/time/#pkg-constants)
-time-zone string
time zone to use (default "Local")
time zone to use (or "Local") (default "UTC")
-match-regex string
a regex pattern. if given, only tokens matching it (re)start the stopwatch
-match-template string
Expand Down Expand Up @@ -113,12 +119,13 @@ $ (echo Hello; echo World) | tj -time-format Kitchen
{"timeSecs":1517592194,"timeNanos":1517592194875197515,"time":"6:23PM","deltaSecs":0.000180876,"deltaNanos":180876,"delta":"180.876µs","totalSecs":0.000198018,"totalNanos":198018,"total":"198.018µs","text":"World"}
```

The [constant names from pkg/time](https://golang.org/pkg/time/#pkg-constants) as well as regular go time layouts are admissible values for `-time-format`:
The [constant names from pkg/time](https://golang.org/pkg/time/#pkg-constants) as well as regular go time layouts are valid values for `-time-format`:

| Name | Format |
|------------|-------------------------------------|
| ANSIC | `Mon Jan _2 15:04:05 2006` |
| Kitchen | `3:04PM` |
| ISO8601 | `2006-01-02T15:04:05Z07:00` |
| RFC1123 | `Mon, 02 Jan 2006 15:04:05 MST` |
| RFC1123Z | `Mon, 02 Jan 2006 15:04:05 -0700` |
| RFC3339 | `2006-01-02T15:04:05Z07:00` |
Expand Down Expand Up @@ -150,15 +157,18 @@ The fields available to the template are specified in the [`token` struct](cmd/t

Some templates are pre-defined and can be used via `-template NAME`:

| Name | Template |
|------------|--------------------------------------------------|
| Color | `{{color .}}█{{reset}} {{.Text}}` |
| ColorText | `{{color .}}{{.Text}}{{reset}}` |
| Delta | `{{.DeltaNanos}} {{.Text}}` |
| Text | `{{.Text}}` |
| Time | `{{.TimeString}} {{.Text}}` |
| TimeDelta | `{{.TimeString}} +{{.DeltaNanos}} {{.Text}}` |
| TimeColor | `{{.TimeString}} {{color .}}█{{reset}} {{.Text}}`|
| Name | Template |
|-----------------|--------------------------------------------------|
| Color | `{{color .}}█{{reset}} {{.Text}}` |
| ColorText | `{{color .}}{{.Text}}{{reset}}` |
| Delta | `{{.Delta}} {{.Text}}` |
| DeltaColor | `{{.Delta}} {{color .}}█{{reset}} {{.Text}}` |
| DeltaNanos | `{{.DeltaNanos}} {{.Text}}` |
| Text | `{{.Text}}` |
| Time | `{{.TimeString}} {{.Text}}` |
| TimeColor | `{{.TimeString}} {{color .}}█{{reset}} {{.Text}}`|
| TimeDelta | `{{.TimeString}} +{{.Delta}} {{.Text}}` |
| TimeDeltaNanos | `{{.TimeString}} +{{.DeltaNanos}} {{.Text}}` |

### Color output

Expand Down Expand Up @@ -297,4 +307,4 @@ $ docker build . |

## Comments

Feel free to [leave a comment](https://github.com/sgreben/tj/issues/1) or create an issue.
Feel free to [leave a comment](https://github.com/sgreben/tj/issues/1) or create an issue.
Loading

0 comments on commit fdf7108

Please sign in to comment.