copyfile

package module
v1.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 12 Imported by: 1

README

debefix-copyfile

WARNNG: v1 is deprecated, use v2 instead.

License

MIT

Author

Rangel Reale ([email protected])

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCopyFileCallback added in v1.3.1

func DefaultCopyFileCallback(sourcePath, sourceFilename string, destinationPath, destinationFilename string) error

DefaultCopyFileCallback is the default implementation of CopyFileCallback.

func DefaultGetPathsCallback added in v1.3.1

func DefaultGetPathsCallback(ctx debefix.ValueResolveContext, fieldname string, fileData FileData) (source string, destination string, err error)

DefaultGetPathsCallback is the default implementation of GetPathsCallback.

func DefaultGetValueCallback added in v1.3.1

func DefaultGetValueCallback(ctx debefix.ValueCallbackResolveContext, fileData FileData) (value any, addField bool, err error)

DefaultGetValueCallback is the default implementation of GetValueCallback.

func ReplaceFields added in v1.3.1

func ReplaceFields(str string, values map[string]any) (string, error)

ReplaceFields parses curly-brace-delimited fields in strings and replaces them with values. To escape a curly-brace, add two consecutive ones.

func ReplaceFieldsWithFilter added in v1.3.1

func ReplaceFieldsWithFilter(str string, ctx debefix.ValueResolveContext) (string, error)

ReplaceFieldsWithFilter replaces curly-braces separated fields in str as debefix filter expressions.

Types

type CopyFile

type CopyFile struct {
	debefix.ValueImpl
	// contains filtered or unexported fields
}

CopyFile is a debefix plugin to configure files to be copied during the data generation process.

func New

func New(options ...Option) *CopyFile

New creates an instance of the CopyFile debefix plugin.

func NewOptions

func NewOptions(options ...Option) (*CopyFile, []debefix.LoadOption, []debefix.ResolveOption)

NewOptions returns debefix debefix.LoadOption and debefix.ResolveOption to use the plugin.

func (*CopyFile) ParseValue

func (c *CopyFile) ParseValue(tag *ast.TagNode) (bool, any, error)

func (*CopyFile) RowResolved

func (c *CopyFile) RowResolved(ctx debefix.ValueResolveContext) error

type CopyFileCallback added in v1.3.1

type CopyFileCallback func(sourcePath, sourceFilename string, destinationPath, destinationFilename string) error

CopyFileCallback copy a file from a source to a destination.

type FileData

type FileData struct {
	ID          string  `yaml:"id"`
	Value       *string `yaml:"value"`
	Source      string  `yaml:"source"`
	Destination string  `yaml:"destination"`
}

FileData is the information of the !copyfile tag.

type GetPathsCallback added in v1.3.1

type GetPathsCallback func(ctx debefix.ValueResolveContext, fieldname string,
	fileData FileData) (source string, destination string, err error)

GetPathsCallback gets the source and destination file names from FileData.

type GetValueCallback added in v1.3.1

type GetValueCallback func(ctx debefix.ValueCallbackResolveContext,
	fileData FileData) (value any, addField bool, err error)

GetValueCallback allows getting a value for the file field. If addField is false, no field will be added to the data, only the file will be copied.

type Option

type Option func(*CopyFile)

func WithCopyFileCallback added in v1.3.1

func WithCopyFileCallback(callback CopyFileCallback) Option

WithCopyFileCallback sets the callback that copy files from a source to a destination.

func WithDestinationPath added in v1.3.1

func WithDestinationPath(destinationPath string) Option

WithDestinationPath sets the destination path, the root of all destination filenames.

func WithGetPathsCallback added in v1.3.1

func WithGetPathsCallback(callback GetPathsCallback) Option

WithGetPathsCallback sets the callback to get the source and destination filenames from the FileData parameters. The default implementation DefaultGetPathsCallback replaces field filters in both source and destination using ReplaceFieldsWithFilter.

func WithGetValueCallback added in v1.3.1

func WithGetValueCallback(setValueCallback GetValueCallback) Option

WithGetValueCallback sets the callback to have the option to set the file field value. The default implementation DefaultGetValueCallback don't add the field if [FileData.Value] was not set, otherwise it replaces field filters in it using ReplaceFieldsWithFilter.

func WithSourcePath added in v1.3.1

func WithSourcePath(sourcePath string) Option

WithSourcePath sets the source path, the root of all source filenames.

type ParsedFields added in v1.3.1

type ParsedFields struct {
	// contains filtered or unexported fields
}

ParsedFields stores the parsed fields from ParseFields.

func ParseFields added in v1.3.1

func ParseFields(str string) *ParsedFields

ParseFields parses curly-brace-delimited fields in strings and allows listing and replacing them. To escape a curly-brace, add two consecutive ones.

func (*ParsedFields) Fields added in v1.3.1

func (s *ParsedFields) Fields() []string

Fields returns the list of fields found.

func (*ParsedFields) Replace added in v1.3.1

func (s *ParsedFields) Replace(values map[string]any) (string, error)

Replace returns a new string with all fields replaced with values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL