Skip to content

Commit

Permalink
🔨 Resolve #1: Add -skip-path option
Browse files Browse the repository at this point in the history
  • Loading branch information
dwisiswant0 committed Dec 13, 2020
1 parent cd78d75 commit 32da14b
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,33 @@ import (
"fmt"
"net/url"
"os"
"regexp"
"strings"
)

var combine bool
var outfile *os.File
var sc *bufio.Scanner
var replace, outtext, fr, fs string
type skipPaths []string

var (
combine bool
outfile *os.File
sc *bufio.Scanner
skipPath skipPaths
replace, outtext, fr, fs string
)

func (s *skipPaths) String() string {
return ""
}

func (s *skipPaths) Set(value string) error {
*s = append(*s, value)
return nil
}

func init() {
flag.StringVar(&replace, "r", "", "Replace parameters value")
flag.BoolVar(&combine, "combine", false, "Combine parameters")
flag.Var(&skipPath, "skip-path", "Skip specific paths (regExp pattern)")
flag.Parse()

fr := flag.Arg(0)
Expand Down Expand Up @@ -48,6 +64,10 @@ func main() {
continue
}

if matchPath(skipPath, u) {
continue
}

b := fmt.Sprintf("%s://%s%s", u.Scheme, u.Host, u.Path)

if _, d := urls[b]; d {
Expand Down Expand Up @@ -134,3 +154,18 @@ func qsReplace(q url.Values, r string) string {

return qs.Encode()
}

func matchPath(s []string, u *url.URL) bool {
for _, p := range s {
m, e := regexp.MatchString(p, u.Path)
if e != nil {
continue
}

if m {
return true
}
}

return false
}

0 comments on commit 32da14b

Please sign in to comment.