plugins parse flags
This commit is contained in:
parent
a92e7211a7
commit
4c7398ba11
1 changed files with 7 additions and 0 deletions
|
|
@ -21,6 +21,13 @@ import (
|
||||||
// Also see execPlugin in exec.go for the d2 binary plugin protocol.
|
// Also see execPlugin in exec.go for the d2 binary plugin protocol.
|
||||||
func Serve(p Plugin) xmain.RunFunc {
|
func Serve(p Plugin) xmain.RunFunc {
|
||||||
return func(ctx context.Context, ms *xmain.State) (err error) {
|
return func(ctx context.Context, ms *xmain.State) (err error) {
|
||||||
|
fs, err := p.Flags(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, f := range fs {
|
||||||
|
f.AddToOpts(ms.Opts)
|
||||||
|
}
|
||||||
err = ms.Opts.Flags.Parse(ms.Opts.Args)
|
err = ms.Opts.Flags.Parse(ms.Opts.Args)
|
||||||
if !errors.Is(err, pflag.ErrHelp) && err != nil {
|
if !errors.Is(err, pflag.ErrHelp) && err != nil {
|
||||||
return xmain.UsageErrorf("failed to parse flags: %v", err)
|
return xmain.UsageErrorf("failed to parse flags: %v", err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue