forked from calinpristavu/future-proofing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskip.go
More file actions
60 lines (47 loc) · 1.18 KB
/
skip.go
File metadata and controls
60 lines (47 loc) · 1.18 KB
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
package main
import (
"log"
"strings"
"github.com/spf13/cobra"
)
var skip = &cobra.Command{
Use: "skip",
Short: "Skips a rector ruleset",
Long: `Edits the rector.php file to mark a ruleset as skipped`,
Run: func(cmd *cobra.Command, args []string) {
if !isSkipArgumentValid(args) {
log.Fatalf("Invalid or missing argument! Example: \\\\Rector\\\\Set\\\\ValueObject\\\\LevelSetList::UP_TO_PHP_81::class\n")
}
file, lines, err := loadRectorFile()
if err != nil {
log.Fatalf(err.Error())
}
defer file.Close()
skipInjectionPoint, err := findLineIndexFor(lines, skipsMethod)
if err != nil {
lines = injectSkipMethod(lines, args[0])
if err := writeRectorFile(file, lines); err != nil {
log.Fatalf(err.Error())
}
return
}
lines = injectLine(lines, skipInjectionPoint, args[0])
if err := writeRectorFile(file, lines); err != nil {
log.Fatalf(err.Error())
}
},
}
func isSkipArgumentValid(args []string) bool {
// there should be an argument
if len(args) == 0 {
return false
}
if !strings.Contains(args[0], "::") {
return false
}
// argument must have a namespace
if !strings.Contains(args[0], "\\") {
return false
}
return true
}