#160 fixed
This commit is contained in:
parent
0cc05cff1f
commit
e1ec6e46c4
|
@ -38,6 +38,7 @@ func main() {
|
|||
&cli.BoolFlag{Name: "install", Aliases: []string{"i"}, Value: false, Usage: "Enable go install"},
|
||||
&cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build"},
|
||||
&cli.BoolFlag{Name: "run", Aliases: []string{"nr"}, Value: false, Usage: "Enable go run"},
|
||||
&cli.BoolFlag{Name: "legacy", Aliases: []string{"l"}, Value: false, Usage: "Legacy watch by polling instead fsnotify"},
|
||||
&cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing config and doesn't create a new one"},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
|
@ -1117,6 +1118,10 @@ func setup(c *cli.Context) (err error) {
|
|||
// Start realize workflow
|
||||
func start(c *cli.Context) (err error) {
|
||||
r.Server = realize.Server{Parent: &r, Status: false, Open: false, Port: realize.Port, Host: realize.Host}
|
||||
// set legacy watcher
|
||||
if c.Bool("legacy"){
|
||||
r.Settings.Legacy.Set(1)
|
||||
}
|
||||
// check no-config and read
|
||||
if !c.Bool("no-config") {
|
||||
// read a config if exist
|
||||
|
|
|
@ -18,7 +18,7 @@ var (
|
|||
// RPrefix tool name
|
||||
RPrefix = "realize"
|
||||
// RVersion current version
|
||||
RVersion = "2.0.1"
|
||||
RVersion = "2.1"
|
||||
// RExt file extension
|
||||
RExt = ".yaml"
|
||||
// RFile config file name
|
||||
|
|
|
@ -2,7 +2,7 @@ package realize
|
|||
|
||||
// this code is imported from moby, unfortunately i can't import it directly as dependencies from its repo,
|
||||
// cause there was a problem between moby vendor and fsnotify
|
||||
// i have just added only walk methods and some little changes to polling interval, originally set as static.
|
||||
// i have just added only the walk methods and some little changes to polling interval, originally set as static.
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -57,7 +57,7 @@ type (
|
|||
// PollingWatcher returns a poll-based file watcher
|
||||
func PollingWatcher(interval time.Duration) FileWatcher {
|
||||
if interval == 0 {
|
||||
interval = 100 * time.Millisecond
|
||||
interval = time.Duration(1) * time.Second
|
||||
}
|
||||
return &filePoller{
|
||||
interval: interval,
|
||||
|
@ -67,13 +67,13 @@ func PollingWatcher(interval time.Duration) FileWatcher {
|
|||
}
|
||||
|
||||
// NewFileWatcher tries to use an fs-event watcher, and falls back to the poller if there is an error
|
||||
func NewFileWatcher(force bool, interval time.Duration) (FileWatcher, error) {
|
||||
if !force {
|
||||
func NewFileWatcher(l Legacy) (FileWatcher, error) {
|
||||
if !l.Force {
|
||||
if w, err := EventWatcher(); err == nil {
|
||||
return w, nil
|
||||
}
|
||||
}
|
||||
return PollingWatcher(interval), nil
|
||||
return PollingWatcher(l.Interval), nil
|
||||
}
|
||||
|
||||
// EventWatcher returns an fs-event based file watcher
|
||||
|
|
|
@ -274,7 +274,7 @@ func (p *Project) Watch(wg *sync.WaitGroup) {
|
|||
// change channel
|
||||
p.stop = make(chan bool)
|
||||
// init a new watcher
|
||||
p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy.Force, p.parent.Settings.Legacy.Interval)
|
||||
p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -100,7 +100,9 @@ func TestProject_Reload(t *testing.T) {
|
|||
parent: &r,
|
||||
})
|
||||
input := "test/path"
|
||||
r.Projects[0].watcher, _ = NewFileWatcher(false, 0)
|
||||
r.Settings.Legacy.Force = false
|
||||
r.Settings.Legacy.Interval = 0
|
||||
r.Projects[0].watcher, _ = NewFileWatcher(r.Settings.Legacy)
|
||||
r.Reload = func(context Context) {
|
||||
log.Println(context.Path)
|
||||
}
|
||||
|
|
|
@ -61,6 +61,17 @@ type Resource struct {
|
|||
Name string
|
||||
}
|
||||
|
||||
// Set legacy watcher with an interval
|
||||
func (l *Legacy) Set(interval int){
|
||||
l.Force = true
|
||||
l.Interval = time.Duration(interval) * time.Second
|
||||
}
|
||||
|
||||
// Unset legacy watcher
|
||||
func (l *Legacy) Unset(){
|
||||
l.Force = false
|
||||
}
|
||||
|
||||
// Remove realize folder
|
||||
func (s *Settings) Remove(d string) error {
|
||||
_, err := os.Stat(d)
|
||||
|
|
Loading…
Reference in New Issue