Skip to content

Commit c837c7e

Browse files
committed
More extended help
1 parent 8fd7919 commit c837c7e

File tree

2 files changed

+86
-11
lines changed

2 files changed

+86
-11
lines changed

help.go

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,79 @@ import (
3030
"github.com/fatih/color"
3131
)
3232

33-
// --sync.server.keyfile
33+
// --docker.container missing
34+
func showDockerContainerNameMissingHelp() {
35+
showFatalHelp(
36+
"Cannot find docker container name.",
37+
"",
38+
"How to solve this:",
39+
"1 - Add a commandline argument:",
40+
"",
41+
" `arangodb ... --docker.container=<name of container you run starter in>`",
42+
"",
43+
)
44+
}
45+
46+
// --cluster.agency-size invalid.
47+
func showClusterAgencySizeInvalidHelp() {
48+
showFatalHelp(
49+
"Cluster agency size is invalid cluster.agency-size needs to be a positive, odd number.",
50+
"",
51+
"How to solve this:",
52+
"1 - Use a positive, odd number as agency size:",
53+
"",
54+
" `arangodb ... --cluster.agency-size=<1, 3 or 5...>`",
55+
"",
56+
)
57+
}
58+
59+
// --cluster.agency-size=1 without specifying --starter.address.
60+
func showClusterAgencySize1WithoutAddressHelp() {
61+
showFatalHelp(
62+
"With a cluster agency size of 1, a starter address is required.",
63+
"",
64+
"How to solve this:",
65+
"1 - Add a commandline argument:",
66+
"",
67+
" `arangodb ... --starter.address=<IP address of current machine>`",
68+
"",
69+
)
70+
}
71+
72+
// setting both --docker.image and --server.rr is not possible.
73+
func showDockerImageWithRRIsNotAllowedHelp() {
74+
showFatalHelp(
75+
"Using RR is not possible with docker.",
76+
"",
77+
"How to solve this:",
78+
"1 - Remove `--server.rr=...` commandline argument.",
79+
"",
80+
)
81+
}
82+
83+
// setting both --docker.net-host and --docker.net-mode is not possible
84+
func showDockerNetHostAndNotModeNotBothAllowedHelp() {
85+
showFatalHelp(
86+
"It is not allowed to set `--docker.net-host` and `--docker.net-mode` at the same time.",
87+
"",
88+
"How to solve this:",
89+
"1 - Remove one of these two commandline arguments.",
90+
"",
91+
)
92+
}
93+
94+
// Arangod is not found at given path.
95+
func showArangodExecutableNotFoundHelp(arangodPath string) {
96+
showFatalHelp(
97+
fmt.Sprintf("Cannot find `arangod` (expected at `%s`).", arangodPath),
98+
"",
99+
"How to solve this:",
100+
"1 - Install ArangoDB locally or run the ArangoDB starter in docker. (see RADME for details).",
101+
"",
102+
)
103+
}
104+
105+
// --sync.server.keyfile is missing
34106
func showSyncMasterServerKeyfileMissingHelp() {
35107
showFatalHelp(
36108
"A TLS certificate used for the HTTPS connection of the arangosync syncmaster is missing.",
@@ -78,14 +150,18 @@ func showSyncMasterClientCAFileMissingHelp() {
78150
// underneeth and the exit with code 1.
79151
// Backticks in the lines are colored yellow.
80152
func showFatalHelp(title string, lines ...string) {
81-
log.Error(title)
153+
log.Error(highlight(title))
82154
content := strings.Join(lines, "\n")
155+
fmt.Println(highlight(content))
156+
os.Exit(1)
157+
}
158+
159+
func highlight(content string) string {
83160
parts := strings.Split(content, "`")
84161
for i, p := range parts {
85162
if i%2 == 1 {
86163
parts[i] = color.YellowString(p)
87164
}
88165
}
89-
fmt.Println(strings.Join(parts, ""))
90-
os.Exit(1)
166+
return strings.Join(parts, "")
91167
}

main.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo
461461
info, err := findDockerContainerInfo(dockerEndpoint)
462462
if err != nil {
463463
if dockerContainerName == "" {
464-
log.Fatalf("Cannot find docker container name. Please specify using --dockerContainer=...")
464+
showDockerContainerNameMissingHelp()
465465
}
466466
} else {
467467
if dockerContainerName == "" {
@@ -475,19 +475,19 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo
475475

476476
// Some plausibility checks:
477477
if agencySize%2 == 0 || agencySize <= 0 {
478-
log.Fatal("Error: cluster.agency-size needs to be a positive, odd number.")
478+
showClusterAgencySizeInvalidHelp()
479479
}
480480
if agencySize == 1 && ownAddress == "" {
481-
log.Fatal("Error: if cluster.agency-size==1, starter.address must be given.")
481+
showClusterAgencySize1WithoutAddressHelp()
482482
}
483483
if dockerArangodImage != "" && rrPath != "" {
484-
log.Fatal("Error: using --docker.image and --server.rr is not possible.")
484+
showDockerImageWithRRIsNotAllowedHelp()
485485
}
486486
if dockerNetHost {
487487
if dockerNetworkMode == "" {
488488
dockerNetworkMode = "host"
489489
} else if dockerNetworkMode != "host" {
490-
log.Fatal("Error: cannot set --docker.net-host and --docker.net-mode at the same time")
490+
showDockerNetHostAndNotModeNotBothAllowedHelp()
491491
}
492492
}
493493
imagePullPolicy, err := service.ParseImagePullPolicy(dockerImagePullPolicy, dockerArangodImage)
@@ -509,8 +509,7 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo
509509
// Check database executable
510510
if !runningInDocker {
511511
if _, err := os.Stat(arangodPath); os.IsNotExist(err) {
512-
log.Errorf("Cannot find arangod (expected at %s).", arangodPath)
513-
log.Fatal("Please install ArangoDB locally or run the ArangoDB starter in docker (see README for details).")
512+
showArangodExecutableNotFoundHelp(arangodPath)
514513
}
515514
log.Debugf("Using %s as default arangod executable.", arangodPath)
516515
log.Debugf("Using %s as default JS dir.", arangodJSPath)

0 commit comments

Comments
 (0)