Documentation
¶
Overview ¶
Copyright 2026 YLD Limited SPDX-License-Identifier: Apache-2.0 Package fsutil provides filesystem utilities for parsing HCL input (files or directories), listing files by extension, and writing output files with automatic directory creation.
Index ¶
- Variables
- func HasGeneratedMarker(path, provider string) (bool, error)
- func ListFilesWithExtensions(path string, recursive bool, exts ...string) ([]string, error)
- func ParseHCLInput(path string, recursive bool) (hcl.Body, map[string][]byte, error)
- func PrependGeneratedMarker(content []byte, provider string) []byte
- func PruneStaleGeneratedYAML(outputDir string, currentOutputs map[string]struct{}, provider string) error
- func UniqueOutputName(taken map[string]struct{}, base string) string
- func WithoutGeneratedMarker(comment string) string
- func WriteFile(path string, content []byte) error
Constants ¶
This section is empty.
Variables ¶
var ErrNoHCLFiles = cinzelerror.UserInput(errors.New("no HCL files found in input"))
ErrNoHCLFiles is returned when no HCL files are found in the given path.
Functions ¶
func HasGeneratedMarker ¶
HasGeneratedMarker reports whether path has cinzel markers for provider.
func ListFilesWithExtensions ¶
ListFilesWithExtensions returns files under path matching the given extensions.
func ParseHCLInput ¶
ParseHCLInput parses one or more HCL files from path and returns a merged body along with the bytes each file was parsed from, keyed by filename.
The sources are the parser's own, so anything reading back from a source range sees the text the body was built from rather than whatever the file holds by the time it is looked at.
func PrependGeneratedMarker ¶
PrependGeneratedMarker prepends standardized cinzel generation markers.
func PruneStaleGeneratedYAML ¶
func PruneStaleGeneratedYAML(outputDir string, currentOutputs map[string]struct{}, provider string) error
PruneStaleGeneratedYAML removes stale YAML files owned by provider.
The whole tree under outputDir is walked, not only its top level. An output can sit in a subdirectory, either because a filename names one or because an action is written to its own folder, and a file left there was never reached: renaming an action kept the old one beside the new one for good.
Only files carrying the provider's marker are removed, so anything the caller wrote by hand is left where it is. currentOutputs has to name every file this run produced, actions included, or a live file is read as stale and deleted.
func UniqueOutputName ¶ added in v0.6.0
UniqueOutputName returns base, or a suffixed variant when base is already taken, and records whichever it returns. Output paths are built from the input's basename alone, so two files a directory apart wrote to one path and the first result was gone with nothing said.
Case is folded because a name differing only in case is the same file on macOS and Windows, and the same input would otherwise produce different output depending on where it ran.
func WithoutGeneratedMarker ¶ added in v0.7.0
WithoutGeneratedMarker returns comment with the cinzel generation markers removed, and empty string if that is all it held.
The markers are written at the top of every generated file, so a YAML reader hands them back as the comment above the file's first key. They are cinzel's own note and not something an author wrote, and carrying them into the HCL would copy them into the source a person edits, one more line on each roundtrip.
Types ¶
This section is empty.