Documentation
¶
Index ¶
- Constants
- Variables
- func DetectInputMode(args []string) (bool, string, error)
- func ExpandDirectory(dir string) ([]string, error)
- func ExpandFileArgs(args []string) ([]string, error)
- func IsBrokenPipe(err error) bool
- func IsStdinPipe() bool
- func IsValidSQLFileExtension(ext string) bool
- func LooksLikeSQL(input string) bool
- func ReadFromStdin() ([]byte, error)
- func ShouldReadFromStdin(args []string) bool
- func TrackChangedFlags(cmd *cobra.Command) map[string]bool
- func ValidateFileAccess(path string) error
- func ValidateStdinInput(content []byte) error
- func WriteOutput(content []byte, outputFile string, writer io.Writer) error
- type InputResult
- type InputType
- type RootFlags
Constants ¶
const ( OutputFormatText = "text" OutputFormatJSON = "json" OutputFormatSARIF = "sarif" )
Valid output format constants
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 ¶
var ValidOutputFormats = []string{OutputFormatText, OutputFormatJSON, OutputFormatSARIF}
ValidOutputFormats lists all supported output formats for validation
Functions ¶
func DetectInputMode ¶
DetectInputMode determines the input mode based on arguments and stdin state.
func ExpandDirectory ¶
ExpandDirectory finds SQL files in a directory.
func ExpandFileArgs ¶
ExpandFileArgs expands file arguments, handling directories and wildcards.
func IsBrokenPipe ¶
IsBrokenPipe checks if an error is a broken pipe error.
func IsValidSQLFileExtension ¶
IsValidSQLFileExtension checks if the file extension is acceptable for SQL.
func LooksLikeSQL ¶
LooksLikeSQL performs basic heuristic checks to see if input looks like SQL.
func ReadFromStdin ¶
ReadFromStdin reads SQL content from stdin with security limits.
func ShouldReadFromStdin ¶
ShouldReadFromStdin determines if we should read from stdin based on args.
func TrackChangedFlags ¶
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 ¶
ValidateFileAccess checks if we can read the file and it meets size requirements.
func ValidateStdinInput ¶
ValidateStdinInput validates stdin content for security.
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.