Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move test helpers around, start implementing ParseConfig

  • Loading branch information...
commit 1d3bd7725c29729643e3a8d408a8bfe5e70b5255 1 parent 582f8d6
@mrnugget authored
View
11 all_test.go
@@ -0,0 +1,11 @@
+package main
+
+import (
+ "path/filepath"
+ "runtime"
+)
+
+var (
+ _, filename, _, _ = runtime.Caller(0)
+ fixtures = filepath.Dir(filename) + "/fixtures"
+)
View
11 config.go
@@ -0,0 +1,11 @@
+package main
+
+type Rule struct {
+ Path string
+ Run string
+}
+
+func ParseConfig(path string) (rules []*Rule, err error) {
+ rules = make([]*Rule, 0)
+ return
+}
View
12 config_test.go
@@ -0,0 +1,12 @@
+package main
+
+import (
+ "testing"
+)
+
+func TestParseConfig(t *testing.T) {
+ _, err := ParseConfig(fixtures + "/example_config.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+}
View
7 dir_watcher_test.go
@@ -3,17 +3,10 @@ package main
import (
"io/ioutil"
"os"
- "path/filepath"
- "runtime"
"testing"
"time"
)
-var (
- _, filename, _, _ = runtime.Caller(0)
- fixtures = filepath.Dir(filename) + "/fixtures"
-)
-
func TestEvents(t *testing.T) {
sub1 := fixtures + "/sub1"
sub2 := fixtures + "/sub2"
View
8 fixtures/example_config.json
@@ -0,0 +1,8 @@
+{
+ "/tmp/foo": {
+ "run": "/usr/local/bar/foobar"
+ },
+ "/tmp/bar": {
+ "run": "/usr/local/bar/foobar"
+ }
+}
View
19 watchgopher.go
@@ -1,12 +1,27 @@
package main
+import (
+ "flag"
+ "fmt"
+ "os"
+)
+
func main() {
- // @TODO: Read configuration file either from `~/.watchgopher` or from
- // first command line argument
+ flag.Parse()
+ configPath := flag.Arg(0)
+ _, err := os.Stat(configPath)
+ if err != nil && os.IsNotExist(err) {
+ fmt.Println("Please pass the path to the config file to watchgopher")
+ os.Exit(1)
+ }
// @TODO: Parse configuration file to get which directories to watch,
// which pattern to match for which directory, which scripts to run on
// event
+ _, err = ParseConfig(configPath)
+ if err != nil {
+ fmt.Println("Error: Could not parse config file")
+ }
// @TODO: Watch directories for events (see `dir_watcher.go`) and pass
// events to a manager, which checks for appliance of configuration
Please sign in to comment.
Something went wrong with that request. Please try again.