Skip to content

Commit

Permalink
removing file extension restriction
Browse files Browse the repository at this point in the history
resolves #13

In order to do so, we have to have the ability to ignore certain files that were being generated by the .snag.yml (like the binary generated from 'go build').
ExcludeDirectory was therefore renamed to 'ignore' and behave simlarly to a .gitignore. You can list files or directories and both will be ignored
  • Loading branch information
zabawaba99 committed Aug 4, 2015
1 parent 125de90 commit 9fb0d95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .snag.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
verbose: true

exclude_directory:
ignore:
- .git
- snag

script:
- go build
Expand Down
30 changes: 8 additions & 22 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@ import (
fsn "gopkg.in/fsnotify.v1"
)

// supported file extensions
const (
GoExt = ".go"
JSONExt = ".json"
)

var (
mtimes = map[string]time.Time{}
buildExts = []string{GoExt, JSONExt}
)
var mtimes = map[string]time.Time{}

type Bob struct {
w *fsn.Watcher
mtx sync.RWMutex
curVow *vow.Vow
done chan struct{}
watching map[string]struct{}
watchDir string

cmds [][]string
excludedDirs []string
ignoredItems []string

verbose bool
}
Expand All @@ -54,7 +46,7 @@ func NewBuilder(c config) (*Bob, error) {
done: make(chan struct{}),
watching: map[string]struct{}{},
cmds: cmds,
excludedDirs: c.ExcludeDirectory,
ignoredItems: c.IgnoredItems,
verbose: c.Verbose,
}, nil
}
Expand All @@ -65,6 +57,7 @@ func (b *Bob) Close() {
}

func (b *Bob) Watch(path string) error {
b.watchDir = path
b.watch(path)
b.execute()

Expand Down Expand Up @@ -96,15 +89,8 @@ func (b *Bob) Watch(path string) error {
}

func (b *Bob) maybeQueue(path string) {
var found bool
for _, ext := range buildExts {
if filepath.Ext(path) == ext {
found = true
break
}
}

if !found {
relPath := strings.TrimPrefix(path, b.watchDir+"/")
if b.isExcluded(relPath) {
return
}

Expand Down Expand Up @@ -184,7 +170,7 @@ func (b *Bob) watch(path string) bool {
}

func (b *Bob) isExcluded(name string) bool {
for _, n := range b.excludedDirs {
for _, n := range b.ignoredItems {
if n == name {
return true
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
)

type config struct {
Script []string `yaml:"script"`
ExcludeDirectory []string `yaml:"exclude_directory"`
Verbose bool `yaml:"verbose"`
Script []string `yaml:"script"`
IgnoredItems []string `yaml:"ignore"`
Verbose bool `yaml:"verbose"`
}

func main() {
Expand Down

0 comments on commit 9fb0d95

Please sign in to comment.