File: commander.go

package info (click to toggle)
golang-github-svent-go-flags 1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 224 kB
  • ctags: 186
  • sloc: sh: 13; makefile: 7
file content (29 lines) | stat: -rw-r--r-- 435 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package flags

import (
	"sort"
)

type Commander struct {
	Commands map[string]*Group
}

func (x *Commander) sortedNames() []string {
	ret := make([]string, 0, len(x.Commands))

	for k, _ := range x.Commands {
		ret = append(ret, k)
	}

	sort.Strings(ret)
	return ret
}

func (x *Commander) EachCommand(cb func(command string, grp *Group)) {
	for k, v := range x.Commands {
		cb(k, v)

		// Recurse
		v.Commander.EachCommand(cb)
	}
}