Accept shared debug bindings
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
// its command-line backend.
|
||||
package commandmeta
|
||||
|
||||
import "strings"
|
||||
|
||||
// Key identifies one command inside one routing snapshot.
|
||||
type Key uint64
|
||||
|
||||
@@ -100,6 +102,35 @@ func ReportingFlags() []Flag {
|
||||
return flags
|
||||
}
|
||||
|
||||
// EffectiveFlags combines the shared debug option while preserving consumer order.
|
||||
func EffectiveFlags(flags, core []Flag) []Flag {
|
||||
result := append([]Flag(nil), flags...)
|
||||
shared := -1
|
||||
for i, flag := range result {
|
||||
if flag.Name == "debug" && flag.Boolean {
|
||||
shared = i
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, flag := range core {
|
||||
if flag.Name == "debug" && shared >= 0 {
|
||||
app := result[shared]
|
||||
usage := flag.Usage
|
||||
if app.Usage != "" {
|
||||
usage += "; " + app.Usage
|
||||
}
|
||||
if strings.EqualFold(app.Default, "true") {
|
||||
usage += "; application input defaults to true (reporting defaults to ordinary)"
|
||||
}
|
||||
flag.Usage, flag.Short, flag.Required, flag.Completion = usage, app.Short, app.Required, app.Completion
|
||||
result[shared] = flag
|
||||
continue
|
||||
}
|
||||
result = append(result, flag)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// IsReportingFlag reports whether name is reserved for a shared reporting flag.
|
||||
func IsReportingFlag(name string) bool {
|
||||
for _, flag := range reportingFlags {
|
||||
|
||||
Reference in New Issue
Block a user