File tree Expand file tree Collapse file tree 4 files changed +12
-8
lines changed Expand file tree Collapse file tree 4 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 53
53
exit = os .Exit
54
54
)
55
55
56
+ // SetExitFunc sets the function used to exit the program (by default os.Exit)
57
+ // and returns the previous value.
58
+ func SetExitFunc (fn func (code int )) (previous func (int )) {
59
+ previous = exit
60
+ exit = fn
61
+ return previous
62
+ }
63
+
56
64
// Complete the command line arguments for the given command in the case that the program
57
65
// was invoked with COMP_LINE and COMP_POINT environment variables. In that case it will also
58
66
// `os.Exit()`. The program name should be provided for installation purposes.
Original file line number Diff line number Diff line change 1
1
module github.com/posener/complete/v2
2
2
3
3
require (
4
- bou.ke/monkey v1.0.2
5
4
github.com/hashicorp/go-multierror v1.0.0
6
5
github.com/posener/autogen v0.0.2
7
6
github.com/posener/script v1.1.5
Original file line number Diff line number Diff line change 1
- bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI =
2
- bou.ke/monkey v1.0.2 /go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA =
3
1
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 =
4
2
github.com/davecgh/go-spew v1.1.0 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
5
3
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA =
6
4
github.com/hashicorp/errwrap v1.0.0 /go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4 =
7
5
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o =
8
6
github.com/hashicorp/go-multierror v1.0.0 /go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk =
9
- github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I =
10
7
github.com/pkg/errors v0.8.1 /go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0 =
11
8
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
12
9
github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import (
11
11
"strings"
12
12
"testing"
13
13
14
- "bou.ke/monkey"
15
14
"github.com/posener/complete/v2"
16
15
)
17
16
@@ -53,8 +52,8 @@ func TestPredictions(t *testing.T) {
53
52
func BenchmarkFake (b * testing.B ) {}
54
53
55
54
func Example () {
56
- p := monkey . Patch ( os . Exit , func (int ) {})
57
- defer p . Unpatch ( )
55
+ p := complete . SetExitFunc ( func (int ) {})
56
+ defer complete . SetExitFunc ( p )
58
57
os .Setenv ("COMP_LINE" , "go ru" )
59
58
os .Setenv ("COMP_POINT" , "5" )
60
59
main ()
@@ -76,7 +75,8 @@ func equal(s1, s2 []string) bool {
76
75
}
77
76
78
77
func TestErrorSupression (t * testing.T ) {
79
- defer monkey .Patch (os .Exit , func (int ) {}).Unpatch ()
78
+ p := complete .SetExitFunc (func (int ) {})
79
+ defer complete .SetExitFunc (p )
80
80
81
81
// Completion API environment variable names.
82
82
const envLine , envPoint = "COMP_LINE" , "COMP_POINT"
You can’t perform that action at this time.
0 commit comments