@@ -24,9 +24,7 @@ type commandErrorCase struct {
24
24
func TestErrorExamples (t * testing.T ) {
25
25
t .Parallel ()
26
26
27
- var root cli.RootCmd
28
- rootCmd ,err := root .Command (root .AGPL ())
29
- require .NoError (t ,err )
27
+ rootCmd := getRoot (t )
30
28
31
29
var cases []commandErrorCase
32
30
@@ -52,8 +50,7 @@ ExtractCommandPathsLoop:
52
50
53
51
var outBuf bytes.Buffer
54
52
55
- rootCmd ,err := root .Command (root .AGPL ())
56
- require .NoError (t ,err )
53
+ rootCmd := getRoot (t )
57
54
58
55
inv ,_ := clitest .NewWithCommand (t ,rootCmd ,tt .Cmd ... )
59
56
inv .Stderr = & outBuf
@@ -65,7 +62,7 @@ ExtractCommandPathsLoop:
65
62
inv .Stdin = os .Stdin
66
63
}
67
64
68
- err = inv .Run ()
65
+ err : =inv .Run ()
69
66
70
67
errFormatter := cli .ExportNewPrettyErrorFormatter (& outBuf ,false )
71
68
cli .ExportFormat (errFormatter ,err )
@@ -84,3 +81,14 @@ func extractCommandPaths(cmdPath []string, cmds []*serpent.Command) [][]string {
84
81
}
85
82
return cmdPaths
86
83
}
84
+
85
+ // Must return a fresh instance of cmds each time.
86
+ func getRoot (t * testing.T )* serpent.Command {
87
+ t .Helper ()
88
+
89
+ var root cli.RootCmd
90
+ rootCmd ,err := root .Command (root .AGPL ())
91
+ require .NoError (t ,err )
92
+
93
+ return rootCmd
94
+ }