cli

package
v3.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GroupByDirectory

func GroupByDirectory(reports []reporter.Report) map[string][]reporter.Report

GroupByDirectory groups reports by containing directory.

func GroupByErrorType

func GroupByErrorType(reports []reporter.Report) map[string][]reporter.Report

GroupByErrorType groups reports by error type.

func GroupByFileType

func GroupByFileType(reports []reporter.Report) map[string][]reporter.Report

GroupByFileType groups reports by file extension.

func GroupByPassFail

func GroupByPassFail(reports []reporter.Report) map[string][]reporter.Report

GroupByPassFail groups reports by pass or fail status.

Types

type CLI

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

CLI is the main entry point for running config file validation and formatting. Use Init with Option functions to configure, then call Run (check) or Format.

func Init

func Init(opts ...Option) *CLI

func (*CLI) Format

func (c *CLI) Format(optsFunc FormatOptionsFunc) (int, error)

Format runs the formatting pipeline.

For each discovered file whose FileType has a registered Formatter:

  • If the file is already formatted: Report{Status: StatusPass}
  • If the file needs formatting: Report{Status: StatusUnformatted}
  • If --fix is set: rewrite the file atomically, report as StatusPass
  • If the file cannot be parsed by the formatter: skipped (not reported)
  • If the file cannot be read (non-symlink): skipped (not reported)

Files whose FileType has no Formatter are silently skipped. Broken symlinks are reported as StatusFail.

Returns 0 if all files are formatted (or all were fixed), 1 if any file needs formatting and --fix was not set, 2 on tool error.

func (*CLI) Run

func (c *CLI) Run() (int, error)

type File

type File interface {
	Name() string
	Write(b []byte) (int, error)
	Close() error
}

File abstracts file write operations.

type FileSystem

type FileSystem interface {
	Stat(path string) (fs.FileInfo, error)
	CreateTemp(dir, pattern string) (File, error)
	Chmod(path string, mode fs.FileMode) error
	Rename(oldpath, newpath string) error
	Remove(path string) error
}

FileSystem abstracts file operations for testability.

type FormatOptionsFunc

type FormatOptionsFunc func(formatName string) formatter.Options

FormatOptionsFunc returns resolved format options for a given format name.

type GroupNode

type GroupNode = reporter.GroupNode

GroupNode aliases the reporter grouping tree used by grouped output.

func GroupBy

func GroupBy(reports []reporter.Report, groupBy []string) (*GroupNode, error)

GroupBy groups reports into a recursive tree for any number of grouping levels.

type Option

type Option func(*CLI)

Option configures a CLI instance.

func WithDiff

func WithDiff(diff bool) Option

WithDiff enables unified diff output mode for Format. When true, Format prints diffs instead of the normal pass/fail report.

func WithFinder

func WithFinder(f finder.FileFinder) Option

func WithFix

func WithFix(fix bool) Option

WithFix enables writing formatted output back to disk when calling Format. When false (the default), Format reports issues but does not modify files.

func WithGroupOutput

func WithGroupOutput(groupOutput []string) Option

func WithNoSchema

func WithNoSchema(noSchema bool) Option

func WithQuiet

func WithQuiet(quiet bool) Option

func WithReporters

func WithReporters(r ...reporter.Reporter) Option

func WithRequireSchema

func WithRequireSchema(require bool) Option

func WithSchemaMap

func WithSchemaMap(m map[string]string) Option

func WithSchemaStore

func WithSchemaStore(s *schemastore.Store) Option

func WithStdinData

func WithStdinData(data []byte, ft filetype.FileType) Option

Jump to

Keyboard shortcuts

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