Skip to content

Commit

Permalink
Support for Attrib inside conf struct; removed short version of --att…
Browse files Browse the repository at this point in the history
…rib.
  • Loading branch information
Janne Jalkanen committed Feb 3, 2016
1 parent ae0e715 commit 0c5ffef
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -28,7 +28,7 @@ Flags:
-s, --suffixes=SUFFIXES
File suffixes to watch.
-c, --config=CONFIG JSON configuration location
-b, --attrib Also listen to changes to file attributes.
--attrib Also listen to changes to file attributes.
--version Show application version.
```

Expand All @@ -55,7 +55,8 @@ Create json file with content, with name for example conf.json
{
"ignore": ["some/path/to/ignore1", "some/path/to/ignore2"],
"args": ["dev", "test"],
"suffixes": [".go", ".html", ".tpl"]
"suffixes": [".go", ".html", ".tpl"],
"attrib": true
}
```
and then
Expand Down Expand Up @@ -109,7 +110,7 @@ If you are using Vagrant as your development environment, the edited changes do

Then, watch the files with

rerun -b -c conf.json
rerun --attrib -c conf.json

# License
MIT
5 changes: 4 additions & 1 deletion conf.go
Expand Up @@ -18,13 +18,14 @@ var (
args = kingpin.Flag("args", "Application arguments.").Default("").Short('a').String()
suffixes = kingpin.Flag("suffixes", "File suffixes to watch.").Short('s').String()
confPath = kingpin.Flag("config", "JSON configuration location").Short('c').String()
attrib = kingpin.Flag("attrib", "Also watch attribute changes").Short('b').Bool()
attrib = kingpin.Flag("attrib", "Also watch attribute changes").Bool()
)

type config struct {
Ignore []string
Args []string
Suffixes []string
Attrib bool
build string
}

Expand Down Expand Up @@ -93,5 +94,7 @@ func loadConfiguration() (*config, error) {
conf.Ignore = parseGlobs(conf.Ignore)
conf.Ignore = convertAbsolutes(conf.Ignore)

conf.Attrib = *attrib

return conf, nil
}
3 changes: 3 additions & 0 deletions conf_test.go
Expand Up @@ -24,6 +24,7 @@ func TestParseConfWithCliArgs(t *testing.T) {
*ignore = "path1,path2"
*args = "arg1,arg2"
*suffixes = ".go,.html"
*attrib = true

cnf, err := loadConfiguration()
assert.Nil(t, err, "Error should not happen if file is ok")
Expand All @@ -35,4 +36,6 @@ func TestParseConfWithCliArgs(t *testing.T) {
assert.True(t, contains([]string{pathPrefix + "/path1", pathPrefix + "/path2"}, cnf.Ignore[1]))
AssertArraysEq(t, []string{"arg1", "arg2"}, cnf.Args)
AssertArraysEq(t, []string{".go", ".html"}, cnf.Suffixes)

assert.True(t, cnf.Attrib)
}
2 changes: 1 addition & 1 deletion watcher.go
Expand Up @@ -25,7 +25,7 @@ func (w *watcher) isEventImportant(ev fsnotify.Event) bool {
return false
}

importantEvent := ev.Op == fsnotify.Write || ev.Op == fsnotify.Rename || ev.Op == fsnotify.Remove || (*attrib && ev.Op == fsnotify.Chmod)
importantEvent := ev.Op == fsnotify.Write || ev.Op == fsnotify.Rename || ev.Op == fsnotify.Remove || (w.pm.conf.Attrib && ev.Op == fsnotify.Chmod)
if !importantEvent {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion watcher_test.go
Expand Up @@ -31,7 +31,7 @@ func TestIsFileImportant(t *testing.T) {
assert.False(t, watcher.isEventImportant(event))

// Test attrib event in case settings are different
*attrib = true
pm.conf.Attrib = true
event = fsnotify.Event{"some/file.go", fsnotify.Chmod}
assert.True(t, watcher.isEventImportant(event))

Expand Down

0 comments on commit 0c5ffef

Please sign in to comment.