Skip to content

Commit c353c4a

Browse files
authored
Merge pull request #347 from arangodb-helper/sync-deprecated-flags-hint
GT-324 Fix help message when passing deprecated pass-through args
2 parents 6eaf220 + b9be057 commit c353c4a

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Fix restarting cluster with arangosync enabled
55
- Upgrade Go to v1.19.4 to fix CVEs
66
- Fix passing-through boolean flags to arangosync
7+
- Improve deprecated notice for old passthrough flags
78

89
## [0.15.5](https://github.com/arangodb-helper/arangodb/tree/0.15.5) (2022-09-19)
910
- Fix project CI: linter, tests, build, release

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ func init() {
218218
}
219219

220220
f.StringSliceVar(flag.Value, flag.CleanKey, nil, flag.Usage)
221-
if flag.Deprecated {
222-
f.MarkDeprecated(flag.CleanKey, "Deprecated")
221+
if flag.DeprecatedHint != "" {
222+
f.MarkDeprecated(flag.CleanKey, flag.DeprecatedHint)
223223
}
224224
}
225225

options.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
125125
FieldSelector: func(p *options.Configuration, key string) *[]string {
126126
return p.ArgByProcessTypeAndName(definitions.ServerTypeAgent, key)
127127
},
128-
Deprecated: true,
128+
DeprecatedHintFormat: "use --args.all.%s instead",
129129
},
130130
"coordinators": {
131131
Usage: func(key string) string {
@@ -134,7 +134,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
134134
FieldSelector: func(p *options.Configuration, key string) *[]string {
135135
return p.ArgByServerTypeAndName(definitions.ServerTypeCoordinator, key)
136136
},
137-
Deprecated: true,
137+
DeprecatedHintFormat: "use --args.coordinators.%s instead",
138138
},
139139
"dbservers": {
140140
Usage: func(key string) string {
@@ -143,7 +143,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
143143
FieldSelector: func(p *options.Configuration, key string) *[]string {
144144
return p.ArgByServerTypeAndName(definitions.ServerTypeDBServer, key)
145145
},
146-
Deprecated: true,
146+
DeprecatedHintFormat: "use --args.dbservers.%s instead",
147147
},
148148
"agents": {
149149
Usage: func(key string) string {
@@ -152,7 +152,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
152152
FieldSelector: func(p *options.Configuration, key string) *[]string {
153153
return p.ArgByServerTypeAndName(definitions.ServerTypeAgent, key)
154154
},
155-
Deprecated: true,
155+
DeprecatedHintFormat: "use --args.agents.%s instead",
156156
},
157157
"sync": {
158158
Usage: func(key string) string {
@@ -161,7 +161,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
161161
FieldSelector: func(p *options.Configuration, key string) *[]string {
162162
return p.ArgByProcessTypeAndName(definitions.ServerTypeSyncMaster, key)
163163
},
164-
Deprecated: true,
164+
DeprecatedHintFormat: "use --args.sync.%s instead",
165165
},
166166
"syncmasters": {
167167
Usage: func(key string) string {
@@ -170,7 +170,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
170170
FieldSelector: func(p *options.Configuration, key string) *[]string {
171171
return p.ArgByServerTypeAndName(definitions.ServerTypeSyncMaster, key)
172172
},
173-
Deprecated: true,
173+
DeprecatedHintFormat: "use --args.syncmasters.%s instead",
174174
},
175175
"syncworkers": {
176176
Usage: func(key string) string {
@@ -179,7 +179,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
179179
FieldSelector: func(p *options.Configuration, key string) *[]string {
180180
return p.ArgByServerTypeAndName(definitions.ServerTypeSyncWorker, key)
181181
},
182-
Deprecated: true,
182+
DeprecatedHintFormat: "use --args.syncworkers.%s instead",
183183
},
184184
// New methods for args
185185
"args.all": {

service/options/options.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ type ConfigurationFlag struct {
207207
Usage string
208208
Value *[]string
209209

210-
Deprecated bool
210+
DeprecatedHint string
211211
}
212212

213213
type ConfigurationPrefixes map[string]ConfigurationPrefix
@@ -255,12 +255,12 @@ func (c ConfigurationPrefixes) Parse(args ...string) (*Configuration, []Configur
255255
}
256256

257257
f = append(f, ConfigurationFlag{
258-
Key: arg,
259-
CleanKey: ckey,
260-
Extension: targ,
261-
Usage: prefix.Usage(targ),
262-
Value: prefix.FieldSelector(&config, targ),
263-
Deprecated: prefix.Deprecated,
258+
Key: arg,
259+
CleanKey: ckey,
260+
Extension: targ,
261+
Usage: prefix.Usage(targ),
262+
Value: prefix.FieldSelector(&config, targ),
263+
DeprecatedHint: prefix.GetDeprecatedHint(targ),
264264
})
265265
}
266266

@@ -270,7 +270,7 @@ func (c ConfigurationPrefixes) Parse(args ...string) (*Configuration, []Configur
270270
func (c ConfigurationPrefixes) UsageHint() string {
271271
maxNameLen := 0
272272
for n, prefix := range c {
273-
if !prefix.Deprecated {
273+
if prefix.GetDeprecatedHint(n) == "" {
274274
if len(n) > maxNameLen {
275275
maxNameLen = len(n)
276276
}
@@ -279,7 +279,7 @@ func (c ConfigurationPrefixes) UsageHint() string {
279279

280280
parts := make([]string, 0)
281281
for n, prefix := range c {
282-
if !prefix.Deprecated {
282+
if prefix.GetDeprecatedHint(n) == "" {
283283
postfix := "<xxx>=<value>"
284284
pad := maxNameLen - len(n) + len(postfix) + 8
285285
parts = append(parts,
@@ -295,9 +295,16 @@ func (c ConfigurationPrefixes) UsageHint() string {
295295
}
296296

297297
type ConfigurationPrefix struct {
298-
Usage func(key string) string
299-
FieldSelector func(p *Configuration, key string) *[]string
300-
Deprecated bool
298+
Usage func(key string) string
299+
FieldSelector func(p *Configuration, key string) *[]string
300+
DeprecatedHintFormat string
301+
}
302+
303+
func (p ConfigurationPrefix) GetDeprecatedHint(key string) string {
304+
if p.DeprecatedHintFormat == "" {
305+
return ""
306+
}
307+
return fmt.Sprintf(p.DeprecatedHintFormat, key)
301308
}
302309

303310
func stringListCopy(a []string) []string {

0 commit comments

Comments
 (0)