Compare commits

...

4 Commits

Author SHA1 Message Date
Max Claus Nunes 1fde6281f1 Ignore go-tmp-unmask
Closes https://github.com/maxcnunes/gaper/issues/13
2022-08-07 10:47:30 -03:00
Max Claus Nunes 95fc7d2127 Update cli to v2 2022-08-07 10:40:15 -03:00
Max Claus Nunes b0dcdd49b0 Add extensions example 2022-08-07 10:30:58 -03:00
Max Claus Nunes 39d9c0ad64 Support multiple extensions with comma
Closes https://github.com/maxcnunes/gaper/issues/17
2022-08-07 10:10:24 -03:00
8 changed files with 63 additions and 42 deletions

View File

@ -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 --build-args="-ldflags=\"-X 'main.Version=v1.0.0'\"" 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

View File

@ -44,7 +44,7 @@ func TestBuilderFailureBuild(t *testing.T) {
assert.Equal(t, err.Error(), "build failed with exit status 2\n"+ assert.Equal(t, err.Error(), "build failed with exit status 2\n"+
"# github.com/maxcnunes/gaper/testdata/build-failure\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) {

View File

@ -4,14 +4,14 @@ 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.3-dev" version = "1.0.3-dev"
) )
@ -41,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(loggerVerbose) 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" +

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"strings"
"syscall" "syscall"
"time" "time"
@ -208,6 +209,15 @@ 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], ",")
for _, e := range values {
extensions = append(extensions, e)
}
}
cfg.Extensions = extensions
return nil return nil
} }

6
go.mod
View File

@ -3,14 +3,14 @@ module github.com/maxcnunes/gaper
go 1.13 go 1.13
require ( require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/fatih/color v1.7.0 github.com/fatih/color v1.7.0
github.com/mattn/go-colorable v0.0.9 // indirect github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.3 // indirect github.com/mattn/go-isatty v0.0.3 // indirect
github.com/mattn/go-shellwords v1.0.3 github.com/mattn/go-shellwords v1.0.3
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3 github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3
github.com/stretchr/objx v0.1.1 // indirect github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.2.2 github.com/stretchr/testify v1.4.0
github.com/urfave/cli v1.22.2 github.com/urfave/cli/v2 v2.11.1
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3 // indirect golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
) )

29
go.sum
View File

@ -1,6 +1,6 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 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 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
@ -15,17 +15,24 @@ github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3 h1:GWnsQiFbiQ7lREZb
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo= 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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= 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/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= github.com/urfave/cli/v2 v2.11.1 h1:UKK6SP7fV3eKOefbS87iT9YHefv7iB/53ih6e+GNAsE=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 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 h1:FCfAlbS73+IQQJktaKGHldMdL2bGDVpm+OrCEbVz1f4=
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 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/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.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=

1
testdata/server/data.txt vendored Normal file
View File

@ -0,0 +1 @@
test

View File

@ -118,6 +118,11 @@ func (w *watcher) scanChange(watchPath string) (string, error) {
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 { 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) return fmt.Errorf("couldn't walk to path \"%s\": %v", path, err)
} }