-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.go
More file actions
96 lines (77 loc) · 2.58 KB
/
api.go
File metadata and controls
96 lines (77 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package pathfinder
import (
"errors"
"path/filepath"
)
// Version returns the current version of the library.
func Version() string {
return "v0.3.3"
}
// Scan is the main entry point for the library.
// It takes a Config and returns a detailed CodebaseReport.
func Scan(config Config) (CodebaseReport, error) {
// set defaults if zero-values are present
if config.PathFlag == "" {
config.PathFlag = "."
}
if config.BufferSizeFlag == 0 {
config.BufferSizeFlag = 4 // default to 4KB
}
if config.MaxDepthFlag == 0 {
config.MaxDepthFlag = -1 // default to no limit
}
if config.WorkerFlag == 0 {
config.WorkerFlag = 16 // default to 16 concurrent workers
}
// validation
if !config.RecursiveFlag && config.MaxDepthFlag != -1 {
return CodebaseReport{}, errors.New("--max-depth flag is ignored when --recursive is false")
}
absPath, err := filepath.Abs(config.PathFlag)
if err != nil {
return CodebaseReport{}, err
}
// switch and validate buffer size
switch config.BufferSizeFlag {
case 4, 8, 16, 32, 64:
// valid so do nothing
default:
return CodebaseReport{}, errors.New("invalid Buffer Size. Allowed values are 4, 8, 16, 32, 64 (in KB)")
}
// prepare internal config (safe modification since we passed by value)
config.PathFlag = absPath
config.BufferSizeFlag = config.BufferSizeFlag * 1024
return scanCodebase(config)
}
// ScannedLanguages returns a list of all programming languages found in the scanned codebase.
func (c CodebaseReport) ScannedLanguages() []string {
languages := make([]string, 0, len(c.LanguageMetrics))
for _, langReport := range c.LanguageMetrics {
languages = append(languages, langReport.Metrics.Language)
}
return languages
}
// ScannedDirectories returns a list of all directories that were scanned in the codebase.
func (c CodebaseReport) ScannedDirectories() []string {
directories := make([]string, 0, len(c.DirMetrics))
for _, dirReport := range c.DirMetrics {
directories = append(directories, dirReport.Directory)
}
return directories
}
// ScannedFiles returns a list of all files that were scanned in the codebase.
func (c CodebaseReport) ScannedFiles() []string {
files := make([]string, 0, len(c.FileMetrics))
for _, fileReport := range c.FileMetrics {
files = append(files, fileReport.Path)
}
return files
}
// SupportedLanguages returns a list of all supported programming languages that Pathfinder can analyze.
func SupportedLanguages() []string {
languages := make([]string, 0, len(languageDefinitions))
for _, langDef := range languageDefinitions {
languages = append(languages, langDef.Name)
}
return languages
}