File: mpflag.go

package info (click to toggle)
golang-github-muesli-mango-pflag 0.1.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 120 kB
  • sloc: makefile: 3
file content (30 lines) | stat: -rw-r--r-- 657 bytes parent folder | download
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
30
package mpflag

import (
	"github.com/muesli/mango"
	"github.com/spf13/pflag"
)

// PFlagVisitor is used to visit all flags and track them in a mango.ManPage.
func PFlagVisitor(m *mango.ManPage) func(*pflag.Flag) {
	return func(f *pflag.Flag) {
		_ = m.Root.AddFlag(mango.Flag{
			Name:  f.Name,
			Short: f.Shorthand,
			Usage: f.Usage,
			PFlag: true,
		})
	}
}

// PFlagCommandVisitor is used to visit all flags and track them in a mango.Command.
func PFlagCommandVisitor(c *mango.Command) func(*pflag.Flag) {
	return func(f *pflag.Flag) {
		_ = c.AddFlag(mango.Flag{
			Name:  f.Name,
			Short: f.Shorthand,
			Usage: f.Usage,
			PFlag: true,
		})
	}
}