Skip to content

Commit 467f3be

Browse files
Add sanity check for pass-through args usage (#363)
1 parent 3c43ab8 commit 467f3be

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ArangoDB Starter Changelog
22

33
## [master](https://github.com/arangodb-helper/arangodb/tree/master) (N/A)
4+
- Add sanity check for pass-through args usage
45
- Fix printing --starter.instance-up-timeout instead of hardcoded value
56
- Fix context handling in WaitUntilStarterReady for tests
67

config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,23 @@ func loadFlagValuesFromConfig(cfgFilePath string, fs, persistentFs *pflag.FlagSe
119119
}
120120
}
121121
}
122+
123+
// sanityCheckPassThroughArgs will print a warning if user does not specify value for option,
124+
// example: --args.all.log.line-number --args.all.log.performance=true
125+
func sanityCheckPassThroughArgs(fs, persistentFs *pflag.FlagSet) {
126+
sanityCheck := func(flag *pflag.Flag) {
127+
if found, _, _ := passthroughPrefixes.Lookup(flag.Name); found != nil {
128+
if flag.Value == nil {
129+
return
130+
}
131+
if sliceVal, ok := flag.Value.(pflag.SliceValue); ok {
132+
slice := sliceVal.GetSlice()
133+
if len(slice) > 0 && strings.HasPrefix(slice[0], "--") {
134+
log.Warn().Msgf("Possible wrong usage of pass-through argument --%s: its value %s looks like separate argument.", flag.Name, slice[0])
135+
}
136+
}
137+
}
138+
}
139+
fs.Visit(sanityCheck)
140+
persistentFs.Visit(sanityCheck)
141+
}

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ func cmdMainRun(cmd *cobra.Command, args []string) {
459459
log.Fatal().Msgf("Expected no arguments, got %q", args)
460460
}
461461

462+
sanityCheckPassThroughArgs(cmd.Flags(), cmd.PersistentFlags())
463+
462464
// Create service
463465
svc, bsCfg := mustPrepareService(true)
464466

0 commit comments

Comments
 (0)