github.com/dnephin/dobi@v0.15.0/config/resource.go (about)

     1  package config
     2  
     3  import (
     4  	pth "github.com/dnephin/configtf/path"
     5  	"github.com/dnephin/dobi/logging"
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  // Resource is an interface for each configurable type
    10  type Resource interface {
    11  	Dependencies() []string
    12  	Validate(pth.Path, *Config) *pth.Error
    13  	Resolve(Resolver) (Resource, error)
    14  	Describe() string
    15  	CategoryTags() []string
    16  	String() string
    17  }
    18  
    19  // Annotations provides a description and tags to a resource
    20  type Annotations struct {
    21  	// Description of a resource
    22  	// Deprecated use Annotations.Description
    23  	Description string `config:"validate"`
    24  	Annotations AnnotationFields
    25  }
    26  
    27  // Describe returns the resource description
    28  func (a *Annotations) Describe() string {
    29  	if a.Annotations.Description != "" {
    30  		return a.Annotations.Description
    31  	}
    32  	// fall back to old deprecated field
    33  	return a.Description
    34  }
    35  
    36  // CategoryTags tags returns the list of tags
    37  func (a *Annotations) CategoryTags() []string {
    38  	return a.Annotations.Tags
    39  }
    40  
    41  // ValidateDescription prints a warning if set
    42  func (a *Annotations) ValidateDescription() error {
    43  	if a.Description != "" && a.Annotations.Description != "" {
    44  		return errors.Errorf(
    45  			"deprecated description will be ignored in " +
    46  				"favor of annotations.description")
    47  	}
    48  	if a.Description != "" {
    49  		logging.Log.Warn("description is deprecated. Use annotations.description")
    50  	}
    51  	return nil
    52  }
    53  
    54  // AnnotationFields used to annotate a resource
    55  type AnnotationFields struct {
    56  	// Description Description of the resource. Adding a description to a
    57  	// resource makes it visible from ``dobi list``.
    58  	Description string
    59  	// Tags Tags can be used to group resources. There can be configured
    60  	// multiple tags per resource. Adding a tag to a resource outputs a
    61  	// grouped list from ``dobi list -g``.
    62  	Tags []string
    63  }
    64  
    65  // Dependent can be used to provide part of the Resource interface
    66  type Dependent struct {
    67  	// Depends The list of task dependencies.
    68  	// type: list of tasks
    69  	Depends []string
    70  }
    71  
    72  // Dependencies returns the list of tasks
    73  func (d *Dependent) Dependencies() []string {
    74  	return d.Depends
    75  }
    76  
    77  // Resolver is an interface for a type that returns values for variables
    78  type Resolver interface {
    79  	Resolve(tmpl string) (string, error)
    80  	ResolveSlice(tmpls []string) ([]string, error)
    81  }