diff --git a/go.mod b/go.mod index 670483a..8a47fc0 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/golang/mock v1.5.0 github.com/spf13/cobra v1.1.3 github.com/stretchr/testify v1.7.0 - go.octolab.org v0.11.5 + go.octolab.org v0.12.0 go.octolab.org/toolkit/cli v0.6.2 go.octolab.org/toolkit/config v0.0.4 ) diff --git a/go.sum b/go.sum index dfc70fe..ca1d40f 100644 --- a/go.sum +++ b/go.sum @@ -24,7 +24,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= -github.com/brianvoe/gofakeit/v6 v6.0.4/go.mod h1:palrJUk4Fyw38zIFB/uBZqsgzW5VsNllhHKKwAebzew= +github.com/brianvoe/gofakeit/v6 v6.4.1/go.mod h1:palrJUk4Fyw38zIFB/uBZqsgzW5VsNllhHKKwAebzew= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= @@ -194,8 +194,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.octolab.org v0.9.0/go.mod h1:nGTsvNE5SzxSriL/1u0xl5B+ttjIn9RzIbAhzaKE+Sk= -go.octolab.org v0.11.5 h1:zN+1dOTFpCmyJq5y0JhLy2bLu3TFEbILavjBx2wuI6A= -go.octolab.org v0.11.5/go.mod h1:Hl97oqUCvkbdBpFhsU3zUOl3WSkdRUqYab9zwbHCLJY= +go.octolab.org v0.12.0 h1:NZrvpJvcREBheb3m0ZXvlQbDSHyA6gA352iT37k2+20= +go.octolab.org v0.12.0/go.mod h1:TEYR7HOfImJq8AsoCcl9JBK+80t4QBY4EilGxMtscNE= go.octolab.org/toolkit/cli v0.6.2 h1:oRUvE1T1wAuglqcggKg/F8djTTsRvTwr2eFeJvL6ExE= go.octolab.org/toolkit/cli v0.6.2/go.mod h1:iEL6yN6YT3/Sbi19Tl38mn4agRr2yUyiNvbN29iqb/U= go.octolab.org/toolkit/config v0.0.4 h1:Q/MnSuRf4ttHCuAaq7PqpD8xQhEtmfK8mO9NX1IxvlA= diff --git a/internal/cmd/demo/panic.go b/internal/cmd/demo/panic.go new file mode 100644 index 0000000..61c5ff0 --- /dev/null +++ b/internal/cmd/demo/panic.go @@ -0,0 +1,19 @@ +package demo + +import "github.com/spf13/cobra" + +// Panic returns a demo cobra.Command to raise a panic. +// +// $ go run main.go panic +// +func Panic() *cobra.Command { + command := cobra.Command{ + Use: "panic", + Args: cobra.NoArgs, + Run: func(cmd *cobra.Command, args []string) { + panic("unexpected panic") + }, + } + + return &command +} diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 16a19e9..dd138f3 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -1,6 +1,10 @@ package cmd -import "github.com/spf13/cobra" +import ( + "github.com/spf13/cobra" + + "tool/internal/cmd/demo" +) // New returns the new root command. func New() *cobra.Command { @@ -14,7 +18,11 @@ func New() *cobra.Command { SilenceErrors: false, SilenceUsage: true, } + /* configure instance */ - command.AddCommand( /* related commands */ ) + command.AddCommand( + demo.Panic(), + ) + return &command } diff --git a/main.go b/main.go index c8a1749..80779a7 100644 --- a/main.go +++ b/main.go @@ -50,7 +50,8 @@ func main() { } func shutdown(err error) { - if recovered, is := errors.Unwrap(err).(errors.Recovered); is { + var recovered errors.Recovered + if errors.As(err, &recovered) { unsafe.DoSilent(fmt.Fprintf(stderr, "recovered: %+v\n", recovered.Cause())) unsafe.DoSilent(fmt.Fprintln(stderr, "---")) unsafe.DoSilent(fmt.Fprintf(stderr, "%+v\n", err))