File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -93,8 +93,13 @@ func Run(args []string) (err error) {
93
93
94
94
args = CleanUpArgs (args )
95
95
96
- if len (args ) == 1 && (args [0 ] == "-V" || args [0 ] == "--version" ) {
97
- args = []string {"version" }
96
+ if len (args ) == 1 {
97
+ switch args [0 ] {
98
+ case "-V" , "--version" :
99
+ args = []string {"version" }
100
+ case "help" :
101
+ args = []string {"--help" }
102
+ }
98
103
}
99
104
100
105
var warnOnce sync.Once
Original file line number Diff line number Diff line change 9
9
"encoding/json"
10
10
"flag"
11
11
"fmt"
12
+ "io"
12
13
"net/netip"
13
14
"reflect"
14
15
"strings"
@@ -1480,3 +1481,33 @@ func TestParseNLArgs(t *testing.T) {
1480
1481
})
1481
1482
}
1482
1483
}
1484
+
1485
+ func TestHelpAlias (t * testing.T ) {
1486
+ var stdout , stderr bytes.Buffer
1487
+ tstest .Replace [io.Writer ](t , & Stdout , & stdout )
1488
+ tstest .Replace [io.Writer ](t , & Stderr , & stderr )
1489
+
1490
+ gotExit0 := false
1491
+ defer func () {
1492
+ if ! gotExit0 {
1493
+ t .Error ("expected os.Exit(0) to be called" )
1494
+ return
1495
+ }
1496
+ if ! strings .Contains (stderr .String (), "SUBCOMMANDS" ) {
1497
+ t .Errorf ("expected help output to contain SUBCOMMANDS; got stderr=%q; stdout=%q" , stderr .String (), stdout .String ())
1498
+ }
1499
+ }()
1500
+ defer func () {
1501
+ if e := recover (); e != nil {
1502
+ if strings .Contains (fmt .Sprint (e ), "unexpected call to os.Exit(0)" ) {
1503
+ gotExit0 = true
1504
+ } else {
1505
+ t .Errorf ("unexpected panic: %v" , e )
1506
+ }
1507
+ }
1508
+ }()
1509
+ err := Run ([]string {"help" })
1510
+ if err != nil {
1511
+ t .Fatalf ("Run: %v" , err )
1512
+ }
1513
+ }
You can’t perform that action at this time.
0 commit comments