Skip to content

Commit

Permalink
Merge pull request oxequa#177 from oxequa/develop
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
asoseil committed Apr 15, 2018
2 parents 13ee93c + 2bf6bc9 commit 7aba50d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 41 deletions.
4 changes: 2 additions & 2 deletions realize.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ func setup(c *cli.Context) (err error) {
Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool()
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
},
Expand All @@ -815,7 +815,7 @@ func setup(c *cli.Context) (err error) {
if err != nil {
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()
return nil
},
Expand Down
56 changes: 28 additions & 28 deletions realize/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ type Watch struct {
Paths []string `yaml:"paths" json:"paths"`
Scripts []Command `yaml:"scripts,omitempty" json:"scripts,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{
Exts []string `yaml:"exts,omitempty" json:"exts,omitempty"`
Paths []string `yaml:"paths,omitempty" json:"paths,omitempty"`
type Ignore struct {
Exts []string `yaml:"exts,omitempty" json:"exts,omitempty"`
Paths []string `yaml:"paths,omitempty" json:"paths,omitempty"`
}

// Command fields
Expand All @@ -49,22 +49,22 @@ type Command struct {

// Project info
type Project struct {
parent *Realize
watcher FileWatcher
stop chan bool
exit chan os.Signal
paths []string
last last
files int64
folders int64
init bool
Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"`
Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Tools Tools `yaml:"commands" json:"commands"`
Watcher Watch `yaml:"watcher" json:"watcher"`
Buffer Buffer `yaml:"-" json:"buffer"`
parent *Realize
watcher FileWatcher
stop chan bool
exit chan os.Signal
paths []string
last last
files int64
folders int64
init bool
Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"`
Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Tools Tools `yaml:"commands" json:"commands"`
Watcher Watch `yaml:"watcher" json:"watcher"`
Buffer Buffer `yaml:"-" json:"buffer"`
ErrPattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"`
}

Expand Down Expand Up @@ -352,28 +352,28 @@ func (p *Project) Validate(path string, fcheck bool) bool {
}
// check for a valid ext or path
if e := ext(path); e != "" {
if len(p.Watcher.Exts) == 0{
if len(p.Watcher.Exts) == 0 {
return false
}
// check ignored
for _, v := range p.Watcher.Ignore.Exts {
for _, v := range p.Watcher.Ignore {
if v == e {
return false
}
}
// supported extensions
for index, v := range p.Watcher.Exts{
for index, v := range p.Watcher.Exts {
if e == v {
break
}
if index == len(p.Watcher.Exts)-1{
if index == len(p.Watcher.Exts)-1 {
return false
}
}
}
separator := string(os.PathSeparator)
// supported paths
for _, v := range p.Watcher.Ignore.Paths {
for _, v := range p.Watcher.Ignore {
s := append([]string{p.Path}, strings.Split(v, separator)...)
abs, _ := filepath.Abs(filepath.Join(s...))
if path == abs || strings.HasPrefix(path, abs+separator) {
Expand All @@ -383,7 +383,7 @@ func (p *Project) Validate(path string, fcheck bool) bool {
// file check
if fcheck {
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
}
}
Expand Down Expand Up @@ -477,8 +477,8 @@ func (p *Project) cmd(stop <-chan bool, flag string, global bool) {
case <-done:
return
case r := <-result:
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold("Command"), Green.Bold("\"")+r.Name+Green.Bold("\""))
if r.Err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold("Command"), Green.Bold("\"")+r.Name+Green.Bold("\""))
if r.Err != nil {
out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: flag}
p.stamp("error", out, msg, fmt.Sprint(Red.Regular(r.Err.Error())))
} else {
Expand Down
8 changes: 3 additions & 5 deletions realize/projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ func TestProject_Validate(t *testing.T) {
r.Projects = append(r.Projects, Project{
parent: &r,
Watcher: Watch{
Exts: []string{},
Ignore: Ignore{
Paths:[]string{"/test/ignore"},
},
Exts: []string{},
Ignore: []string{"/test/ignore"},
},
})
for i, v := range data {
result := r.Projects[0].Validate(i, false)
if result != v {
if result != v {
t.Error("Unexpected error", i, "expected", v, result)
}
}
Expand Down
4 changes: 1 addition & 3 deletions realize/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func (s *Schema) New(c *cli.Context) Project {
Args: params(c),
Watcher: Watch{
Paths: []string{"/"},
Ignore: Ignore{
Paths:[]string{".git", ".realize", "vendor"},
},
Ignore: []string{".git", ".realize", "vendor"},
Exts: []string{"go"},
},
}
Expand Down
2 changes: 1 addition & 1 deletion realize/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"os/exec"
"runtime"
"strconv"
"github.com/go-siris/siris/core/errors"
"errors"
)

// Dafault host and port
Expand Down
2 changes: 1 addition & 1 deletion realize/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type Resource struct {
}

// 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.Interval = time.Duration(interval) * time.Second
}
Expand Down
2 changes: 1 addition & 1 deletion realize/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
cmd.Stderr = &stderr
// Start command
err := cmd.Start()
if err != nil{
if err != nil {
response.Name = t.name
response.Err = err
return
Expand Down

0 comments on commit 7aba50d

Please sign in to comment.