plugin.template 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Hercules plugin
  2. // How to build: go build -buildmode=plugin {{.output}}
  3. // This command creates ./{{.shlib}}
  4. // Usage: hercules -plugin {{.shlib}} -{{.flag}}
  5. package {{.package}}
  6. import (
  7. "gopkg.in/src-d/go-git.v4"
  8. "gopkg.in/src-d/hercules.v3"
  9. )
  10. // {{.name}} contains the intermediate state which is mutated by Consume(). It should implement
  11. // hercules.LeafPipelineItem.
  12. type {{.name}} struct {
  13. }
  14. // {{.name}}Result is returned by Finalize() and represents the analysis result.
  15. type {{.name}}Result struct {
  16. }
  17. // Analysis' name in the graph is usually the same as the type's name, however, does not have to.
  18. func ({{.varname}} *{{.name}}) Name() string {
  19. return "{{.name}}"
  20. }
  21. // LeafPipelineItem-s normally do not act as intermediate nodes and thus we return an empty slice.
  22. func ({{.varname}} *{{.name}}) Provides() []string {
  23. return []string{}
  24. }
  25. // Requires returns the list of dependencies which must be supplied in Consume().
  26. func ({{.varname}} *{{.name}}) Requires() []string {
  27. arr := [...]string{/* insert dependencies here */}
  28. return arr[:]
  29. }
  30. // ListConfigurationOptions tells the engine which parameters can be changed through the command
  31. // line.
  32. func ({{.varname}} *{{.name}}) ListConfigurationOptions() []hercules.ConfigurationOption {
  33. opts := [...]hercules.ConfigurationOption{ /* {
  34. Name: "ParameterName",
  35. Description: "Parameter's description.",
  36. Flag: "my-cmdline-flag",
  37. Type: hercules.BoolConfigurationOption,
  38. Default: false}, */
  39. }
  40. return opts[:]
  41. }
  42. // Flag returns the command line switch which activates the analysis.
  43. func ({{.varname}} *{{.name}}) Flag() string {
  44. return "{{.flag}}"
  45. }
  46. // Configure applies the parameters specified in the command line. Map keys correspond to "Name".
  47. func ({{.varname}} *{{.name}}) Configure(facts map[string]interface{}) {
  48. }
  49. // Initialize resets the internal temporary data structures and prepares the object for Consume().
  50. func ({{.varname}} *{{.name}}) Initialize(repository *git.Repository) {
  51. }
  52. func ({{.varname}} *{{.name}}) Consume(deps map[string]interface{}) (map[string]interface{}, error) {
  53. return nil, nil
  54. }
  55. func ({{.varname}} *{{.name}}) Finalize() interface{} {
  56. result := {{.name}}Result{}
  57. // insert code here
  58. return result
  59. }
  60. func init() {
  61. hercules.Registry.Register(&{{.name}}{})
  62. }