diff --git a/cmd/dashboard.go b/cmd/dashboard.go index 7c617299..74347efe 100644 --- a/cmd/dashboard.go +++ b/cmd/dashboard.go @@ -44,6 +44,7 @@ func GetDashboardCommand() *cobra.Command { skipCheckFlag, _ := cmd.Flags().GetBool("skip-check") timeoutFlag, _ := cmd.Flags().GetInt("timeout") hardModeFlag, _ := cmd.Flags().GetBool("hard-mode") + silent, _ := cmd.Flags().GetBool("silent") var err error vacuumReport, specBytes, _ := vacuum_report.BuildVacuumReportFromFile(args[0]) @@ -61,7 +62,7 @@ func GetDashboardCommand() *cobra.Command { if vacuumReport == nil { functionsFlag, _ := cmd.Flags().GetString("functions") - customFunctions, _ := LoadCustomFunctions(functionsFlag) + customFunctions, _ := LoadCustomFunctions(functionsFlag, silent) rulesetFlag, _ := cmd.Flags().GetString("ruleset") resultSet, ruleset, err = BuildResultsWithDocCheckSkip(false, hardModeFlag, rulesetFlag, specBytes, customFunctions, diff --git a/cmd/html_report.go b/cmd/html_report.go index d12dad3a..f40b5612 100644 --- a/cmd/html_report.go +++ b/cmd/html_report.go @@ -46,6 +46,7 @@ func GetHTMLReportCommand() *cobra.Command { skipCheckFlag, _ := cmd.Flags().GetBool("skip-check") timeoutFlag, _ := cmd.Flags().GetInt("timeout") hardModeFlag, _ := cmd.Flags().GetBool("hard-mode") + silent, _ := cmd.Flags().GetBool("silent") // disable color and styling, for CI/CD use. // https://github.com/daveshanley/vacuum/issues/234 @@ -91,7 +92,7 @@ func GetHTMLReportCommand() *cobra.Command { if vacuumReport == nil { functionsFlag, _ := cmd.Flags().GetString("functions") - customFunctions, _ := LoadCustomFunctions(functionsFlag) + customFunctions, _ := LoadCustomFunctions(functionsFlag, silent) rulesetFlag, _ := cmd.Flags().GetString("ruleset") resultSet, ruleset, err = BuildResultsWithDocCheckSkip(false, hardModeFlag, rulesetFlag, specBytes, customFunctions, diff --git a/cmd/lint.go b/cmd/lint.go index 26f6c649..3bf73092 100644 --- a/cmd/lint.go +++ b/cmd/lint.go @@ -105,7 +105,7 @@ func GetLintCommand() *cobra.Command { defaultRuleSets := rulesets.BuildDefaultRuleSetsWithLogger(logger) selectedRS := defaultRuleSets.GenerateOpenAPIRecommendedRuleSet() - customFunctions, _ := LoadCustomFunctions(functionsFlag) + customFunctions, _ := LoadCustomFunctions(functionsFlag, silent) // HARD MODE if hardModeFlag { diff --git a/cmd/shared_functions.go b/cmd/shared_functions.go index 0b6bb203..b8b4ef56 100644 --- a/cmd/shared_functions.go +++ b/cmd/shared_functions.go @@ -82,10 +82,10 @@ func PrintBanner() { } // LoadCustomFunctions will scan for (and load) custom functions defined as vacuum plugins. -func LoadCustomFunctions(functionsFlag string) (map[string]model.RuleFunction, error) { +func LoadCustomFunctions(functionsFlag string, silence bool) (map[string]model.RuleFunction, error) { // check custom functions if functionsFlag != "" { - pm, err := plugin.LoadFunctions(functionsFlag) + pm, err := plugin.LoadFunctions(functionsFlag, silence) if err != nil { pterm.Error.Printf("Unable to open custom functions: %v\n", err) pterm.Println() diff --git a/cmd/spectral_report.go b/cmd/spectral_report.go index 3aadf4a7..d495c9ec 100644 --- a/cmd/spectral_report.go +++ b/cmd/spectral_report.go @@ -133,7 +133,7 @@ func GetSpectralReportCommand() *cobra.Command { // and see if it's valid. If so - let's go! if rulesetFlag != "" { - customFunctions, _ = LoadCustomFunctions(functionsFlag) + customFunctions, _ = LoadCustomFunctions(functionsFlag, true) rsBytes, rsErr := os.ReadFile(rulesetFlag) if rsErr != nil { pterm.Error.Printf("Unable to read ruleset file '%s': %s\n", rulesetFlag, rsErr.Error()) diff --git a/cmd/vacuum_report.go b/cmd/vacuum_report.go index a1f1a9ec..465e44d8 100644 --- a/cmd/vacuum_report.go +++ b/cmd/vacuum_report.go @@ -134,7 +134,7 @@ func GetVacuumReportCommand() *cobra.Command { // and see if it's valid. If so - let's go! if rulesetFlag != "" { - customFunctions, _ = LoadCustomFunctions(functionsFlag) + customFunctions, _ = LoadCustomFunctions(functionsFlag, true) rsBytes, rsErr := os.ReadFile(rulesetFlag) if rsErr != nil { diff --git a/motor/rule_applicator_test.go b/motor/rule_applicator_test.go index e5b8567b..aa288cde 100644 --- a/motor/rule_applicator_test.go +++ b/motor/rule_applicator_test.go @@ -2038,7 +2038,7 @@ custom: id: "1234" ` // load custom functions - pm, err := plugin.LoadFunctions("../plugin/sample/js") + pm, err := plugin.LoadFunctions("../plugin/sample/js", false) assert.NoError(t, err) // create a new document. @@ -2084,7 +2084,7 @@ func TestApplyRules_TestRules_Custom_JS_Function_CustomDoc_CoreFunction(t *testi notCustom: true" ` // load custom functions - pm, err := plugin.LoadFunctions("../plugin/sample/js") + pm, err := plugin.LoadFunctions("../plugin/sample/js", false) assert.NoError(t, err) // create a new document. @@ -2136,7 +2136,7 @@ paths: patch: something ` // load custom functions - pm, err := plugin.LoadFunctions("../plugin/sample/js") + pm, err := plugin.LoadFunctions("../plugin/sample/js", false) assert.NoError(t, err) // create a new document. @@ -2182,7 +2182,7 @@ func TestApplyRules_TestRules_Custom_JS_Function_CustomDoc_CoreFunction_Function notCustom: true" ` // load custom functions - pm, err := plugin.LoadFunctions("../plugin/sample/js") + pm, err := plugin.LoadFunctions("../plugin/sample/js", false) assert.NoError(t, err) // create a new document. diff --git a/plugin/plugin_loader.go b/plugin/plugin_loader.go index 456fcfde..7be729dc 100644 --- a/plugin/plugin_loader.go +++ b/plugin/plugin_loader.go @@ -15,7 +15,7 @@ import ( ) // LoadFunctions will load custom functions found in the supplied path -func LoadFunctions(path string) (*Manager, error) { +func LoadFunctions(path string, silence bool) (*Manager, error) { dirEntries, err := os.ReadDir(path) if err != nil { @@ -29,8 +29,9 @@ func LoadFunctions(path string) (*Manager, error) { fPath := filepath.Join(path, entry.Name()) // found something - pterm.Info.Printf("Located custom function plugin: %s\n", fPath) - + if !silence { + pterm.Info.Printf("Located custom function plugin: %s\n", fPath) + } // let's try and open it. p, e := plugin.Open(fPath) if e != nil { @@ -65,8 +66,9 @@ func LoadFunctions(path string) (*Manager, error) { function := javascript.NewJSRuleFunction(fName, string(p)) // found something - pterm.Info.Printf("Located custom javascript function: '%s'\n", function.GetSchema().Name) - + if !silence { + pterm.Info.Printf("Located custom javascript function: '%s'\n", function.GetSchema().Name) + } // check if the function is valid sErr := function.CheckScript() diff --git a/plugin/plugin_loader_test.go b/plugin/plugin_loader_test.go index 185b5383..eb33cac0 100644 --- a/plugin/plugin_loader_test.go +++ b/plugin/plugin_loader_test.go @@ -7,20 +7,20 @@ import ( ) func TestLoadFunctions_Nowhere(t *testing.T) { - pm, err := LoadFunctions("nowhere") + pm, err := LoadFunctions("nowhere", false) assert.Nil(t, pm) assert.Error(t, err) } func TestLoadFunctions(t *testing.T) { - pm, err := LoadFunctions("../model/test_files") + pm, err := LoadFunctions("../model/test_files", false) assert.NotNil(t, pm) assert.NoError(t, err) assert.Equal(t, 0, pm.LoadedFunctionCount()) } func TestLoadFunctions_JavaScript_OK(t *testing.T) { - pm, err := LoadFunctions("sample/js") + pm, err := LoadFunctions("sample/js", false) assert.NotNil(t, pm) assert.NoError(t, err) assert.Equal(t, 5, pm.LoadedFunctionCount()) @@ -31,7 +31,7 @@ func TestLoadFunctions_JavaScript_OK(t *testing.T) { } func TestLoadFunctions_Sample(t *testing.T) { - pm, err := LoadFunctions("sample") + pm, err := LoadFunctions("sample", false) if runtime.GOOS != "windows" { // windows does not support this feature, at all. assert.NotNil(t, pm) assert.NoError(t, err) @@ -40,7 +40,7 @@ func TestLoadFunctions_Sample(t *testing.T) { } func TestLoadFunctions_TestCompile(t *testing.T) { - pm, err := LoadFunctions("sample") + pm, err := LoadFunctions("sample", false) if runtime.GOOS != "windows" { // windows does not support this feature, at all. assert.NotNil(t, pm) assert.NoError(t, err)