diff --git a/realize.go b/realize.go index d44ceb8..76b06ca 100644 --- a/realize.go +++ b/realize.go @@ -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 = r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore[:len(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore)-1] + r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths = r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths[:len(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths)-1] } return val }, @@ -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 = append(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore, val) + r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths = append(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths, val) d.Reload() return nil }, @@ -1128,7 +1128,10 @@ func start(c *cli.Context) (err error) { // check no-config and read if !c.Bool("no-config") { // read a config if exist - r.Settings.Read(&r) + err := r.Settings.Read(&r) + if err != nil{ + return err + } if c.String("name") != "" { // filter by name flag if exist r.Schema.Projects = r.Schema.Filter("Name", c.String("name")) @@ -1143,6 +1146,7 @@ func start(c *cli.Context) (err error) { } // check project list length if len(r.Schema.Projects) <= 0 { + println("len",r.Schema.Projects) // create a new project based on given params project := r.Schema.New(c) // Add to projects list diff --git a/realize/projects.go b/realize/projects.go index 6772ec3..144a83e 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -28,7 +28,8 @@ var ( type Watch struct { Paths []string `yaml:"paths" json:"paths"` Exts []string `yaml:"extensions" json:"extensions"` - Ignore []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"` + IgnoredExts []string `yaml:"ignored_extensions,omitempty" json:"ignored_extensions,omitempty"` + IgnoredPaths []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"` Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"` Hidden bool `yaml:"skip_hidden,omitempty" json:"skip_hidden,omitempty"` } @@ -347,14 +348,24 @@ func (p *Project) Validate(path string, fcheck bool) bool { } // check for a valid ext or path if e := ext(path); e != "" { - // supported exts - if !array(e, p.Watcher.Exts) { - return false + for _, v := range p.Watcher.IgnoredExts { + if v == e { + return false + } + } + // supported extensions + for index, v := range p.Watcher.Exts{ + if e == v { + break + } + if index == len(p.Watcher.Exts)-1{ + return false + } } } separator := string(os.PathSeparator) // supported paths - for _, v := range p.Watcher.Ignore { + for _, v := range p.Watcher.IgnoredPaths { s := append([]string{p.Path}, strings.Split(v, separator)...) abs, _ := filepath.Abs(filepath.Join(s...)) if path == abs || strings.HasPrefix(path, abs+separator) { diff --git a/realize/projects_test.go b/realize/projects_test.go index bdba2e1..763fd06 100644 --- a/realize/projects_test.go +++ b/realize/projects_test.go @@ -128,7 +128,8 @@ func TestProject_Validate(t *testing.T) { r.Projects = append(r.Projects, Project{ parent: &r, Watcher: Watch{ - Ignore: []string{"/test/ignore"}, + Exts: []string{"go","html"}, + IgnoredPaths: []string{"/test/ignore"}, }, }) for i, v := range data { diff --git a/realize/schema.go b/realize/schema.go index 36cedf1..38974f0 100644 --- a/realize/schema.go +++ b/realize/schema.go @@ -68,7 +68,7 @@ func (s *Schema) New(c *cli.Context) Project { Args: params(c), Watcher: Watch{ Paths: []string{"/"}, - Ignore: []string{".git", ".realize", "vendor"}, + IgnoredPaths: []string{".git", ".realize", "vendor"}, Exts: []string{"go"}, }, } diff --git a/realize/utils.go b/realize/utils.go index 72da59e..30ed600 100644 --- a/realize/utils.go +++ b/realize/utils.go @@ -8,16 +8,6 @@ import ( "strings" ) -// Array check if a string is in given array -func array(str string, list []string) bool { - for _, v := range list { - if v == str { - return true - } - } - return false -} - // Params parse one by one the given argumentes func params(params *cli.Context) []string { argsN := params.NArg() diff --git a/realize/utils_test.go b/realize/utils_test.go index b0d2b07..0018295 100644 --- a/realize/utils_test.go +++ b/realize/utils_test.go @@ -43,16 +43,6 @@ func TestDuplicates(t *testing.T) { } -func TestArray(t *testing.T) { - arr := []string{"a", "b", "c"} - if !array(arr[0], arr) { - t.Fatal("Unexpected", arr[0], "should be in", arr) - } - if array("d", arr) { - t.Fatal("Unexpected", "d", "shouldn't be in", arr) - } -} - func TestWdir(t *testing.T) { expected, err := os.Getwd() if err != nil {