-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathhelp.go
132 lines (120 loc) · 3.43 KB
/
help.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// DISCLAIMER
//
// Copyright 2018-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package main
import (
"fmt"
"os"
"strings"
"github.com/fatih/color"
)
// --docker.container missing
func showDockerContainerNameMissingHelp() {
showFatalHelp(
"Cannot find docker container name.",
"",
"How to solve this:",
"1 - Add a commandline argument:",
"",
" `arangodb ... --docker.container=<name of container you run starter in>`",
"",
)
}
// --cluster.agency-size invalid.
func showClusterAgencySizeInvalidHelp() {
showFatalHelp(
"Cluster agency size is invalid cluster.agency-size needs to be a positive, odd number.",
"",
"How to solve this:",
"1 - Use a positive, odd number as agency size:",
"",
" `arangodb ... --cluster.agency-size=<1, 3 or 5...>`",
"",
)
}
// --cluster.agency-size=1 without specifying --starter.address.
func showClusterAgencySize1WithoutAddressHelp() {
showFatalHelp(
"With a cluster agency size of 1, a starter address is required.",
"",
"How to solve this:",
"1 - Add a commandline argument:",
"",
" `arangodb ... --starter.address=<IP address of current machine>`",
"",
)
}
// setting both --docker.image and --server.rr is not possible.
func showDockerImageWithRRIsNotAllowedHelp() {
showFatalHelp(
"Using RR is not possible with docker.",
"",
"How to solve this:",
"1 - Remove `--server.rr=...` commandline argument.",
"",
)
}
// setting both --docker.net-host and --docker.net-mode is not possible
func showDockerNetHostAndNotModeNotBothAllowedHelp() {
showFatalHelp(
"It is not allowed to set `--docker.net-host` and `--docker.net-mode` at the same time.",
"",
"How to solve this:",
"1 - Remove one of these two commandline arguments.",
"",
)
}
// Arangod is not found at given path.
func showArangodExecutableNotFoundHelp(arangodPath string) {
showFatalHelp(
fmt.Sprintf("Cannot find `arangod` (expected at `%s`).", arangodPath),
"",
"How to solve this:",
"1 - Install ArangoDB locally or run the ArangoDB starter in docker. (see README for details).",
"",
)
}
// cannnot specify both `--ssl.auto-key` and `--ssl.keyfile`
func showSslAutoKeyAndKeyFileNotBothAllowedHelp() {
showFatalHelp(
"Specifying both `--ssl.auto-key` and `--ssl.keyfile` is not allowed.",
"",
"How to solve this:",
"1 - Remove one of these two commandline arguments.",
"",
)
}
// showFatalHelp logs a title and prints additional usages
// underneeth and the exit with code 1.
// Backticks in the lines are colored yellow.
func showFatalHelp(title string, lines ...string) {
log.Error().Msg(highlight(title))
content := strings.Join(lines, "\n")
fmt.Println(highlight(content))
os.Exit(1)
}
func highlight(content string) string {
parts := strings.Split(content, "`")
for i, p := range parts {
if i%2 == 1 {
parts[i] = color.YellowString(p)
}
}
return strings.Join(parts, "")
}