4
4
package cmd
5
5
6
6
import (
7
+ "context"
7
8
"fmt"
8
9
"github.com/daveshanley/vacuum/model"
9
10
"github.com/daveshanley/vacuum/plugin"
10
11
"github.com/daveshanley/vacuum/rulesets"
11
12
"github.com/dustin/go-humanize"
12
13
"github.com/pb33f/libopenapi/index"
13
14
"github.com/pterm/pterm"
15
+ "os"
16
+ "strings"
14
17
"time"
15
18
)
16
19
20
+
17
21
// BuildRuleSetFromUserSuppliedSet creates a ready to run ruleset, augmented or provided by a user
18
22
// configured ruleset. This ruleset could be lifted directly from a Spectral configuration.
19
23
func BuildRuleSetFromUserSuppliedSet (rsBytes []byte , rs rulesets.RuleSets ) (* rulesets.RuleSet , error ) {
@@ -29,6 +33,28 @@ func BuildRuleSetFromUserSuppliedSet(rsBytes []byte, rs rulesets.RuleSets) (*rul
29
33
return rs .GenerateRuleSetFromSuppliedRuleSet (userRS ), nil
30
34
}
31
35
36
+ // BuildRuleSetFromUserSuppliedLocation creates a ready to run ruleset from a location (file path or URL)
37
+ func BuildRuleSetFromUserSuppliedLocation (rulesetFlag string , rs rulesets.RuleSets , remote bool ) (* rulesets.RuleSet , error ) {
38
+ if strings .HasPrefix (rulesetFlag , "http" ) {
39
+ // Handle remote ruleset URL directly
40
+ if ! remote {
41
+ return nil , fmt .Errorf ("remote ruleset specified but remote flag is disabled (use --remote=true or -u=true)" )
42
+ }
43
+ downloadedRS , rsErr := rulesets .DownloadRemoteRuleSet (context .Background (), rulesetFlag )
44
+ if rsErr != nil {
45
+ return nil , rsErr
46
+ }
47
+ return rs .GenerateRuleSetFromSuppliedRuleSet (downloadedRS ), nil
48
+ } else {
49
+ // Handle local ruleset file
50
+ rsBytes , rsErr := os .ReadFile (rulesetFlag )
51
+ if rsErr != nil {
52
+ return nil , rsErr
53
+ }
54
+ return BuildRuleSetFromUserSuppliedSet (rsBytes , rs )
55
+ }
56
+ }
57
+
32
58
// RenderTimeAndFiles will render out the time taken to process a specification, and the size of the file in kb.
33
59
// it will also render out how many files were processed.
34
60
func RenderTimeAndFiles (timeFlag bool , duration time.Duration , fileSize int64 , totalFiles int ) {
0 commit comments