Beispiel #1
0
func main() {
	flag.Parse()
	if *relaxed && *matching != "" {
		fmt.Fprintf(os.Stderr, "-r and -m at the same time don't make much sense.\n")
		os.Exit(1)
	}
	re := xurls.Strict
	if *relaxed {
		re = xurls.Relaxed
	} else if *matching != "" {
		var err error
		if re, err = xurls.StrictMatchingScheme(*matching); err != nil {
			fmt.Fprintf(os.Stderr, "invalid regular expression '%s': %v\n", *matching, err)
			os.Exit(1)
		}
	}
	args := flag.Args()
	if len(args) == 0 {
		scan(re, os.Stdin)
	}
	for _, path := range args {
		if path == "-" {
			scan(re, os.Stdin)
			continue
		}
		file, err := os.Open(path)
		if err != nil {
			fmt.Fprintf(os.Stdout, "could not open file '%s': %v\n", path, err)
			os.Exit(1)
		}
		scan(re, file)
		file.Close()
	}
}
Beispiel #2
0
func main() {
	flag.Parse()
	if *relaxed && *matching != "" {
		errExit(fmt.Errorf("-r and -m at the same time don't make much sense"))
	}
	re := xurls.Strict
	if *relaxed {
		re = xurls.Relaxed
	} else if *matching != "" {
		var err error
		if re, err = xurls.StrictMatchingScheme(*matching); err != nil {
			errExit(err)
		}
	}
	args := flag.Args()
	if len(args) == 0 {
		args = []string{"-"}
	}
	for _, path := range args {
		if err := scanPath(re, path); err != nil {
			errExit(err)
		}
	}
}