sort

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AFS *afero.Afero
	FS  afero.Fs
)

Functions

func GetCommand

func GetCommand() *cobra.Command

func SetFileSystem

func SetFileSystem(fs afero.Fs)

SetFileSystem sets the filesystem to use for the Sort command

func Sort

func Sort(target string, settings *Params)

Sort sorts a Terraform file or folder.

If the target is a folder, all files in the folder will be sorted. If the target is a file, only that file will be sorted.

Types

type BlockListSorter

type BlockListSorter []*hclsyntax.Block

BlockListSorter implements the sort.Interface for []*hclsyntax.Block

func (BlockListSorter) Len

func (bs BlockListSorter) Len() int

Len returns the length of the array

func (BlockListSorter) Less

func (bs BlockListSorter) Less(i, j int) bool

Less compares two blocks based on their types and labels

func (BlockListSorter) Swap

func (bs BlockListSorter) Swap(i, j int)

Swap swaps two blocks in the array

type Params

type Params struct {
	// If the group-by-type flag is set, the resources will be grouped by type in the output files.
	// Otherwise, the resources will be sorted alphabetically ascending by resource type and name in the existing files.
	GroupByType bool `yaml:"group-by-type"`
	// If the has-header flag is set, the input files have a header.
	HasHeader bool `yaml:"has-header"`
	// If the header-pattern flag is set, the header pattern will be used to find the header in the input files.
	HeaderPattern string `yaml:"header-pattern"`
	// If the keep-header flag is set, the header matched in the header pattern will be persisted in the output files.
	KeepHeader bool `yaml:"keep-header"`
	// If the output directory is set, the sorted files will be written to the output directory.
	// Otherwise, the sorted files will be printed to stdout.
	OutputDir string `yaml:"output-dir"`
	// If the remove-comments flag is set, the comments will be removed from the files.
	// Otherwise, the comments will be preserved.
	RemoveComments bool `yaml:"remove-comments"`
}

Params represents the parameters for the sort command.

Jump to

Keyboard shortcuts

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