cmd

package
v0.18.9 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SummaryTableWidthFull is the width of summary tables for terminals >= 100 width
	// Calculated as: 40 (rule) + 12 (violations) + 50 (impact) + 4 (spacing) + 1 (leading) = 107
	SummaryTableWidthFull = 107

	// SummaryTableWidthMedium is the width for terminals 80-99 width
	// Calculated as: 25 (rule) + 10 (violations) + 30 (impact) + 4 (spacing) + 1 (leading) = 70
	SummaryTableWidthMedium = 70

	// SummaryTableWidthSmall is the width for terminals 60-79 width
	// Calculated as: 20 (rule) + 8 (violations) + 20 (impact) + 4 (spacing) + 1 (leading) = 53
	SummaryTableWidthSmall = 53
)

Constants for summary table widths at different terminal sizes

View Source
const (
	HardModeEnabled           = "🚨 HARD MODE ENABLED 🚨"
	HardModeWithCustomRuleset = "🚨 OWASP Rules added to custom ruleset 🚨"
)

Hard mode message constants

Variables

This section is empty.

Functions

func BuildResults added in v0.0.4

func BuildResults(
	silent bool,
	hardMode bool,
	rulesetFlag string,
	specBytes []byte,
	customFunctions map[string]model.RuleFunction,
	base string,
	remote bool,
	timeout time.Duration,
	httpClientConfig utils.HTTPClientConfig,
	ignoredItems model.IgnoredItems) (*model.RuleResultSet, *motor.RuleSetExecutionResult, error)

func BuildResultsWithDocCheckSkip added in v0.2.7

func BuildResultsWithDocCheckSkip(
	silent bool,
	hardMode bool,
	rulesetFlag string,
	specBytes []byte,
	customFunctions map[string]model.RuleFunction,
	base string,
	remote bool,
	skipCheck bool,
	timeout time.Duration,
	httpClientConfig utils.HTTPClientConfig,
	ignoredItems model.IgnoredItems) (*model.RuleResultSet, *motor.RuleSetExecutionResult, error)

func BuildRuleSetFromUserSuppliedLocation added in v0.17.8

func BuildRuleSetFromUserSuppliedLocation(rulesetFlag string, rs rulesets.RuleSets, remote bool, httpClient *http.Client) (*rulesets.RuleSet, error)

BuildRuleSetFromUserSuppliedLocation creates a ready to run ruleset from a location (file path or URL)

func BuildRuleSetFromUserSuppliedSet added in v0.0.5

func BuildRuleSetFromUserSuppliedSet(rsBytes []byte, rs rulesets.RuleSets) (*rulesets.RuleSet, error)

BuildRuleSetFromUserSuppliedSet creates a ready to run ruleset, augmented or provided by a user configured ruleset. This ruleset could be lifted directly from a Spectral configuration.

func BuildRuleSetFromUserSuppliedSetWithHTTPClient added in v0.17.8

func BuildRuleSetFromUserSuppliedSetWithHTTPClient(rsBytes []byte, rs rulesets.RuleSets, httpClient *http.Client) (*rulesets.RuleSet, error)

BuildRuleSetFromUserSuppliedSetWithHTTPClient creates a ready to run ruleset, augmented or provided by a user configured ruleset with HTTP client support for certificate authentication.

func CheckFailureSeverity added in v0.0.16

func CheckFailureSeverity(failSeverityFlag string, errors int, warnings int, informs int) error

func CreateHTTPClientFromFlags added in v0.18.0

func CreateHTTPClientFromFlags(flags *LintFlags) (*http.Client, error)

CreateHTTPClientFromFlags creates an HTTP client based on certificate flags

func Execute

func Execute(version, commit, date string)

func ExtractSpecFromReport added in v0.18.0

func ExtractSpecFromReport(report *vacuum_report.VacuumReport) ([]byte, string, error)

ExtractSpecFromReport extracts the specification bytes from a vacuum report. Returns the spec bytes and the original filename if available.

func GetBundleCommand added in v0.8.0

func GetBundleCommand() *cobra.Command

func GetCommit added in v0.18.0

func GetCommit() string

GetCommit returns the current commit hash for compatibility

func GetDashboardCommand

func GetDashboardCommand() *cobra.Command

func GetDate added in v0.18.0

func GetDate() string

GetDate returns the current build date for compatibility

func GetGenerateIgnoreFileCommand added in v0.15.0

func GetGenerateIgnoreFileCommand() *cobra.Command

func GetGenerateRulesetCommand added in v0.0.5

func GetGenerateRulesetCommand() *cobra.Command

func GetGenerateVersionCommand added in v0.6.0

func GetGenerateVersionCommand() *cobra.Command

func GetHTMLReportCommand added in v0.0.2

func GetHTMLReportCommand() *cobra.Command

GetHTMLReportCommand returns a cobra command for generating an HTML Report.

func GetHTTPClientConfig added in v0.18.0

func GetHTTPClientConfig(flags *LintFlags) (utils.HTTPClientConfig, error)

GetHTTPClientConfig creates HTTPClientConfig from flags

func GetLanguageServerCommand added in v0.9.0

func GetLanguageServerCommand() *cobra.Command

func GetLintCommand added in v0.0.5

func GetLintCommand() *cobra.Command

func GetRootCommand added in v0.3.5

func GetRootCommand() *cobra.Command

func GetSpectralReportCommand

func GetSpectralReportCommand() *cobra.Command

func GetVacuumReportCommand added in v0.0.4

func GetVacuumReportCommand() *cobra.Command

func GetVersion added in v0.18.0

func GetVersion() string

GetVersion returns the current version string for compatibility

func IsVacuumReport added in v0.18.0

func IsVacuumReport(filePath string) bool

IsVacuumReport checks if a file is a vacuum report without fully loading it

func LoadCustomFunctions added in v0.0.11

func LoadCustomFunctions(functionsFlag string, silence bool) (map[string]model.RuleFunction, error)

LoadCustomFunctions will scan for (and load) custom functions defined as vacuum plugins.

func LoadIgnoreFile added in v0.18.0

func LoadIgnoreFile(ignoreFile string, silent, pipeline, noStyle bool) (model.IgnoredItems, error)

LoadIgnoreFile loads and parses the ignore file if specified

func LoadReportOnly added in v0.18.0

func LoadReportOnly(filePath string) (*vacuum_report.VacuumReport, error)

LoadReportOnly attempts to load a file specifically as a vacuum report. Returns an error if the file is not a valid vacuum report.

func LoadRulesetWithConfig added in v0.18.0

func LoadRulesetWithConfig(flags *LintFlags, logger *slog.Logger) (*rulesets.RuleSet, error)

LoadRulesetWithConfig loads and configures the ruleset based on flags

func MergeOWASPRulesToRuleSet added in v0.17.11

func MergeOWASPRulesToRuleSet(selectedRS *rulesets.RuleSet, hardModeFlag bool) bool

MergeOWASPRulesToRuleSet merges OWASP rules into the provided ruleset when hard mode is enabled. This fixes issue #552 where -z flag was ignored when using -r flag. Returns true if OWASP rules were merged, false otherwise.

func PrintBanner added in v0.0.5

func PrintBanner(noStyle ...bool)

func RenderBufferedLogs added in v0.18.0

func RenderBufferedLogs(bufferedLogger *logging.BufferedLogger, noStyle bool)

RenderBufferedLogs renders the buffered logs with proper formatting and spacing

func RenderMarkdownSummary added in v0.18.0

func RenderMarkdownSummary(rso RenderSummaryOptions)

func RenderTime added in v0.0.5

func RenderTime(timeFlag bool, duration time.Duration, fi int64)

RenderTime will render out the time taken to process a specification, and the size of the file in kb.

func RenderTimeAndFiles added in v0.5.1

func RenderTimeAndFiles(timeFlag bool, duration time.Duration, fileSize int64, totalFiles int)

RenderTimeAndFiles will render out the time taken to process a specification, and the size of the file in kb. it will also render out how many files were processed.

func ResolveBasePathForFile added in v0.18.1

func ResolveBasePathForFile(specFilePath string, baseFlag string) (string, error)

ResolveBasePathForFile determines the base path to use for a given spec file. If baseFlag is explicitly set (not empty), it returns that value unchanged. If baseFlag is empty, it returns the absolute directory of the spec file.

func ResolveConfigPath added in v0.18.9

func ResolveConfigPath(raw string) (string, error)

ResolveConfigPath normalizes paths supplied via flags or configuration. It expands ~ and environment variables, and if the path is relative, resolves it against the configuration directory when available.

func SetupVacuumEnvironment added in v0.18.0

func SetupVacuumEnvironment(flags *LintFlags)

SetupVacuumEnvironment configures the environment based on flags

Types

type FileProcessingConfig added in v0.18.0

type FileProcessingConfig struct {
	Flags           *LintFlags
	Logger          *slog.Logger
	BufferedLogger  *logging.BufferedLogger
	SelectedRuleset *rulesets.RuleSet
	CustomFunctions map[string]model.RuleFunction
	IgnoredItems    model.IgnoredItems
}

FileProcessingConfig contains all configuration needed to process a file

type FileProcessingResult added in v0.18.0

type FileProcessingResult struct {
	Results  []*model.RuleFunctionResult
	Errors   int
	Warnings int
	Informs  int
	FileSize int64
	Logs     []string
	Error    error
}

FileProcessingResult contains the results of processing a single file

func ProcessSingleFileOptimized added in v0.18.0

func ProcessSingleFileOptimized(fileName string, config *FileProcessingConfig) *FileProcessingResult

ProcessSingleFileOptimized processes a single file using pre-loaded configuration

type LintFlags added in v0.18.0

type LintFlags struct {
	GlobPattern              string
	DetailsFlag              bool
	SnippetsFlag             bool
	ErrorsFlag               bool
	CategoryFlag             string
	SilentFlag               bool
	NoStyleFlag              bool
	NoBannerFlag             bool
	NoMessageFlag            bool
	AllResultsFlag           bool
	ShowRules                bool
	PipelineOutput           bool
	FailSeverityFlag         string
	BaseFlag                 string
	RemoteFlag               bool
	SkipCheckFlag            bool
	TimeoutFlag              int
	RulesetFlag              string
	FunctionsFlag            string
	TimeFlag                 bool
	HardModeFlag             bool
	IgnoreFile               string
	NoClipFlag               bool
	ExtRefsFlag              bool
	IgnoreArrayCircleRef     bool
	IgnorePolymorphCircleRef bool
	MinScore                 int
	CertFile                 string
	KeyFile                  string
	CAFile                   string
	Insecure                 bool
	DebugFlag                bool
}

LintFlags holds all the command line flags for lint operations

func ReadLintFlags added in v0.18.0

func ReadLintFlags(cmd *cobra.Command) *LintFlags

ReadLintFlags reads all lint-related flags from the command

type RenderDetailsOptions added in v0.18.0

type RenderDetailsOptions struct {
	Results    []*model.RuleFunctionResult
	SpecData   []string
	Snippets   bool
	Errors     bool
	Silent     bool
	NoMessage  bool
	AllResults bool
	NoClip     bool
	FileName   string
	NoStyle    bool
}

RenderDetailsOptions contains all options for rendering detailed results

type RenderSummaryOptions added in v0.16.15

type RenderSummaryOptions struct {
	RuleResultSet  *model.RuleResultSet
	RuleSet        *rulesets.RuleSet
	RuleCategories []*model.RuleCategory
	Statistics     *reports.ReportStatistics
	Filename       string
	Silent         bool
	NoStyle        bool
	PipelineOutput bool
	ShowRules      bool
	RenderRules    bool
	ReportStats    *reports.ReportStatistics
	TotalFiles     int
	Severity       string
}

RenderSummaryOptions contains all options for rendering summary

type ReportLoadResult added in v0.18.0

type ReportLoadResult struct {
	// If the file was a pre-compiled report
	IsReport bool
	Report   *vacuum_report.VacuumReport

	// The raw spec bytes (either from file or extracted from report)
	SpecBytes []byte

	// The filename/path for display
	FileName string

	// Pre-processed results if from a report
	ResultSet *model.RuleResultSet
}

ReportLoadResult contains the results of attempting to load a file as either a pre-compiled vacuum report or raw OpenAPI spec

func LoadFileAsReportOrSpec added in v0.18.0

func LoadFileAsReportOrSpec(filePath string) (*ReportLoadResult, error)

LoadFileAsReportOrSpec attempts to load a file as either a pre-compiled vacuum report or as a raw OpenAPI specification. It returns a ReportLoadResult with all the necessary data for either case.

type SeverityInfo added in v0.18.0

type SeverityInfo struct {
	Icon      string
	Text      string
	Color     string
	Formatted string
}

SeverityInfo holds severity display information

type TableConfig added in v0.18.0

type TableConfig struct {
	Width         int
	ShowCategory  bool
	ShowPath      bool
	ShowRule      bool
	UseTreeFormat bool
	LocationWidth int
	SeverityWidth int
	MessageWidth  int
	RuleWidth     int
	CategoryWidth int
	PathWidth     int
	NoMessage     bool
	NoClip        bool
	NoStyle       bool
}

TableConfig holds all table configuration and column widths

type VersionInfo added in v0.18.0

type VersionInfo struct {
	Version   string
	Commit    string
	Date      string
	GoVersion string
	Modified  bool
}

func GetVersionInfo added in v0.18.0

func GetVersionInfo() VersionInfo

GetVersionInfo returns version information using ldflags (if set) or debug.ReadBuildInfo as fallback This hybrid approach supports both: - Package managers using ldflags: go build -ldflags "-X main.version=v1.0.0 ..." - Direct go install: go install github.com/daveshanley/vacuum@latest

Jump to

Keyboard shortcuts

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