summarylogtreecommitdiffstats
path: root/cli-output.patch
blob: e14547869c9b405a96e29e937757e843313dd14b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
--- b/dashing.go	2017-01-05 14:48:00.403357303 -0600
+++ c/dashing.go	2017-01-05 15:32:17.327116746 -0600
@@ -74,13 +74,8 @@
 // Transform structs.
 type Transform struct {
 	Type        string
-
-	// Perform a replace operation on the text
 	Regexp      *regexp.Regexp
 	Replacement string
-
-	// Skip files that don't match this path
-	MatchPath		*regexp.Regexp
 }
 
 var ignoreHash map[string]bool
@@ -128,7 +123,7 @@
 		{
 			Name:   "version",
 			Usage:  "Print version and exit.",
-			Action: func(c *cli.Context) error { fmt.Println(version);return nil },
+			Action: func(c *cli.Context) { fmt.Println(version) },
 			Flags: []cli.Flag{
 				cli.StringFlag{
 					Name:  "config, f",
@@ -139,7 +134,7 @@
 	}
 }
 
-func create(c *cli.Context) error {
+func create(c *cli.Context) {
 	f := c.String("config")
 	if len(f) == 0 {
 		f = "dashing.json"
@@ -160,14 +155,14 @@
 	}
 	err = ioutil.WriteFile(f, j, 0755)
 	if err != nil {
-		fmt.Errorf("Could not initialize JSON file: %s", err)
+		fmt.Errorf("Could not initialize JSON file: %s\n", err)
 		os.Exit(1)
 	}
-	fmt.Printf("You may now edit %s", f)
-	return nil
+	fmt.Printf("You may now edit %s\n", f)
+
 }
 
-func build(c *cli.Context) error {
+func build(c *cli.Context) {
 	var dashing Dashing
 
 	source_depth := 0
@@ -212,11 +207,10 @@
 	db, err := createDB(name)
 	if err != nil {
 		fmt.Printf("Failed to create database: %s\n", err)
-		return nil
+		return
 	}
 	defer db.Close()
 	texasRanger(source, source_depth, name, dashing, db)
-	return nil
 }
 
 func decodeSelectField(d *Dashing) error {
@@ -230,37 +224,30 @@
 			}
 		} else if rv.Kind() == reflect.Map {
 			val := val.(map[string]interface{})
-			var ttype, trep string
-			var creg, cmatchpath *regexp.Regexp
-			var err error
-
-			if r, ok := val["type"]; ok {
-				ttype = r.(string)
+			var ttype, treg, trep string
+			if t, ok := val["type"]; ok {
+				ttype = t.(string)
 			}
 			if r, ok := val["regexp"]; ok {
-				creg, err = regexp.Compile(r.(string))
-				if err != nil {
-					return fmt.Errorf("failed to compile regexp '%s': %s", r.(string), err)
-				}
+				treg = r.(string)
 			}
 			if r, ok := val["replacement"]; ok {
 				trep = r.(string)
 			}
-			if r, ok := val["matchpath"]; ok {
-				cmatchpath, err = regexp.Compile(r.(string))
-				if err != nil {
-					return fmt.Errorf("failed to compile regexp '%s': %s", r.(string), err)
+			var creg *regexp.Regexp
+			var err error
+			if len(treg) > 0 {
+				if creg, err = regexp.Compile(treg); err != nil {
+					return fmt.Errorf("failed to compile regexp '%s': %s", treg, err)
 				}
 			}
 			trans = &Transform{
 				Type:        ttype,
 				Regexp:      creg,
 				Replacement: trep,
-				MatchPath:   cmatchpath,
 			}
 		} else {
 			fmt.Errorf("Expected string or map. Kind is %s.", rv.Kind().String())
-			return nil
 		}
 		d.selectors[sel] = trans
 	}
@@ -454,11 +441,6 @@
 	}
 
 	for pattern, sel := range dashing.selectors {
-		// Skip this selector if file path doesn't match
-		if sel.MatchPath != nil && ! sel.MatchPath.MatchString(path) {
-			continue
-		}
-
 		m := css.MustCompile(pattern)
 		found := m.MatchAll(top)
 		for _, n := range found {