diff --git a/go.mod b/go.mod index 55a6fd6..6a43ca2 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module mvdan.cc/unparam go 1.22.0 require ( - github.com/rogpeppe/go-internal v1.12.0 - golang.org/x/tools v0.25.0 + github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a + golang.org/x/tools v0.26.0 ) require ( golang.org/x/mod v0.21.0 // indirect golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.25.0 // indirect + golang.org/x/sys v0.26.0 // indirect ) diff --git a/go.sum b/go.sum index 28f5a78..3959cf0 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,10 @@ -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a h1:w3tdWGKbLGBPtR/8/oO74W6hmz0qE5q0z9aqSAewaaM= +github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a/go.mod h1:S8kfXMp+yh77OxPD4fdM6YUknrZpQxLhvxzS4gDHENY= golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= -golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE= -golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= +golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= diff --git a/main.go b/main.go index 08cca48..fb761f5 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( ) var ( - flagSet = flag.NewFlagSet("unparam", flag.ContinueOnError) + flagSet = flag.NewFlagSet("unparam", flag.ExitOnError) tests = flagSet.Bool("tests", false, "load tests too") exported = flagSet.Bool("exported", false, "inspect exported functions") @@ -21,30 +21,20 @@ var ( ) func main() { - os.Exit(main1()) -} - -func main1() int { flagSet.Usage = func() { fmt.Fprintln(os.Stderr, "usage: unparam [flags] [package ...]") flagSet.PrintDefaults() } - if err := flagSet.Parse(os.Args[1:]); err != nil { - if err != flag.ErrHelp { - fmt.Fprintln(os.Stderr, err) - } - return 1 - } + flagSet.Parse(os.Args[1:]) warns, err := check.UnusedParams(*tests, *exported, *debug, flagSet.Args()...) if err != nil { fmt.Fprintln(os.Stderr, err) - return 1 + os.Exit(1) } for _, warn := range warns { fmt.Println(warn) } if len(warns) > 0 { - return 1 + os.Exit(1) } - return 0 } diff --git a/main_test.go b/main_test.go index a1b578a..ad5f492 100644 --- a/main_test.go +++ b/main_test.go @@ -10,9 +10,9 @@ import ( ) func TestMain(m *testing.M) { - os.Exit(testscript.RunMain(m, map[string]func() int{ - "unparam": main1, - })) + testscript.Main(m, map[string]func(){ + "unparam": main, + }) } func TestScript(t *testing.T) { diff --git a/testdata/script/cmds.txtar b/testdata/script/cmds.txtar index fab1fb9..80f7ad6 100644 --- a/testdata/script/cmds.txtar +++ b/testdata/script/cmds.txtar @@ -1,4 +1,4 @@ -! exec unparam -h +exec unparam -h stderr '^usage: unparam \[flags' ! stderr 'test\.' # don't include flags from testing ! stderr 'command not specified'