mirror of https://github.com/maxcnunes/gaper.git
Compare commits
28 Commits
Author | SHA1 | Date |
---|---|---|
|
c44dd59952 | |
|
5a02122f33 | |
|
edee55552a | |
|
d314b7b928 | |
|
f0479bba61 | |
|
90f855c72b | |
|
1fde6281f1 | |
|
95fc7d2127 | |
|
b0dcdd49b0 | |
|
39d9c0ad64 | |
|
9229e8d69b | |
|
4eb2525b49 | |
|
7f381c7e58 | |
|
2a09c4e713 | |
|
e99cd89574 | |
|
3f3fcea575 | |
|
0324256f9c | |
|
7c57257db3 | |
|
60a0a90d11 | |
|
2cdb29eb89 | |
|
69ab70821a | |
|
56a75324ca | |
|
7ecf55b3f6 | |
|
931f3778a8 | |
|
a5cac98c13 | |
|
a93d484fb3 | |
|
daee1bff02 | |
|
c9da986360 |
|
@ -0,0 +1,37 @@
|
||||||
|
name: goreleaser
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
# run only against tags
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
goreleaser:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
-
|
||||||
|
name: Fetch all tags
|
||||||
|
run: git fetch --force --tags
|
||||||
|
-
|
||||||
|
name: Set up Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.19
|
||||||
|
-
|
||||||
|
name: Run GoReleaser
|
||||||
|
uses: goreleaser/goreleaser-action@v2
|
||||||
|
with:
|
||||||
|
distribution: goreleaser
|
||||||
|
version: latest
|
||||||
|
args: release --rm-dist
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@ -0,0 +1,39 @@
|
||||||
|
name: dev-workflow
|
||||||
|
|
||||||
|
on:
|
||||||
|
- push
|
||||||
|
jobs:
|
||||||
|
run:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- ubuntu-latest
|
||||||
|
# - macos-latest
|
||||||
|
# - windows-latest
|
||||||
|
go:
|
||||||
|
- '1.19'
|
||||||
|
# - '1.18'
|
||||||
|
# - '1.17'
|
||||||
|
# - '1.16'
|
||||||
|
# - '1.15'
|
||||||
|
env:
|
||||||
|
OS: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v3
|
||||||
|
with:
|
||||||
|
version: v1.48
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: make test
|
||||||
|
|
||||||
|
- name: Upload coverage to Codecov
|
||||||
|
uses: codecov/codecov-action@v3
|
29
.travis.yml
29
.travis.yml
|
@ -1,29 +0,0 @@
|
||||||
language: go
|
|
||||||
|
|
||||||
go:
|
|
||||||
# - 1.7.x
|
|
||||||
# - 1.8.x
|
|
||||||
# - 1.9.x
|
|
||||||
- 1.10.x
|
|
||||||
# - master
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- go version
|
|
||||||
- make setup
|
|
||||||
- make lint
|
|
||||||
|
|
||||||
script:
|
|
||||||
- make test
|
|
||||||
|
|
||||||
after_success:
|
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
email: false
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
- provider: script
|
|
||||||
skip_cleanup: true
|
|
||||||
script: curl -sL http://git.io/goreleaser | bash
|
|
||||||
on:
|
|
||||||
tags: true
|
|
|
@ -28,7 +28,13 @@ make setup
|
||||||
### Running gaper in development
|
### Running gaper in development
|
||||||
|
|
||||||
```
|
```
|
||||||
make build && ./gaper --verbose --bin-name srv --build-path ./testdata/server
|
make build && \
|
||||||
|
./gaper \
|
||||||
|
--verbose \
|
||||||
|
--bin-name srv \
|
||||||
|
--build-path ./testdata/server \
|
||||||
|
--build-args="-ldflags=\"-X 'main.Version=v1.0.0'\"" \
|
||||||
|
--extensions "go,txt"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Running lint
|
### Running lint
|
||||||
|
@ -49,3 +55,6 @@ A single test:
|
||||||
go test -run TestSimplePost ./...
|
go test -run TestSimplePost ./...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Release
|
||||||
|
|
||||||
|
The release runs automatically with a Github action on pushed git tags.
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/davecgh/go-spew"
|
|
||||||
packages = ["spew"]
|
|
||||||
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
|
|
||||||
version = "v1.1.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/fatih/color"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "5b77d2a35fb0ede96d138fc9a99f5c9b6aef11b4"
|
|
||||||
version = "v1.7.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/mattn/go-colorable"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
|
|
||||||
version = "v0.0.9"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/mattn/go-isatty"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
|
|
||||||
version = "v0.0.3"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/mattn/go-shellwords"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "02e3cf038dcea8290e44424da473dd12be796a8a"
|
|
||||||
version = "v1.0.3"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/mattn/go-zglob"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"fastwalk"
|
|
||||||
]
|
|
||||||
revision = "49693fbb3fe3c3a75fc4e4d6fb1d7cedcbdeb385"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/pmezard/go-difflib"
|
|
||||||
packages = ["difflib"]
|
|
||||||
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
|
|
||||||
version = "v1.0.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/stretchr/objx"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "477a77ecc69700c7cdeb1fa9e129548e1c1c393c"
|
|
||||||
version = "v0.1.1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/stretchr/testify"
|
|
||||||
packages = [
|
|
||||||
"assert",
|
|
||||||
"mock"
|
|
||||||
]
|
|
||||||
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
|
|
||||||
version = "v1.2.2"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/urfave/cli"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1"
|
|
||||||
version = "v1.20.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/sys"
|
|
||||||
packages = ["unix"]
|
|
||||||
revision = "6c888cc515d3ed83fc103cf1d84468aad274b0a7"
|
|
||||||
|
|
||||||
[solve-meta]
|
|
||||||
analyzer-name = "dep"
|
|
||||||
analyzer-version = 1
|
|
||||||
inputs-digest = "8446ff85ebcb6bc802d3f444727c3910444a405f3c073c1095eb5cc8c497138b"
|
|
||||||
solver-name = "gps-cdcl"
|
|
||||||
solver-version = 1
|
|
23
Gopkg.toml
23
Gopkg.toml
|
@ -1,23 +0,0 @@
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/fatih/color"
|
|
||||||
version = "1.7.0"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/mattn/go-shellwords"
|
|
||||||
version = "1.0.3"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/urfave/cli"
|
|
||||||
version = "1.20.0"
|
|
||||||
|
|
||||||
[prune]
|
|
||||||
go-tests = true
|
|
||||||
unused-packages = true
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/mattn/go-zglob"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/stretchr/testify"
|
|
||||||
version = "1.2.2"
|
|
24
Makefile
24
Makefile
|
@ -3,32 +3,14 @@ TEST_PACKAGES := $(shell go list ./... | grep -v cmd)
|
||||||
COVER_PACKAGES := $(shell go list ./... | grep -v cmd | paste -sd "," -)
|
COVER_PACKAGES := $(shell go list ./... | grep -v cmd | paste -sd "," -)
|
||||||
LINTER := $(shell command -v gometalinter 2> /dev/null)
|
LINTER := $(shell command -v gometalinter 2> /dev/null)
|
||||||
|
|
||||||
.PHONY: setup
|
|
||||||
|
|
||||||
setup:
|
|
||||||
ifeq ($(OS), Darwin)
|
|
||||||
brew install dep
|
|
||||||
else
|
|
||||||
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
|
||||||
endif
|
|
||||||
dep ensure -vendor-only
|
|
||||||
ifndef LINTER
|
|
||||||
@echo "Installing linter"
|
|
||||||
@go get -u github.com/alecthomas/gometalinter
|
|
||||||
@gometalinter --install
|
|
||||||
endif
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@go build -o ./gaper cmd/gaper/main.go
|
@go build -o ./gaper cmd/gaper/main.go
|
||||||
|
|
||||||
## lint: Validate golang code
|
## lint: Validate golang code
|
||||||
|
# Install it following this doc https://golangci-lint.run/usage/install/#local-installation,
|
||||||
|
# please use the same version from .github/workflows/workflow.yml.
|
||||||
lint:
|
lint:
|
||||||
@gometalinter \
|
@golangci-lint run
|
||||||
--deadline=120s \
|
|
||||||
--line-length=120 \
|
|
||||||
--enable-all \
|
|
||||||
--disable=gochecknoinits --disable=gochecknoglobals \
|
|
||||||
--vendor ./...
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@go test -p=1 -coverpkg $(COVER_PACKAGES) \
|
@go test -p=1 -coverpkg $(COVER_PACKAGES) \
|
||||||
|
|
42
README.md
42
README.md
|
@ -18,15 +18,23 @@
|
||||||
[](https://goreportcard.com/report/github.com/maxcnunes/gaper)
|
[](https://goreportcard.com/report/github.com/maxcnunes/gaper)
|
||||||
[](https://github.com/goreleaser)
|
[](https://github.com/goreleaser)
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
|
||||||
|
See [Releases](https://github.com/maxcnunes/gaper/releases) for detailed history changes.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
Using go tooling:
|
||||||
|
|
||||||
```
|
```
|
||||||
go get -u github.com/maxcnunes/gaper/cmd/gaper
|
go get -u github.com/maxcnunes/gaper/cmd/gaper
|
||||||
```
|
```
|
||||||
|
|
||||||
## Changelog
|
Or, downloading the binary instead (example for version 1.1.0, make sure you are using the latest version though):
|
||||||
|
|
||||||
See [Releases](https://github.com/maxcnunes/gaper/releases) for detailed history changes.
|
```
|
||||||
|
curl -SL https://github.com/maxcnunes/gaper/releases/download/v1.1.0/gaper_1.1.0_linux_amd64.tar.gz | tar -xvzf - -C "${GOPATH}/bin"
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -53,7 +61,7 @@ GLOBAL OPTIONS:
|
||||||
--watch value, -w value list of folders or files to watch for changes
|
--watch value, -w value list of folders or files to watch for changes
|
||||||
--ignore value, -i value list of folders or files to ignore for changes
|
--ignore value, -i value list of folders or files to ignore for changes
|
||||||
--poll-interval value, -p value how often in milliseconds to poll watched files for changes (default: 500)
|
--poll-interval value, -p value how often in milliseconds to poll watched files for changes (default: 500)
|
||||||
--extensions value, -e value a comma-delimited list of file extensions to watch for changes (default: "go")
|
--extensions value, -e value extensions to watch for changes (default: "go")
|
||||||
--no-restart-on value, -n value don't automatically restart the supervised program if it ends:
|
--no-restart-on value, -n value don't automatically restart the supervised program if it ends:
|
||||||
if "error", an exit code of 0 will still restart.
|
if "error", an exit code of 0 will still restart.
|
||||||
if "exit", no restart regardless of exit code.
|
if "exit", no restart regardless of exit code.
|
||||||
|
@ -62,7 +70,15 @@ GLOBAL OPTIONS:
|
||||||
--version, -v print the version
|
--version, -v print the version
|
||||||
```
|
```
|
||||||
|
|
||||||
Since in most projects there is no need to watch changes of:
|
### Watch and Ignore paths
|
||||||
|
|
||||||
|
For those options Gaper supports static paths (e.g. `build/`, `seed.go`) or glob paths (e.g. `migrations/**/up.go`, `*_test.go`).
|
||||||
|
|
||||||
|
On using a path to a directory please add a `/` at the end (e.g. `build/`) to make sure Gaper won't include other matches that starts with that same value (e.g. `build/`, `build_settings.go`).
|
||||||
|
|
||||||
|
### Default ignore settings
|
||||||
|
|
||||||
|
Since in most projects there is no need to watch changes for:
|
||||||
|
|
||||||
* hidden files and folders
|
* hidden files and folders
|
||||||
* test files (`*_test.go`)
|
* test files (`*_test.go`)
|
||||||
|
@ -70,6 +86,10 @@ Since in most projects there is no need to watch changes of:
|
||||||
|
|
||||||
Gaper by default ignores those cases already. Although, if you need Gaper to watch those files anyway it is possible to disable this setting with `--disable-default-ignore` argument.
|
Gaper by default ignores those cases already. Although, if you need Gaper to watch those files anyway it is possible to disable this setting with `--disable-default-ignore` argument.
|
||||||
|
|
||||||
|
### Watch method
|
||||||
|
|
||||||
|
Currently Gaper uses polling to watch file changes. We have plans to [support fs events](https://github.com/maxcnunes/gaper/issues/12) though in a near future.
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
Using all defaults provided by Gaper:
|
Using all defaults provided by Gaper:
|
||||||
|
@ -78,12 +98,18 @@ Using all defaults provided by Gaper:
|
||||||
gaper
|
gaper
|
||||||
```
|
```
|
||||||
|
|
||||||
Ignore watch over all test files:
|
Example providing a few custom configurations:
|
||||||
|
|
||||||
> no need for this in case if you are not using `--disable-default-ignore`
|
|
||||||
|
|
||||||
```
|
```
|
||||||
--ignore './**/*_test.go'
|
gaper \
|
||||||
|
--bin-name build/api-dev \
|
||||||
|
--build-path cmd/server \
|
||||||
|
--build-args "-ldflags=\"-X 'main.Version=dev'" \
|
||||||
|
-w 'public/**' -w '*.go' \
|
||||||
|
-e js -e css -e html \
|
||||||
|
--ignore './**/*_mock.go' \
|
||||||
|
--program-args "-arg1 ok -arg2=nope" \
|
||||||
|
--watch .
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
31
appveyor.yml
31
appveyor.yml
|
@ -1,31 +0,0 @@
|
||||||
version: "{build}"
|
|
||||||
|
|
||||||
# Source Config
|
|
||||||
|
|
||||||
clone_folder: c:\gopath\src\github.com\maxcnunes\gaper
|
|
||||||
|
|
||||||
# Build host
|
|
||||||
|
|
||||||
environment:
|
|
||||||
GOPATH: c:\gopath
|
|
||||||
GOBIN: c:\gopath\bin
|
|
||||||
|
|
||||||
init:
|
|
||||||
- git config --global core.autocrlf input
|
|
||||||
|
|
||||||
# Build
|
|
||||||
|
|
||||||
install:
|
|
||||||
- set Path=c:\go\bin;c:\gopath\bin;%Path%
|
|
||||||
- go version
|
|
||||||
- go env
|
|
||||||
- go get -u github.com/golang/dep/cmd/dep
|
|
||||||
- choco install make
|
|
||||||
- make setup
|
|
||||||
|
|
||||||
build: false
|
|
||||||
deploy: false
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- go build github.com/maxcnunes/gaper/cmd/gaper
|
|
||||||
- make test
|
|
|
@ -17,7 +17,6 @@ type Builder interface {
|
||||||
type builder struct {
|
type builder struct {
|
||||||
dir string
|
dir string
|
||||||
binary string
|
binary string
|
||||||
errors string
|
|
||||||
wd string
|
wd string
|
||||||
buildArgs []string
|
buildArgs []string
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,15 +38,13 @@ func TestBuilderFailureBuild(t *testing.T) {
|
||||||
t.Fatalf("couldn't get current working directory: %v", err)
|
t.Fatalf("couldn't get current working directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
absPathBuild := filepath.Join(wd, dir)
|
|
||||||
|
|
||||||
b := NewBuilder(dir, bin, wd, bArgs)
|
b := NewBuilder(dir, bin, wd, bArgs)
|
||||||
err = b.Build()
|
err = b.Build()
|
||||||
assert.NotNil(t, err, "build error")
|
assert.NotNil(t, err, "build error")
|
||||||
assert.Equal(t, err.Error(), "build failed with exit status 2\n"+
|
assert.Equal(t, err.Error(), "build failed with exit status 2\n"+
|
||||||
"# _"+absPathBuild+"\n"+
|
"# github.com/maxcnunes/gaper/testdata/build-failure\n"+
|
||||||
"./main.go:4:6: func main must have no arguments and no return values\n"+
|
"./main.go:4:6: func main must have no arguments and no return values\n"+
|
||||||
"./main.go:5:1: missing return at end of function\n")
|
"./main.go:5:1: missing return\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilderDefaultBinName(t *testing.T) {
|
func TestBuilderDefaultBinName(t *testing.T) {
|
||||||
|
|
|
@ -4,27 +4,29 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/maxcnunes/gaper"
|
"github.com/maxcnunes/gaper"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// build info
|
// build info
|
||||||
var (
|
var (
|
||||||
// keep the version hardcoded because on installing it through "go get/install"
|
// Version is hardcoded because when installing it through "go get/install"
|
||||||
// it doesn't apply the build tags to override it. So, it is make easier for
|
// the build tags are not available to override it.
|
||||||
// people using in that case to find out which version they are using
|
// Update it after every release.
|
||||||
version = "1.0.1-dev"
|
version = "1.0.3-dev"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = gaper.NewLogger("gaper")
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
logger := gaper.Logger()
|
||||||
|
loggerVerbose := false
|
||||||
|
|
||||||
parseArgs := func(c *cli.Context) *gaper.Config {
|
parseArgs := func(c *cli.Context) *gaper.Config {
|
||||||
|
loggerVerbose = c.Bool("verbose")
|
||||||
|
|
||||||
return &gaper.Config{
|
return &gaper.Config{
|
||||||
BinName: c.String("bin-name"),
|
BinName: c.String("bin-name"),
|
||||||
BuildPath: c.String("build-path"),
|
BuildPath: c.String("build-path"),
|
||||||
BuildArgsMerged: c.String("build-args"),
|
BuildArgsMerged: c.String("build-args"),
|
||||||
ProgramArgsMerged: c.String("program-args"),
|
ProgramArgsMerged: c.String("program-args"),
|
||||||
Verbose: c.Bool("verbose"),
|
|
||||||
DisableDefaultIgnore: c.Bool("disable-default-ignore"),
|
DisableDefaultIgnore: c.Bool("disable-default-ignore"),
|
||||||
WatchItems: c.StringSlice("watch"),
|
WatchItems: c.StringSlice("watch"),
|
||||||
IgnoreItems: c.StringSlice("ignore"),
|
IgnoreItems: c.StringSlice("ignore"),
|
||||||
|
@ -39,69 +41,61 @@ func main() {
|
||||||
app.Usage = "Used to build and restart a Go project when it crashes or some watched file changes"
|
app.Usage = "Used to build and restart a Go project when it crashes or some watched file changes"
|
||||||
app.Version = version
|
app.Version = version
|
||||||
|
|
||||||
app.Action = func(c *cli.Context) {
|
app.Action = func(c *cli.Context) error {
|
||||||
args := parseArgs(c)
|
args := parseArgs(c)
|
||||||
chOSSiginal := make(chan os.Signal, 2)
|
chOSSiginal := make(chan os.Signal, 2)
|
||||||
logger.Verbose(args.Verbose)
|
logger.Verbose(loggerVerbose)
|
||||||
|
|
||||||
if err := gaper.Run(args, chOSSiginal); err != nil {
|
return gaper.Run(args, chOSSiginal)
|
||||||
logger.Error(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exts := make(cli.StringSlice, len(gaper.DefaultExtensions))
|
|
||||||
for i := range gaper.DefaultExtensions {
|
|
||||||
exts[i] = gaper.DefaultExtensions[i]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// supported arguments
|
// supported arguments
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "bin-name",
|
Name: "bin-name",
|
||||||
Usage: "name for the binary built by gaper for the executed program (default current directory name)",
|
Usage: "name for the binary built by gaper for the executed program (default current directory name)",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "build-path",
|
Name: "build-path",
|
||||||
Value: gaper.DefaultBuildPath,
|
Value: gaper.DefaultBuildPath,
|
||||||
Usage: "path to the program source code",
|
Usage: "path to the program source code",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "build-args",
|
Name: "build-args",
|
||||||
Usage: "arguments used on building the program",
|
Usage: "arguments used on building the program",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "program-args",
|
Name: "program-args",
|
||||||
Usage: "arguments used on executing the program",
|
Usage: "arguments used on executing the program",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "verbose",
|
Name: "verbose",
|
||||||
Usage: "turns on the verbose messages from gaper",
|
Usage: "turns on the verbose messages from gaper",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "disable-default-ignore",
|
Name: "disable-default-ignore",
|
||||||
Usage: "turns off default ignore for hidden files and folders, \"*_test.go\" files, and vendor folder",
|
Usage: "turns off default ignore for hidden files and folders, \"*_test.go\" files, and vendor folder",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "watch, w",
|
Name: "watch, w",
|
||||||
Usage: "list of folders or files to watch for changes",
|
Usage: "list of folders or files to watch for changes",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "ignore, i",
|
Name: "ignore, i",
|
||||||
Usage: "list of folders or files to ignore for changes\n" +
|
Usage: "list of folders or files to ignore for changes\n" +
|
||||||
"\t\t(always ignores all hidden files and directories)",
|
"\t\t(always ignores all hidden files and directories)",
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "poll-interval, p",
|
Name: "poll-interval, p",
|
||||||
Value: gaper.DefaultPoolInterval,
|
Value: gaper.DefaultPoolInterval,
|
||||||
Usage: "how often in milliseconds to poll watched files for changes",
|
Usage: "how often in milliseconds to poll watched files for changes",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "extensions, e",
|
Name: "extensions, e",
|
||||||
Value: &exts,
|
Value: cli.NewStringSlice(gaper.DefaultExtensions...),
|
||||||
Usage: "a comma-delimited list of file extensions to watch for changes",
|
Usage: "a comma-delimited list of file extensions to watch for changes",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "no-restart-on, n",
|
Name: "no-restart-on, n",
|
||||||
Usage: "don't automatically restart the supervised program if it ends:\n" +
|
Usage: "don't automatically restart the supervised program if it ends:\n" +
|
||||||
"\t\tif \"error\", an exit code of 0 will still restart.\n" +
|
"\t\tif \"error\", an exit code of 0 will still restart.\n" +
|
||||||
|
|
21
gaper.go
21
gaper.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -29,8 +30,6 @@ var (
|
||||||
NoRestartOnExit = "exit"
|
NoRestartOnExit = "exit"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = NewLogger("gaper")
|
|
||||||
|
|
||||||
// exit statuses
|
// exit statuses
|
||||||
var exitStatusSuccess = 0
|
var exitStatusSuccess = 0
|
||||||
var exitStatusError = 1
|
var exitStatusError = 1
|
||||||
|
@ -48,7 +47,6 @@ type Config struct {
|
||||||
PollInterval int
|
PollInterval int
|
||||||
Extensions []string
|
Extensions []string
|
||||||
NoRestartOn string
|
NoRestartOn string
|
||||||
Verbose bool
|
|
||||||
DisableDefaultIgnore bool
|
DisableDefaultIgnore bool
|
||||||
WorkingDirectory string
|
WorkingDirectory string
|
||||||
}
|
}
|
||||||
|
@ -62,6 +60,8 @@ func Run(cfg *Config, chOSSiginal chan os.Signal) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Debugf("Config: %+v", cfg)
|
||||||
|
|
||||||
wCfg := WatcherConfig{
|
wCfg := WatcherConfig{
|
||||||
DefaultIgnore: !cfg.DisableDefaultIgnore,
|
DefaultIgnore: !cfg.DisableDefaultIgnore,
|
||||||
PollInterval: cfg.PollInterval,
|
PollInterval: cfg.PollInterval,
|
||||||
|
@ -101,7 +101,13 @@ func run(cfg *Config, chOSSiginal chan os.Signal, builder Builder, runner Runner
|
||||||
select {
|
select {
|
||||||
case event := <-watcher.Events():
|
case event := <-watcher.Events():
|
||||||
logger.Debug("Detected new changed file:", event)
|
logger.Debug("Detected new changed file:", event)
|
||||||
changeRestart = true
|
if changeRestart {
|
||||||
|
logger.Debug("Skip restart due to existing on going restart")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
changeRestart = runner.IsRunning()
|
||||||
|
|
||||||
if err := restart(builder, runner); err != nil {
|
if err := restart(builder, runner); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -203,6 +209,13 @@ func setupConfig(cfg *Config) error {
|
||||||
cfg.WatchItems = append(cfg.WatchItems, cfg.BuildPath)
|
cfg.WatchItems = append(cfg.WatchItems, cfg.BuildPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var extensions []string
|
||||||
|
for i := range cfg.Extensions {
|
||||||
|
values := strings.Split(cfg.Extensions[i], ",")
|
||||||
|
extensions = append(extensions, values...)
|
||||||
|
}
|
||||||
|
cfg.Extensions = extensions
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
module github.com/maxcnunes/gaper
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/fatih/color v1.7.0
|
||||||
|
github.com/mattn/go-colorable v0.0.9 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.3 // indirect
|
||||||
|
github.com/mattn/go-shellwords v1.0.3
|
||||||
|
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3
|
||||||
|
github.com/stretchr/objx v0.1.1 // indirect
|
||||||
|
github.com/stretchr/testify v1.4.0
|
||||||
|
github.com/urfave/cli/v2 v2.11.1
|
||||||
|
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
)
|
|
@ -0,0 +1,38 @@
|
||||||
|
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||||
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
|
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
|
||||||
|
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||||
|
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
|
||||||
|
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||||
|
github.com/mattn/go-shellwords v1.0.3 h1:K/VxK7SZ+cvuPgFSLKi5QPI9Vr/ipOf4C1gN+ntueUk=
|
||||||
|
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
|
||||||
|
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3 h1:GWnsQiFbiQ7lREZbKkiJC6xxbymvny8GKtpdkPxjB6o=
|
||||||
|
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
|
||||||
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/urfave/cli/v2 v2.11.1 h1:UKK6SP7fV3eKOefbS87iT9YHefv7iB/53ih6e+GNAsE=
|
||||||
|
github.com/urfave/cli/v2 v2.11.1/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||||
|
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3 h1:FCfAlbS73+IQQJktaKGHldMdL2bGDVpm+OrCEbVz1f4=
|
||||||
|
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
30
logger.go
30
logger.go
|
@ -7,18 +7,26 @@ import (
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Logger used by gaper
|
// logger use by the whole package
|
||||||
type Logger struct {
|
var logger = newLogger("gaper")
|
||||||
|
|
||||||
|
// Logger give access to external packages to use gaper logger
|
||||||
|
func Logger() *LoggerEntity {
|
||||||
|
return logger
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoggerEntity used by gaper
|
||||||
|
type LoggerEntity struct {
|
||||||
verbose bool
|
verbose bool
|
||||||
logDebug *log.Logger
|
logDebug *log.Logger
|
||||||
logInfo *log.Logger
|
logInfo *log.Logger
|
||||||
logError *log.Logger
|
logError *log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLogger creates a new logger
|
// newLogger creates a new logger
|
||||||
func NewLogger(prefix string) *Logger {
|
func newLogger(prefix string) *LoggerEntity {
|
||||||
prefix = "[" + prefix + "] "
|
prefix = "[" + prefix + "] "
|
||||||
return &Logger{
|
return &LoggerEntity{
|
||||||
verbose: false,
|
verbose: false,
|
||||||
logDebug: log.New(os.Stdout, prefix, 0),
|
logDebug: log.New(os.Stdout, prefix, 0),
|
||||||
logInfo: log.New(os.Stdout, color.CyanString(prefix), 0),
|
logInfo: log.New(os.Stdout, color.CyanString(prefix), 0),
|
||||||
|
@ -27,35 +35,35 @@ func NewLogger(prefix string) *Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verbose toggle this logger verbosity
|
// Verbose toggle this logger verbosity
|
||||||
func (l *Logger) Verbose(verbose bool) {
|
func (l *LoggerEntity) Verbose(verbose bool) {
|
||||||
l.verbose = verbose
|
l.verbose = verbose
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug logs a debug message
|
// Debug logs a debug message
|
||||||
func (l *Logger) Debug(v ...interface{}) {
|
func (l *LoggerEntity) Debug(v ...interface{}) {
|
||||||
if l.verbose {
|
if l.verbose {
|
||||||
l.logDebug.Println(v...)
|
l.logDebug.Println(v...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf logs a debug message with format
|
// Debugf logs a debug message with format
|
||||||
func (l *Logger) Debugf(format string, v ...interface{}) {
|
func (l *LoggerEntity) Debugf(format string, v ...interface{}) {
|
||||||
if l.verbose {
|
if l.verbose {
|
||||||
l.logDebug.Printf(format, v...)
|
l.logDebug.Printf(format, v...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info logs a info message
|
// Info logs a info message
|
||||||
func (l *Logger) Info(v ...interface{}) {
|
func (l *LoggerEntity) Info(v ...interface{}) {
|
||||||
l.logInfo.Println(v...)
|
l.logInfo.Println(v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error logs an error message
|
// Error logs an error message
|
||||||
func (l *Logger) Error(v ...interface{}) {
|
func (l *LoggerEntity) Error(v ...interface{}) {
|
||||||
l.logError.Println(v...)
|
l.logError.Println(v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf logs and error message with format
|
// Errorf logs and error message with format
|
||||||
func (l *Logger) Errorf(format string, v ...interface{}) {
|
func (l *LoggerEntity) Errorf(format string, v ...interface{}) {
|
||||||
l.logError.Printf(format, v...)
|
l.logError.Printf(format, v...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,19 +7,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoggerDefault(t *testing.T) {
|
func TestLoggerDefault(t *testing.T) {
|
||||||
l := NewLogger("gaper-test")
|
l := newLogger("gaper-test")
|
||||||
assert.Equal(t, l.verbose, false)
|
assert.Equal(t, l.verbose, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoggerEnableVerbose(t *testing.T) {
|
func TestLoggerEnableVerbose(t *testing.T) {
|
||||||
l := NewLogger("gaper-test")
|
l := newLogger("gaper-test")
|
||||||
l.Verbose(true)
|
l.Verbose(true)
|
||||||
assert.Equal(t, l.verbose, true)
|
assert.Equal(t, l.verbose, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoggerRunAllLogsWithoutVerbose(t *testing.T) {
|
func TestLoggerRunAllLogsWithoutVerbose(t *testing.T) {
|
||||||
// no asserts, just checking it doesn't crash
|
// no asserts, just checking it doesn't crash
|
||||||
l := NewLogger("gaper-test")
|
l := newLogger("gaper-test")
|
||||||
l.Debug("debug")
|
l.Debug("debug")
|
||||||
l.Debugf("%s", "debug")
|
l.Debugf("%s", "debug")
|
||||||
l.Info("info")
|
l.Info("info")
|
||||||
|
@ -29,7 +29,7 @@ func TestLoggerRunAllLogsWithoutVerbose(t *testing.T) {
|
||||||
|
|
||||||
func TestLoggerRunAllLogsWithVerbose(t *testing.T) {
|
func TestLoggerRunAllLogsWithVerbose(t *testing.T) {
|
||||||
// no asserts, just checking it doesn't crash
|
// no asserts, just checking it doesn't crash
|
||||||
l := NewLogger("gaper-test")
|
l := newLogger("gaper-test")
|
||||||
l.Verbose(true)
|
l.Verbose(true)
|
||||||
l.Debug("debug")
|
l.Debug("debug")
|
||||||
l.Debugf("%s", "debug")
|
l.Debugf("%s", "debug")
|
||||||
|
|
|
@ -23,6 +23,7 @@ type Runner interface {
|
||||||
Kill() error
|
Kill() error
|
||||||
Errors() chan error
|
Errors() chan error
|
||||||
Exited() bool
|
Exited() bool
|
||||||
|
IsRunning() bool
|
||||||
ExitStatus(err error) int
|
ExitStatus(err error) int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +109,11 @@ func (r *runner) Exited() bool {
|
||||||
return r.command != nil && r.command.ProcessState != nil && r.command.ProcessState.Exited()
|
return r.command != nil && r.command.ProcessState != nil && r.command.ProcessState.Exited()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsRunning returns if the process is running
|
||||||
|
func (r *runner) IsRunning() bool {
|
||||||
|
return r.command != nil && r.command.Process != nil && r.command.Process.Pid > 0
|
||||||
|
}
|
||||||
|
|
||||||
// Errors get errors occurred during the build
|
// Errors get errors occurred during the build
|
||||||
func (r *runner) Errors() chan error {
|
func (r *runner) Errors() chan error {
|
||||||
return r.errors
|
return r.errors
|
||||||
|
|
|
@ -57,6 +57,12 @@ func (m *MockRunner) Exited() bool {
|
||||||
return args.Bool(0)
|
return args.Bool(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsRunning ...
|
||||||
|
func (m *MockRunner) IsRunning() bool {
|
||||||
|
args := m.Called()
|
||||||
|
return args.Bool(0)
|
||||||
|
}
|
||||||
|
|
||||||
// ExitStatus ...
|
// ExitStatus ...
|
||||||
func (m *MockRunner) ExitStatus(err error) int {
|
func (m *MockRunner) ExitStatus(err error) int {
|
||||||
args := m.Called()
|
args := m.Called()
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
sleep 2
|
sleep 3
|
||||||
echo "Gaper Test Message"
|
echo "Gaper Test Message"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
timeout 2 2>NUL
|
timeout 3 2>NUL
|
||||||
@echo Gaper Test Message
|
@echo Gaper Test Message
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
test
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var Version string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) // nolint gas
|
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) // nolint gas
|
||||||
|
@ -16,6 +18,6 @@ func main() {
|
||||||
log.Fatal("Forced failure")
|
log.Fatal("Forced failure")
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Println("Starting server")
|
log.Println("Starting server: Version", Version)
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
}
|
}
|
||||||
|
|
18
watcher.go
18
watcher.go
|
@ -117,6 +117,15 @@ func (w *watcher) scanChange(watchPath string) (string, error) {
|
||||||
var fileChanged string
|
var fileChanged string
|
||||||
|
|
||||||
err := filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error {
|
err := filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
// Ignore attempt to acess go temporary unmask
|
||||||
|
if strings.Contains(err.Error(), "-go-tmp-umask") {
|
||||||
|
return filepath.SkipDir
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("couldn't walk to path \"%s\": %v", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
if w.ignoreFile(path, info) {
|
if w.ignoreFile(path, info) {
|
||||||
return skipFile(info)
|
return skipFile(info)
|
||||||
}
|
}
|
||||||
|
@ -185,13 +194,14 @@ func resolvePaths(paths []string, extensions map[string]bool) (map[string]bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
// don't care for extension filter right now for non glob paths
|
// ignore existing files that don't match the allowed extensions
|
||||||
// since they could be a directory
|
if f, err := os.Stat(match); !os.IsNotExist(err) && !f.IsDir() {
|
||||||
if isGlob {
|
if ext := filepath.Ext(match); ext != "" {
|
||||||
if _, ok := extensions[filepath.Ext(match)]; !ok {
|
if _, ok := extensions[ext]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if _, ok := result[match]; !ok {
|
if _, ok := result[match]; !ok {
|
||||||
result[match] = true
|
result[match] = true
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package gaper
|
package gaper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -105,14 +104,19 @@ func TestWatcherWatchChange(t *testing.T) {
|
||||||
time.Sleep(time.Millisecond * 500)
|
time.Sleep(time.Millisecond * 500)
|
||||||
|
|
||||||
// update hidden files and dirs to check builtin hidden ignore is working
|
// update hidden files and dirs to check builtin hidden ignore is working
|
||||||
os.Chtimes(hiddenfile1, time.Now(), time.Now())
|
err = os.Chtimes(hiddenfile1, time.Now(), time.Now())
|
||||||
os.Chtimes(hiddenfile2, time.Now(), time.Now())
|
assert.Nil(t, err, "chtimes error")
|
||||||
|
|
||||||
|
err = os.Chtimes(hiddenfile2, time.Now(), time.Now())
|
||||||
|
assert.Nil(t, err, "chtimes error")
|
||||||
|
|
||||||
// update testfile first to check ignore is working
|
// update testfile first to check ignore is working
|
||||||
os.Chtimes(testfile, time.Now(), time.Now())
|
err = os.Chtimes(testfile, time.Now(), time.Now())
|
||||||
|
assert.Nil(t, err, "chtimes error")
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 500)
|
time.Sleep(time.Millisecond * 500)
|
||||||
os.Chtimes(mainfile, time.Now(), time.Now())
|
err = os.Chtimes(mainfile, time.Now(), time.Now())
|
||||||
|
assert.Nil(t, err, "chtimes error")
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case event := <-w.Events():
|
case event := <-w.Events():
|
||||||
|
@ -173,6 +177,11 @@ func TestWatcherIgnoreFile(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create vendor folder for testing
|
||||||
|
if err := os.MkdirAll("vendor", os.ModePerm); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
srvdir := "."
|
srvdir := "."
|
||||||
|
@ -198,12 +207,12 @@ func TestWatcherIgnoreFile(t *testing.T) {
|
||||||
filePath := tc.file
|
filePath := tc.file
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileInfo, err := file.Stat()
|
fileInfo, err := file.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, tc.expectIgnore, wt.ignoreFile(filePath, fileInfo))
|
assert.Equal(t, tc.expectIgnore, wt.ignoreFile(filePath, fileInfo))
|
||||||
|
|
Loading…
Reference in New Issue