fsutil

package
v0.7.0 Latest Latest
Warning

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

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

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

Constants

This section is empty.

Variables

View Source
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

func HasGeneratedMarker(path, provider string) (bool, error)

HasGeneratedMarker reports whether path has cinzel markers for provider.

func ListFilesWithExtensions

func ListFilesWithExtensions(path string, recursive bool, exts ...string) ([]string, error)

ListFilesWithExtensions returns files under path matching the given extensions.

func ParseHCLInput

func ParseHCLInput(path string, recursive bool) (hcl.Body, map[string][]byte, error)

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

func PrependGeneratedMarker(content []byte, provider string) []byte

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

func UniqueOutputName(taken map[string]struct{}, base string) string

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

func WithoutGeneratedMarker(comment string) string

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.

func WriteFile

func WriteFile(path string, content []byte) error

WriteFile writes content to path, creating parent directories as needed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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