Skip to content

GT-324 Fix help message when passing deprecated pass-through args #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Fix restarting cluster with arangosync enabled
- Upgrade Go to v1.19.4 to fix CVEs
- Fix passing-through boolean flags to arangosync
- Improve deprecated notice for old passthrough flags

## [0.15.5](https://github.com/arangodb-helper/arangodb/tree/0.15.5) (2022-09-19)
- Fix project CI: linter, tests, build, release
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func init() {
}

f.StringSliceVar(flag.Value, flag.CleanKey, nil, flag.Usage)
if flag.Deprecated {
f.MarkDeprecated(flag.CleanKey, "Deprecated")
if flag.DeprecatedHint != "" {
f.MarkDeprecated(flag.CleanKey, flag.DeprecatedHint)
}
}

Expand Down
14 changes: 7 additions & 7 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
FieldSelector: func(p *options.Configuration, key string) *[]string {
return p.ArgByProcessTypeAndName(definitions.ServerTypeAgent, key)
},
Deprecated: true,
DeprecatedHintFormat: "use --args.all.%s instead",
},
"coordinators": {
Usage: func(key string) string {
Expand All @@ -134,7 +134,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
FieldSelector: func(p *options.Configuration, key string) *[]string {
return p.ArgByServerTypeAndName(definitions.ServerTypeCoordinator, key)
},
Deprecated: true,
DeprecatedHintFormat: "use --args.coordinators.%s instead",
},
"dbservers": {
Usage: func(key string) string {
Expand All @@ -143,7 +143,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
FieldSelector: func(p *options.Configuration, key string) *[]string {
return p.ArgByServerTypeAndName(definitions.ServerTypeDBServer, key)
},
Deprecated: true,
DeprecatedHintFormat: "use --args.dbservers.%s instead",
},
"agents": {
Usage: func(key string) string {
Expand All @@ -152,7 +152,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
FieldSelector: func(p *options.Configuration, key string) *[]string {
return p.ArgByServerTypeAndName(definitions.ServerTypeAgent, key)
},
Deprecated: true,
DeprecatedHintFormat: "use --args.agents.%s instead",
},
"sync": {
Usage: func(key string) string {
Expand All @@ -161,7 +161,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
FieldSelector: func(p *options.Configuration, key string) *[]string {
return p.ArgByProcessTypeAndName(definitions.ServerTypeSyncMaster, key)
},
Deprecated: true,
DeprecatedHintFormat: "use --args.sync.%s instead",
},
"syncmasters": {
Usage: func(key string) string {
Expand All @@ -170,7 +170,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
FieldSelector: func(p *options.Configuration, key string) *[]string {
return p.ArgByServerTypeAndName(definitions.ServerTypeSyncMaster, key)
},
Deprecated: true,
DeprecatedHintFormat: "use --args.syncmasters.%s instead",
},
"syncworkers": {
Usage: func(key string) string {
Expand All @@ -179,7 +179,7 @@ func preparePassthroughPrefixes() options.ConfigurationPrefixes {
FieldSelector: func(p *options.Configuration, key string) *[]string {
return p.ArgByServerTypeAndName(definitions.ServerTypeSyncWorker, key)
},
Deprecated: true,
DeprecatedHintFormat: "use --args.syncworkers.%s instead",
},
// New methods for args
"args.all": {
Expand Down
31 changes: 19 additions & 12 deletions service/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ type ConfigurationFlag struct {
Usage string
Value *[]string

Deprecated bool
DeprecatedHint string
}

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

f = append(f, ConfigurationFlag{
Key: arg,
CleanKey: ckey,
Extension: targ,
Usage: prefix.Usage(targ),
Value: prefix.FieldSelector(&config, targ),
Deprecated: prefix.Deprecated,
Key: arg,
CleanKey: ckey,
Extension: targ,
Usage: prefix.Usage(targ),
Value: prefix.FieldSelector(&config, targ),
DeprecatedHint: prefix.GetDeprecatedHint(targ),
})
}

Expand All @@ -270,7 +270,7 @@ func (c ConfigurationPrefixes) Parse(args ...string) (*Configuration, []Configur
func (c ConfigurationPrefixes) UsageHint() string {
maxNameLen := 0
for n, prefix := range c {
if !prefix.Deprecated {
if prefix.GetDeprecatedHint(n) == "" {
if len(n) > maxNameLen {
maxNameLen = len(n)
}
Expand All @@ -279,7 +279,7 @@ func (c ConfigurationPrefixes) UsageHint() string {

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

type ConfigurationPrefix struct {
Usage func(key string) string
FieldSelector func(p *Configuration, key string) *[]string
Deprecated bool
Usage func(key string) string
FieldSelector func(p *Configuration, key string) *[]string
DeprecatedHintFormat string
}

func (p ConfigurationPrefix) GetDeprecatedHint(key string) string {
if p.DeprecatedHintFormat == "" {
return ""
}
return fmt.Sprintf(p.DeprecatedHintFormat, key)
}

func stringListCopy(a []string) []string {
Expand Down