Skip to content

Commit

Permalink
remove unnecessary testscript exit status
Browse files Browse the repository at this point in the history
unnecessary since rogpeppe/go-internal#201
  • Loading branch information
sentriz committed Feb 21, 2024
1 parent cc3f405 commit c9f9e4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
31 changes: 12 additions & 19 deletions cliphist.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,23 @@ import (
//go:embed version.txt
var version string

// allow us to test main
func main() { os.Exit(main_()) }
func main_() int {
flags := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
flags.Usage = func() {
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage:\n")
fmt.Fprintf(os.Stderr, " $ %s <store|list|decode|delete|delete-query|wipe|version>\n", os.Args[0])
fmt.Fprintf(os.Stderr, "options:\n")
flags.VisitAll(func(f *flag.Flag) {
flag.VisitAll(func(f *flag.Flag) {
fmt.Fprintf(os.Stderr, " -%s (default %s)\n", f.Name, f.DefValue)
fmt.Fprintf(os.Stderr, " %s\n", f.Usage)
})
}

maxItems := flags.Uint64("max-items", 750, "maximum number of items to store")
maxDedupeSearch := flags.Uint64("max-dedupe-search", 100, "maximum number of last items to look through when finding duplicates")

if err := flags.Parse(os.Args[1:]); err != nil {
return 1
}
maxItems := flag.Uint64("max-items", 750, "maximum number of items to store")
maxDedupeSearch := flag.Uint64("max-dedupe-search", 100, "maximum number of last items to look through when finding duplicates")
flag.Parse()

var err error
switch flags.Arg(0) {
switch flag.Arg(0) {
case "store":
switch os.Getenv("CLIPBOARD_STATE") { // from man wl-clipboard
case "sensitive":
Expand All @@ -62,24 +56,23 @@ func main_() int {
case "list":
err = list(os.Stdout)
case "decode":
err = decode(os.Stdin, os.Stdout, flags.Arg(1))
err = decode(os.Stdin, os.Stdout, flag.Arg(1))
case "delete-query":
err = deleteQuery(flags.Arg(1))
err = deleteQuery(flag.Arg(1))
case "delete":
err = delete(os.Stdin)
case "wipe":
err = wipe()
case "version":
fmt.Fprint(os.Stderr, version)
default:
flags.Usage()
return 1
flag.Usage()
os.Exit(1)
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
os.Exit(1)
}
return 0
}

func store(in io.Reader, maxDedupeSearch, maxItems uint64) error {
Expand Down
2 changes: 1 addition & 1 deletion cliphist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestMain(m *testing.M) {
testImage := image.NewRGBA(image.Rectangle{Max: image.Point{20, 20}})

os.Exit(testscript.RunMain(m, map[string]func() int{
"cliphist": main_,
"cliphist": func() int { main(); return 0 },

"rand": func() int {
size, _ := strconv.Atoi(os.Args[1])
Expand Down

0 comments on commit c9f9e4b

Please sign in to comment.