Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func main() {
Value: "gin-bin",
Usage: "name of generated binary file",
},
cli.StringSliceFlag{
Name: "ext,e",
Usage: "Use ext to specify the file extensions to listen to.",
Value: &cli.StringSlice{".go"},
},
cli.StringFlag{
Name: "path,t",
Value: ".",
Expand Down Expand Up @@ -116,7 +121,7 @@ func MainAction(c *cli.Context) {
build(builder, runner, logger)

// scan for changes
scanChanges(c.GlobalString("path"), func(path string) {
scanChanges(c.GlobalString("path"), c.GlobalStringSlice("ext"), func(path string) {
runner.Kill()
build(builder, runner, logger)
})
Expand Down Expand Up @@ -157,7 +162,16 @@ func build(builder gin.Builder, runner gin.Runner, logger *log.Logger) {

type scanCallback func(path string)

func scanChanges(watchPath string, cb scanCallback) {
func in(str string, arr []string) bool {
for _, v := range arr {
if v == str {
return true
}
}
return false
}

func scanChanges(watchPath string, ext []string, cb scanCallback) {
for {
filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error {
if path == ".git" {
Expand All @@ -169,7 +183,7 @@ func scanChanges(watchPath string, cb scanCallback) {
return nil
}

if filepath.Ext(path) == ".go" && info.ModTime().After(startTime) {
if in(filepath.Ext(path), ext) && info.ModTime().After(startTime) {
cb(path)
startTime = time.Now()
return errors.New("done")
Expand Down