file

package
v0.116.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File defines a resource of kind "file"

func New

func New(spec interface{}) (*File, error)

New returns a reference to a newly initialized File object from a Spec or an error if the provided Filespec triggers a validation error.

func (*File) Changelog

func (f *File) Changelog(from, to string) *result.Changelogs

Changelog returns the changelog for this resource, or an empty string if not supported

func (*File) Condition

func (f *File) Condition(_ context.Context, source string, scm scm.ScmHandler) (pass bool, message string, err error)

Condition test if a file content matches the content provided via configuration. If the configuration doesn't specify a value then it fall back to the source output

func (*File) Read

func (f *File) Read() error

Read puts the content of the file(s) as value of the f.files map if the file(s) exist(s) or log the non existence of the file

func (*File) ReportConfig added in v0.99.0

func (f *File) ReportConfig() interface{}

ReportConfig returns a new configuration with only the necessary configuration fields without any sensitive information or context specific data.

func (*File) Source

func (f *File) Source(_ context.Context, workingDir string, resultSource *result.Source) error

Source return a file content

func (*File) Target

func (f *File) Target(_ context.Context, source string, scm scm.ScmHandler, dryRun bool, resultTarget *result.Target) error

Target creates or updates a file from a source control management system. The default content is the value retrieved from source

func (*File) UpdateAbsoluteFilePath added in v0.50.0

func (f *File) UpdateAbsoluteFilePath(workDir string)

type Spec

type Spec struct {
	//   `file` contains the file path
	//
	//   compatible:
	//       * source
	//       * condition
	//       * target
	//
	//   remarks:
	//       * `file` is incompatible with `files`
	//       * feel free to look at searchpattern attribute to search for files matching a pattern
	File string `yaml:",omitempty"`
	//   `files` contains the file path(s)
	//
	//   compatible:
	//       * condition
	//       * target
	//
	//   remarks:
	//       * `files` is incompatible with `file`
	//       * feel free to look at searchpattern attribute to search for files matching a pattern
	Files []string `yaml:",omitempty"`
	//   `line` contains the line of the file(s) to manipulate
	//
	//   compatible:
	//       * source
	//       * condition
	//       * target
	Line int `yaml:",omitempty"`
	//   `content` specifies the content to manipulate
	//
	//   compatible:
	//       * source
	//       * condition
	//       * target
	Content string `yaml:",omitempty"`
	//   `forcecreate` defines if nonexistent file(s) should be created
	//
	//   compatible:
	//       * target
	ForceCreate bool `yaml:",omitempty"`
	//   `matchpattern` specifies the regexp pattern to match on the file(s)
	//
	//   compatible:
	//       * source
	//       * condition
	//       * target
	//
	//   remarks:
	//       * For targets: Capture groups (parentheses) in the pattern automatically extract
	//         the current value for changelog generation
	//       * Without capture groups, changelogs show generic "unknown" version changes
	//       * With capture groups, changelogs show actual version changes (e.g., "1.24.5" → "1.25.1")
	//       * Example: `"version":\s*"([\d\.]+)"` captures version numbers for changelogs
	//       * Supports full Go regexp syntax
	MatchPattern string `yaml:",omitempty"`
	//   `replacepattern` specifies the regexp replace pattern to apply on the file(s) content
	//
	//   compatible:
	//       * source
	//       * condition
	//       * target
	ReplacePattern string `yaml:",omitempty"`
	//   `searchpattern` defines if the MatchPattern should be applied on the file(s) path
	//
	//   If set to true, it modifies the behavior of the `file` and `files` attributes to search for files matching the pattern instead of searching for files with the exact name.
	//   When looking for file path pattern, it requires pattern to match all of name, not just a substring.
	//
	//   The pattern syntax is:
	//
	//   “`
	//       pattern:
	//           { term }
	//       term:
	//           '*'         matches any sequence of non-Separator characters
	//           '?'         matches any single non-Separator character
	//           '[' [ '^' ] { character-range } ']'
	//                       character class (must be non-empty)
	//           c           matches character c (c != '*', '?', '\\', '[')
	//           '\\' c      matches character c
	//
	//       character-range:
	//           c           matches character c (c != '\\', '-', ']')
	//           '\\' c      matches character c
	//           lo '-' hi   matches character c for lo <= c <= hi
	//   “`
	SearchPattern bool `yaml:",omitempty"`
	//   `template` specifies the path to a Go template file to render with source values
	//
	//   compatible:
	//       * target
	//
	//   remarks:
	//       * When using template, the source value is passed as `.source` in the template context
	//       * All Go template functions from sprig are available
	//       * The template file is read and rendered at execution time
	//       * `template` is mutually exclusive with `content`, `line`, `matchpattern`, and `replacepattern`
	//
	//   example:
	//       template: "path/to/template.tmpl"
	Template string `yaml:",omitempty"`
	//
	//	`templateData` specifies additional data to pass to the template
	//
	//	compatible:
	//	    * target
	//
	//	remarks:
	//	    * When using template, the data specified here is passed as additional fields in the template context
	//	    * All Go template functions from sprig are available
	//	    * The template file is read and rendered at execution time
	//	    * `templateData` is optional
	//
	//	example:
	//	    templateData:
	//	        key1: "value1"
	//	        key2: "value2"
	TemplateData map[string]interface{} `yaml:",omitempty"`
}

Spec defines a specification for a "file" resource parsed from an updatecli manifest file

func (*Spec) Validate added in v0.23.0

func (s *Spec) Validate() error

Validate validates the object and returns an error (with all the failed validation messages) if not valid

Jump to

Keyboard shortcuts

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