cmdutil

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OutputFormatText  = "text"
	OutputFormatJSON  = "json"
	OutputFormatSARIF = "sarif"
)

Valid output format constants

View Source
const (
	// MaxFileSize limits file size to prevent DoS attacks (10MB).
	MaxFileSize = 10 * 1024 * 1024

	// MaxStdinSize limits stdin input to prevent DoS attacks (10MB).
	MaxStdinSize = 10 * 1024 * 1024
)

Variables

ValidOutputFormats lists all supported output formats for validation

Functions

func DetectInputMode

func DetectInputMode(args []string) (bool, string, error)

DetectInputMode determines the input mode based on arguments and stdin state.

func ExpandDirectory

func ExpandDirectory(dir string) ([]string, error)

ExpandDirectory finds SQL files in a directory.

func ExpandFileArgs

func ExpandFileArgs(args []string) ([]string, error)

ExpandFileArgs expands file arguments, handling directories and wildcards.

func IsBrokenPipe

func IsBrokenPipe(err error) bool

IsBrokenPipe checks if an error is a broken pipe error.

func IsStdinPipe

func IsStdinPipe() bool

IsStdinPipe detects if stdin is a pipe (not a terminal).

func IsValidSQLFileExtension

func IsValidSQLFileExtension(ext string) bool

IsValidSQLFileExtension checks if the file extension is acceptable for SQL.

func LooksLikeSQL

func LooksLikeSQL(input string) bool

LooksLikeSQL performs basic heuristic checks to see if input looks like SQL.

func ReadFromStdin

func ReadFromStdin() ([]byte, error)

ReadFromStdin reads SQL content from stdin with security limits.

func ShouldReadFromStdin

func ShouldReadFromStdin(args []string) bool

ShouldReadFromStdin determines if we should read from stdin based on args.

func TrackChangedFlags

func TrackChangedFlags(cmd *cobra.Command) map[string]bool

TrackChangedFlags returns a map of flag names that were explicitly set on the command line. This includes both local flags and parent persistent flags.

func ValidateFileAccess

func ValidateFileAccess(path string) error

ValidateFileAccess checks if we can read the file and it meets size requirements.

func ValidateStdinInput

func ValidateStdinInput(content []byte) error

ValidateStdinInput validates stdin content for security.

func WriteOutput

func WriteOutput(content []byte, outputFile string, writer io.Writer) error

WriteOutput writes content to the specified output destination.

Types

type InputResult

type InputResult struct {
	Type    InputType
	Content []byte
	Source  string // Original input string or file path
}

InputResult contains the detected input type and content.

func DetectAndReadInput

func DetectAndReadInput(input string) (*InputResult, error)

DetectAndReadInput robustly detects whether input is a file path or direct SQL and returns the SQL content with proper validation and security limits.

func GetInputSource

func GetInputSource(arg string) (*InputResult, error)

GetInputSource determines the source of input and returns the content.

func ReadInputWithFallback

func ReadInputWithFallback(args []string) (*InputResult, error)

ReadInputWithFallback tries to read from the specified source with stdin fallback.

type InputType

type InputType int

InputType represents the type of input detected.

const (
	// InputTypeSQL indicates direct SQL query string input.
	InputTypeSQL InputType = iota
	// InputTypeFile indicates file path input.
	InputTypeFile
)

type RootFlags

type RootFlags struct {
	Verbose    *bool
	OutputFile *string
	Format     *string
}

RootFlags holds pointers to the root command's persistent flag values. Sub-packages receive this to access global flags without circular imports.

Jump to

Keyboard shortcuts

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