github.com/oNaiPs/go-generate-fast@v0.3.0/src/plugins/go-bindata/go-bindata.go (about)

     1  package plugin_go_bindata
     2  
     3  import (
     4  	"github.com/go-bindata/go-bindata"
     5  	"github.com/oNaiPs/go-generate-fast/src/plugins"
     6  	"go.uber.org/zap"
     7  )
     8  
     9  type GobindataPlugin struct {
    10  	plugins.Plugin
    11  }
    12  
    13  func (p *GobindataPlugin) Name() string {
    14  	return "go-bindata"
    15  }
    16  
    17  func (p *GobindataPlugin) Matches(opts plugins.GenerateOpts) bool {
    18  	return opts.ExecutableName == "go-bindata" ||
    19  		opts.GoPackage == "github.com/go-bindata/go-bindata/..."
    20  }
    21  
    22  func (p *GobindataPlugin) ComputeInputOutputFiles(opts plugins.GenerateOpts) *plugins.InputOutputFiles {
    23  	ioFiles := plugins.InputOutputFiles{}
    24  
    25  	cfg := parseArgs(opts.SanitizedArgs)
    26  	if cfg == nil {
    27  		// there's no config returned, so most likely the original command will fail
    28  		return nil
    29  	}
    30  
    31  	var toc []bindata.Asset
    32  	var knownFuncs = make(map[string]int)
    33  	var visitedPaths = make(map[string]bool)
    34  	for _, input := range cfg.Input {
    35  		err := findFiles(input.Path, cfg.Prefix, input.Recursive, &toc, cfg.Ignore, knownFuncs, visitedPaths)
    36  		if err != nil {
    37  			zap.S().Error("go-bindata: cannot find files: %s", err)
    38  			return nil
    39  		}
    40  	}
    41  
    42  	for _, asset := range toc {
    43  		ioFiles.InputFiles = append(ioFiles.InputFiles, asset.Path)
    44  	}
    45  
    46  	ioFiles.OutputFiles = append(ioFiles.OutputFiles, cfg.Output)
    47  
    48  	return &ioFiles
    49  }
    50  func init() {
    51  	plugins.RegisterPlugin(&GobindataPlugin{})
    52  }