package main import ( "strconv" "strings" ) // popBool removes every occurrence of the given flag spellings from args and // reports whether any were present. func popBool(args []string, names ...string) (bool, []string) { var rest []string found := false for _, a := range args { if contains(names, a) { found = true continue } rest = append(rest, a) } return found, rest } func contains(ss []string, s string) bool { for _, x := range ss { if x == s { return true } } return false } // parseClip pulls pass-style clipboard flags out of args: -c / --clip copy the // first line; --clip=N or -cN copy line N (1-based). func parseClip(args []string) (clip bool, line int, rest []string) { line = 1 for _, a := range args { switch { case a == "-c" || a == "--clip": clip = true case strings.HasPrefix(a, "--clip="): clip = true if n, err := strconv.Atoi(a[len("--clip="):]); err == nil && n > 0 { line = n } case strings.HasPrefix(a, "-c") && len(a) > 2: clip = true if n, err := strconv.Atoi(a[2:]); err == nil && n > 0 { line = n } default: rest = append(rest, a) } } return clip, line, rest } func atoiDefault(s string, def int) int { if n, err := strconv.Atoi(s); err == nil { return n } return def }