This commit is contained in:
asoseil 2018-04-15 19:26:18 +02:00
parent f0e28d1602
commit 6ba5a47b0e
7 changed files with 38 additions and 43 deletions

View File

@ -795,7 +795,7 @@ func setup(c *cli.Context) (err error) {
Resolve: func(d interact.Context) bool { Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool() val, _ := d.Ans().Bool()
if val { if val {
r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore.Paths = r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore.Paths[:len(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore.Paths)-1] r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore = r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore[:len(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore)-1]
} }
return val return val
}, },
@ -815,7 +815,7 @@ func setup(c *cli.Context) (err error) {
if err != nil { if err != nil {
return d.Err() return d.Err()
} }
r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore.Paths = append(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore.Paths, val) r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore = append(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore, val)
d.Reload() d.Reload()
return nil return nil
}, },

View File

@ -30,12 +30,12 @@ type Watch struct {
Paths []string `yaml:"paths" json:"paths"` Paths []string `yaml:"paths" json:"paths"`
Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"` Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"`
Hidden bool `yaml:"hidden,omitempty" json:"hidden,omitempty"` Hidden bool `yaml:"hidden,omitempty" json:"hidden,omitempty"`
Ignore Ignore `yaml:"ignore,omitempty" json:"ignore,omitempty"` Ignore []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"`
} }
type Ignore struct{ type Ignore struct {
Exts []string `yaml:"exts,omitempty" json:"exts,omitempty"` Exts []string `yaml:"exts,omitempty" json:"exts,omitempty"`
Paths []string `yaml:"paths,omitempty" json:"paths,omitempty"` Paths []string `yaml:"paths,omitempty" json:"paths,omitempty"`
} }
// Command fields // Command fields
@ -49,27 +49,27 @@ type Command struct {
// Project info // Project info
type Project struct { type Project struct {
parent *Realize parent *Realize
watcher FileWatcher watcher FileWatcher
stop chan bool stop chan bool
exit chan os.Signal exit chan os.Signal
paths []string paths []string
last last last last
files int64 files int64
folders int64 folders int64
init bool init bool
Name string `yaml:"name" json:"name"` Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"` Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
Args []string `yaml:"args,omitempty" json:"args,omitempty"` Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Tools Tools `yaml:"commands" json:"commands"` Tools Tools `yaml:"commands" json:"commands"`
Watcher Watch `yaml:"watcher" json:"watcher"` Watcher Watch `yaml:"watcher" json:"watcher"`
Buffer Buffer `yaml:"-" json:"buffer"` Buffer Buffer `yaml:"-" json:"buffer"`
ErrPattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"` ErrPattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"`
} }
// Last is used to save info about last file changed // Last is used to save info about last file changed
type last struct{ type last struct {
file string file string
time time.Time time time.Time
} }
@ -352,28 +352,28 @@ func (p *Project) Validate(path string, fcheck bool) bool {
} }
// check for a valid ext or path // check for a valid ext or path
if e := ext(path); e != "" { if e := ext(path); e != "" {
if len(p.Watcher.Exts) == 0{ if len(p.Watcher.Exts) == 0 {
return false return false
} }
// check ignored // check ignored
for _, v := range p.Watcher.Ignore.Exts { for _, v := range p.Watcher.Ignore {
if v == e { if v == e {
return false return false
} }
} }
// supported extensions // supported extensions
for index, v := range p.Watcher.Exts{ for index, v := range p.Watcher.Exts {
if e == v { if e == v {
break break
} }
if index == len(p.Watcher.Exts)-1{ if index == len(p.Watcher.Exts)-1 {
return false return false
} }
} }
} }
separator := string(os.PathSeparator) separator := string(os.PathSeparator)
// supported paths // supported paths
for _, v := range p.Watcher.Ignore.Paths { for _, v := range p.Watcher.Ignore {
s := append([]string{p.Path}, strings.Split(v, separator)...) s := append([]string{p.Path}, strings.Split(v, separator)...)
abs, _ := filepath.Abs(filepath.Join(s...)) abs, _ := filepath.Abs(filepath.Join(s...))
if path == abs || strings.HasPrefix(path, abs+separator) { if path == abs || strings.HasPrefix(path, abs+separator) {
@ -383,7 +383,7 @@ func (p *Project) Validate(path string, fcheck bool) bool {
// file check // file check
if fcheck { if fcheck {
fi, err := os.Stat(path) fi, err := os.Stat(path)
if err != nil || fi.Mode()&os.ModeSymlink != 0 || !fi.IsDir() && ext(path) == "" || fi.Size() <= 0{ if err != nil || fi.Mode()&os.ModeSymlink != 0 || !fi.IsDir() && ext(path) == "" || fi.Size() <= 0 {
return false return false
} }
} }
@ -477,8 +477,8 @@ func (p *Project) cmd(stop <-chan bool, flag string, global bool) {
case <-done: case <-done:
return return
case r := <-result: case r := <-result:
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold("Command"), Green.Bold("\"")+r.Name+Green.Bold("\"")) msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold("Command"), Green.Bold("\"")+r.Name+Green.Bold("\""))
if r.Err != nil { if r.Err != nil {
out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: flag} out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: flag}
p.stamp("error", out, msg, fmt.Sprint(Red.Regular(r.Err.Error()))) p.stamp("error", out, msg, fmt.Sprint(Red.Regular(r.Err.Error())))
} else { } else {
@ -495,7 +495,7 @@ func (p *Project) walk(path string, info os.FileInfo, err error) error {
result := p.watcher.Walk(path, p.init) result := p.watcher.Walk(path, p.init)
if result != "" { if result != "" {
if p.parent.Settings.Recovery.Index { if p.parent.Settings.Recovery.Index {
log.Println("Indexing",path) log.Println("Indexing", path)
} }
p.tools(p.stop, path, info) p.tools(p.stop, path, info)
if info.IsDir() { if info.IsDir() {

View File

@ -128,15 +128,13 @@ func TestProject_Validate(t *testing.T) {
r.Projects = append(r.Projects, Project{ r.Projects = append(r.Projects, Project{
parent: &r, parent: &r,
Watcher: Watch{ Watcher: Watch{
Exts: []string{}, Exts: []string{},
Ignore: Ignore{ Ignore: []string{"/test/ignore"},
Paths:[]string{"/test/ignore"},
},
}, },
}) })
for i, v := range data { for i, v := range data {
result := r.Projects[0].Validate(i, false) result := r.Projects[0].Validate(i, false)
if result != v { if result != v {
t.Error("Unexpected error", i, "expected", v, result) t.Error("Unexpected error", i, "expected", v, result)
} }
} }

View File

@ -68,9 +68,7 @@ func (s *Schema) New(c *cli.Context) Project {
Args: params(c), Args: params(c),
Watcher: Watch{ Watcher: Watch{
Paths: []string{"/"}, Paths: []string{"/"},
Ignore: Ignore{ Ignore: []string{".git", ".realize", "vendor"},
Paths:[]string{".git", ".realize", "vendor"},
},
Exts: []string{"go"}, Exts: []string{"go"},
}, },
} }

View File

@ -14,7 +14,6 @@ import (
"os/exec" "os/exec"
"runtime" "runtime"
"strconv" "strconv"
"github.com/go-siris/siris/core/errors"
) )
// Dafault host and port // Dafault host and port

View File

@ -62,7 +62,7 @@ type Resource struct {
} }
// Set legacy watcher with an interval // Set legacy watcher with an interval
func (l *Legacy) Set(status bool, interval int){ func (l *Legacy) Set(status bool, interval int) {
l.Force = true l.Force = true
l.Interval = time.Duration(interval) * time.Second l.Interval = time.Duration(interval) * time.Second
} }

View File

@ -135,7 +135,7 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
cmd.Stderr = &stderr cmd.Stderr = &stderr
// Start command // Start command
err := cmd.Start() err := cmd.Start()
if err != nil{ if err != nil {
response.Name = t.name response.Name = t.name
response.Err = err response.Err = err
return return