MCPcopy
hub / github.com/six2dez/OneListForAll / Run

Function Run

internal/classify/run.go:23–110  ·  view source on GitHub ↗

Run walks all source directories, classifies each .txt file, and writes the classification index.

(opts Options)

Source from the content-addressed store, hash-verified

21// Run walks all source directories, classifies each .txt file,
22// and writes the classification index.
23func Run(opts Options) (ClassificationIndex, error) {
24 cfg, err := config.Load(opts.ConfigPath)
25 if err != nil {
26 return ClassificationIndex{}, err
27 }
28
29 taxonomy, err := config.LoadTaxonomy(opts.TaxonomyPath)
30 if err != nil {
31 return ClassificationIndex{}, err
32 }
33
34 classifier, err := NewClassifier(taxonomy, cfg.Classification, cfg.Sources)
35 if err != nil {
36 return ClassificationIndex{}, err
37 }
38
39 entries := make([]FileClassification, 0, 4096)
40
41 for _, src := range cfg.Sources {
42 srcDir := filepath.Join(opts.SourcesDir, src.Name)
43 if _, err := os.Stat(srcDir); os.IsNotExist(err) {
44 continue
45 }
46
47 for _, p := range src.Paths {
48 root := srcDir
49 if p != "all" {
50 root = filepath.Join(srcDir, p)
51 }
52 if _, err := os.Stat(root); os.IsNotExist(err) {
53 continue
54 }
55
56 err := filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
57 if err != nil {
58 return err
59 }
60 if d.IsDir() {
61 return nil
62 }
63 if !strings.HasSuffix(strings.ToLower(d.Name()), ".txt") {
64 return nil
65 }
66
67 relPath, err := filepath.Rel(srcDir, path)
68 if err != nil {
69 return err
70 }
71
72 // Handle version collapsing: mark version files as not short eligible
73 if src.CollapseVersions && IsVersionPath(relPath, src.VersionDirPattern) {
74 fc, err := classifier.ClassifyFile(src.Name, srcDir, relPath)
75 if err != nil {
76 fmt.Fprintf(os.Stderr, "warning: classify %s/%s: %v\n", src.Name, relPath, err)
77 return nil
78 }
79 fc.IsShortEligible = false // version files are never short
80 entries = append(entries, fc)

Callers 2

runClassifyFunction · 0.92
runPipelineFunction · 0.92

Calls 7

ClassifyFileMethod · 0.95
LoadFunction · 0.92
LoadTaxonomyFunction · 0.92
NewClassifierFunction · 0.85
IsVersionPathFunction · 0.85
computeStatsFunction · 0.85
WriteIndexFunction · 0.85

Tested by

no test coverage detected