Skip to content

Commit 86783de

Browse files
committed
Add help command
1 parent b1697e6 commit 86783de

6 files changed

Lines changed: 30 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Usage:
4242
boring close, c Close tunnels (same options as 'open')
4343
boring edit, e Edit the configuration file
4444
boring version, v Show the version number
45+
boring help, h Show this help message
4546
```
4647

4748
## Configuration

cmd/boring/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func main() {
5454
editConfig()
5555
case "version", "v":
5656
printVersion()
57+
case "help", "h":
58+
printUsage()
5759
default:
5860
log.Printf("Unknown command: %v\n\n", os.Args[1])
5961
printUsage()
@@ -102,4 +104,5 @@ func printUsage() {
102104
log.Printf(" boring close, c Close tunnels (same options as 'open')\n")
103105
log.Printf(" boring edit, e Edit the configuration file\n")
104106
log.Printf(" boring version, v Show the version number\n")
107+
log.Printf(" boring help, h Show this help message\n")
105108
}

completions/boring.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ _boring() {
33
cur="${COMP_WORDS[COMP_CWORD]}"
44
prev="${COMP_WORDS[COMP_CWORD-1]}"
55

6-
local commands=("open" "close" "list" "edit" "version")
6+
local commands=("open" "close" "list" "edit" "version" "help")
77

88
_boring_get_names() {
99
local status="$1"

completions/boring.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function __boring_complete
3434
set arguments (commandline -opc)[3..-1]
3535

3636
if test (count $command) -eq 0
37-
printf "%s\n" open close list edit version
37+
printf "%s\n" open close list edit version help
3838
return
3939
end
4040

completions/boring.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _boring() {
88
"list"
99
"edit"
1010
"version"
11+
"help"
1112
)
1213

1314
_boring_get_names() {

test/e2e/usage_test.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66
)
77

8-
func TestUsage(t *testing.T) {
8+
func TestUsagePlain(t *testing.T) {
99
env, err := makeDefaultEnv(t)
1010
if err != nil {
1111
t.Fatalf("%v", err.Error())
@@ -23,13 +23,31 @@ func TestUsage(t *testing.T) {
2323
}
2424
}
2525

26-
func TestUsageWithCommand(t *testing.T) {
26+
func TestUsageHelp(t *testing.T) {
2727
env, err := makeDefaultEnv(t)
2828
if err != nil {
2929
t.Fatalf("%v", err.Error())
3030
}
3131

32-
c, out, err := cliCommand(env, "help") // or any other unknown command
32+
c, out, err := cliCommand(env, "help")
33+
if err != nil {
34+
t.Fatalf("failed to run CLI command: %v", err)
35+
}
36+
if c != 0 {
37+
t.Fatalf("exit code %d: %v", c, err)
38+
}
39+
if !strings.Contains(out, "Usage:") {
40+
t.Errorf("output did not contain usage information: %s", out)
41+
}
42+
}
43+
44+
func TestUsageUnknownCommand(t *testing.T) {
45+
env, err := makeDefaultEnv(t)
46+
if err != nil {
47+
t.Fatalf("%v", err.Error())
48+
}
49+
50+
c, out, err := cliCommand(env, "foo") // or any other unknown command
3351
if err != nil {
3452
t.Fatalf("failed to run CLI command: %v", err)
3553
}
@@ -39,7 +57,8 @@ func TestUsageWithCommand(t *testing.T) {
3957
if !strings.Contains(out, "Usage:") {
4058
t.Errorf("output did not contain usage information: %s", out)
4159
}
42-
if !strings.Contains(out, "Unknown command: help") {
60+
if !strings.Contains(out, "Unknown command: foo") {
4361
t.Errorf("output did not contain unknown command warning: %s", out)
4462
}
4563
}
64+

0 commit comments

Comments
 (0)