Merge pull request #571 from alixander/include-binary-plugins
Include binary plugins
This commit is contained in:
commit
3e2c5bf18a
3 changed files with 31 additions and 2 deletions
|
|
@ -126,7 +126,7 @@ func (p execPlugin) Layout(ctx context.Context, g *d2graph.Graph) error {
|
|||
|
||||
args := []string{"layout"}
|
||||
for k, v := range p.opts {
|
||||
args = append(args, k, v)
|
||||
args = append(args, fmt.Sprintf("--%s", k), v)
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, p.path, args...)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,15 @@ func (f *PluginSpecificFlag) AddToOpts(opts *xmain.Opts) {
|
|||
case "string":
|
||||
opts.String("", f.Name, "", f.Default.(string), f.Usage)
|
||||
case "int64":
|
||||
opts.Int64("", f.Name, "", f.Default.(int64), f.Usage)
|
||||
var val int64
|
||||
switch defaultType := f.Default.(type) {
|
||||
case int64:
|
||||
val = defaultType
|
||||
case float64:
|
||||
// json unmarshals numbers to float64
|
||||
val = int64(defaultType)
|
||||
}
|
||||
opts.Int64("", f.Name, "", val, f.Usage)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,5 +150,19 @@ func ListPluginFlags(ctx context.Context) ([]PluginSpecificFlag, error) {
|
|||
}
|
||||
out = append(out, flags...)
|
||||
}
|
||||
|
||||
matches, err := xexec.SearchPath(binaryPrefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, path := range matches {
|
||||
p := &execPlugin{path: path}
|
||||
flags, err := p.Flags(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, flags...)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,13 @@ import (
|
|||
// Also see execPlugin in exec.go for the d2 binary plugin protocol.
|
||||
func Serve(p Plugin) xmain.RunFunc {
|
||||
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)
|
||||
if !errors.Is(err, pflag.ErrHelp) && err != nil {
|
||||
return xmain.UsageErrorf("failed to parse flags: %v", err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue