@cryptotaxi247 / kubo / commits / 08c75aa79

fix `ipfs help` bug

License: MIT Signed-off-by: Kejie Zhang <601172892@qq.com>

Kejie Zhang committed Oct 9, 2018 at 10:52 UTC 08c75aa795ac570e2ef5d46b731750029ad6e0bb
5 files changed +68 -8
cmd/ipfs/main.go
+14 -5
@@ -82,13 +82,22 @@ func mainRet() int {
82 intrh, ctx := setupInterruptHandler(ctx)
83 defer intrh.Close()
84
85 - // Handle `ipfs help'
86 - if len(os.Args) == 2 {
87 - if os.Args[1] == "help" {
88 - os.Args[1] = "-h"
89 - } else if os.Args[1] == "--version" {
85 + // Handle `ipfs version` or `ipfs help`
86 + if len(os.Args) > 1 {
87 + // Handle `ipfs --version'
88 + if os.Args[1] == "--version" {
89 os.Args[1] = "version"
90 }
91 +
92 + //Handle `ipfs help` and `ipfs help <sub-command>`
93 + if os.Args[1] == "help" {
94 + if len(os.Args) > 2 {
95 + os.Args = append(os.Args[:1], os.Args[2:]...)
96 + os.Args = append(os.Args, "-h")
97 + } else {
98 + os.Args[1] = "-h"
99 + }
100 + }
101 }
102
103 // output depends on executable name passed in os.Args
test/sharness/t0010-basic-commands.sh
+10
@@ -51,6 +51,16 @@ test_expect_success "ipfs help output looks good" '
51 test_fsh cat help.txt
52 '
53
54 +test_expect_success "ipfs help --help succeeds" '
55 + ipfs help --help >help.txt
56 +'
57 +
58 +test_expect_success "ipfs help --help output looks good" '
59 + egrep -i "^Usage" help.txt >/dev/null &&
60 + egrep "ipfs <command>" help.txt >/dev/null ||
61 + test_fsh cat help.txt
62 +'
63 +
64 test_expect_success "'ipfs commands' succeeds" '
65 ipfs commands >commands.txt
66 '
test/sharness/t0040-add-and-cat.sh
+30 -3
@@ -10,12 +10,21 @@ test_description="Test add and cat commands"
10
11 test_add_cat_file() {
12 test_expect_success "ipfs add --help works" '
13 - ipfs add --help 2> add_help_err > /dev/null
13 + ipfs add --help 2> add_help_err1 > /dev/null
14 '
15
16 test_expect_success "stdin reading message doesnt show up" '
17 - test_expect_code 1 grep "ipfs: Reading from" add_help_err &&
18 - test_expect_code 1 grep "send Ctrl-d to stop." add_help_err
17 + test_expect_code 1 grep "ipfs: Reading from" add_help_err1 &&
18 + test_expect_code 1 grep "send Ctrl-d to stop." add_help_err1
19 + '
20 +
21 + test_expect_success "ipfs help add works" '
22 + ipfs help add 2> add_help_err2 > /dev/null
23 + '
24 +
25 + test_expect_success "stdin reading message doesnt show up" '
26 + test_expect_code 1 grep "ipfs: Reading from" add_help_err2 &&
27 + test_expect_code 1 grep "send Ctrl-d to stop." add_help_err2
28 '
29
30 test_expect_success "ipfs add succeeds" '
@@ -431,6 +440,15 @@ test_expect_success "'ipfs add --help' output looks good" '
440 test_fsh cat actual
441 '
442
443 +test_expect_success "'ipfs help add' succeeds" '
444 + ipfs help add >actual
445 +'
446 +
447 +test_expect_success "'ipfs help add' output looks good" '
448 + egrep "ipfs add.*<path>" actual >/dev/null ||
449 + test_fsh cat actual
450 +'
451 +
452 test_expect_success "'ipfs cat --help' succeeds" '
453 ipfs cat --help >actual
454 '
@@ -440,6 +458,15 @@ test_expect_success "'ipfs cat --help' output looks good" '
458 test_fsh cat actual
459 '
460
461 +test_expect_success "'ipfs help cat' succeeds" '
462 + ipfs help cat >actual
463 +'
464 +
465 +test_expect_success "'ipfs help cat' output looks good" '
466 + egrep "ipfs cat.*<ipfs-path>" actual >/dev/null ||
467 + test_fsh cat actual
468 +'
469 +
470 test_add_cat_file
471
472 test_expect_success "ipfs cat succeeds with stdin opened (issue #1141)" '
test/sharness/t0060-daemon.sh
+10
@@ -80,6 +80,16 @@ test_expect_success "ipfs help output looks good" '
80 test_fsh cat help.txt
81 '
82
83 +test_expect_success "ipfs help --help succeeds" '
84 + ipfs help --help >help.txt
85 +'
86 +
87 +test_expect_success "ipfs help --help output looks good" '
88 + egrep -i "^Usage" help.txt >/dev/null &&
89 + egrep "ipfs .* <command>" help.txt >/dev/null ||
90 + test_fsh cat help.txt
91 +'
92 +
93 # netcat (nc) is needed for the following test
94 test_expect_success "nc is available" '
95 type nc >/dev/null
test/sharness/t0100-name.sh
+4
@@ -158,6 +158,10 @@ test_expect_success "'ipfs name publish --help' succeeds" '
158 ipfs name publish --help
159 '
160
161 +test_expect_success "'ipfs help name publish' succeeds" '
162 + ipfs help name publish
163 +'
164 +
165 test_launch_ipfs_daemon
166
167 test_expect_success "empty request to name publish doesn't panic and returns error" '