Skip to content

Commit 08e7e4f

Browse files
author
Matthew Fisher
committed
Merge pull request #3898 from Joshua-Anderson/deisctl-cleanup
ref(deisctl): clean up some parsing and error behavior
2 parents 4bd8ceb + 697163e commit 08e7e4f

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

deisctl/deisctl.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ Options:
6060
argv, helpFlag := parseArgs(argv)
6161
// give docopt an optional final false arg so it doesn't call os.Exit()
6262
args, err := docopt.Parse(usage, argv, false, version.Version, true, false)
63-
if err != nil || len(args) == 0 {
64-
if helpFlag {
65-
fmt.Print(usage)
66-
return 0
67-
} else if argv[0] == "--version" {
68-
return 0
69-
}
63+
64+
if err != nil && err.Error() != "" {
65+
fmt.Println(err)
7066
return 1
7167
}
68+
69+
if len(args) == 0 {
70+
return 0
71+
}
72+
7273
command := args["<command>"]
7374
setTunnel := true
7475
// "--help" and "refresh-units" doesn't need SSH tunneling

deisctl/deisctl_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bytes"
5+
"fmt"
56
"io"
67
"os"
78
"strings"
@@ -47,8 +48,9 @@ func TestHelp(t *testing.T) {
4748
// TestUsage ensures that deisctl prints a short usage string when no arguments were provided.
4849
func TestUsage(t *testing.T) {
4950
out := commandOutput(nil)
50-
if out != "Usage: deisctl [options] <command> [<args>...]\n" {
51-
t.Error(out)
51+
expected := "Usage: deisctl [options] <command> [<args>...]\n"
52+
if out != expected {
53+
t.Error(fmt.Errorf("Expected '%s', Got '%s'", expected, out))
5254
}
5355
}
5456

0 commit comments

Comments
 (0)