mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
help: global flags help command extended filtering
This commit is contained in:
committed by
Nick Craig-Wood
parent
c6352231e4
commit
1720d3e11c
@@ -50,16 +50,17 @@ func (gs *Groups) NewGroup(name, help string) *Group {
|
||||
}
|
||||
|
||||
// Filter makes a copy of groups filtered by flagsRe
|
||||
func (gs *Groups) Filter(flagsRe *regexp.Regexp) *Groups {
|
||||
func (gs *Groups) Filter(group string, filterRe *regexp.Regexp, filterNamesOnly bool) *Groups {
|
||||
newGs := NewGroups()
|
||||
for _, g := range gs.Groups {
|
||||
newG := newGs.NewGroup(g.Name, g.Help)
|
||||
g.Flags.VisitAll(func(f *pflag.Flag) {
|
||||
matched := flagsRe == nil || flagsRe.MatchString(f.Name) || flagsRe.MatchString(f.Usage)
|
||||
if matched {
|
||||
newG.Flags.AddFlag(f)
|
||||
}
|
||||
})
|
||||
if group == "" || strings.EqualFold(g.Name, group) {
|
||||
newG := newGs.NewGroup(g.Name, g.Help)
|
||||
g.Flags.VisitAll(func(f *pflag.Flag) {
|
||||
if filterRe == nil || filterRe.MatchString(f.Name) || (!filterNamesOnly && filterRe.MatchString(f.Usage)) {
|
||||
newG.Flags.AddFlag(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return newGs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user