refactor(processor): inject cfg into file-mutating methods
This commit is contained in:
@@ -80,6 +80,14 @@ func (p *Processor) processGitChanges() error {
|
|||||||
fmt.Printf("Found %d supported files with changes to process\n", len(supportedChanges))
|
fmt.Printf("Found %d supported files with changes to process\n", len(supportedChanges))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg, _, cfgErr := config.Load()
|
||||||
|
if cfgErr != nil {
|
||||||
|
if p.cli.Verbose {
|
||||||
|
fmt.Printf("Warning: failed to load config, using defaults: %v\n", cfgErr)
|
||||||
|
}
|
||||||
|
cfg = config.Default()
|
||||||
|
}
|
||||||
|
|
||||||
totals := &GitTotals{}
|
totals := &GitTotals{}
|
||||||
|
|
||||||
for _, change := range supportedChanges {
|
for _, change := range supportedChanges {
|
||||||
@@ -94,7 +102,7 @@ func (p *Processor) processGitChanges() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := p.processFileWithLineRanges(change.Path, change.LineRanges); err != nil {
|
if err := p.processFileWithLineRanges(change.Path, change.LineRanges, cfg); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error processing %s: %v\n", change.Path, err)
|
fmt.Fprintf(os.Stderr, "Error processing %s: %v\n", change.Path, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -109,18 +117,12 @@ func (p *Processor) processGitChanges() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Processor) processFileWithLineRanges(filename string, lineRanges []git.LineRange) error {
|
func (p *Processor) processFileWithLineRanges(filename string, lineRanges []git.LineRange, cfg *config.Config) error {
|
||||||
language, err := DetectLanguage(filename)
|
language, err := DetectLanguage(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, _, err := config.Load()
|
|
||||||
if err != nil && p.cli.Verbose {
|
|
||||||
fmt.Printf("Warning: failed to load config, using defaults: %v\n", err)
|
|
||||||
cfg = config.Default()
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.cli.Verbose {
|
if p.cli.Verbose {
|
||||||
fmt.Printf("Processing %s (language: %s)\n", filename, GetLanguageName(filename))
|
fmt.Printf("Processing %s (language: %s)\n", filename, GetLanguageName(filename))
|
||||||
if len(lineRanges) == 0 {
|
if len(lineRanges) == 0 {
|
||||||
|
|||||||
@@ -28,6 +28,14 @@ func (p *Processor) Process() error {
|
|||||||
return p.processGitChanges()
|
return p.processGitChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg, _, err := config.Load()
|
||||||
|
if err != nil {
|
||||||
|
if p.cli.Verbose {
|
||||||
|
fmt.Printf("Warning: failed to load config, using defaults: %v\n", err)
|
||||||
|
}
|
||||||
|
cfg = config.Default()
|
||||||
|
}
|
||||||
|
|
||||||
info, err := os.Stat(p.cli.Path)
|
info, err := os.Stat(p.cli.Path)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return fmt.Errorf("path not found: %s", p.cli.Path)
|
return fmt.Errorf("path not found: %s", p.cli.Path)
|
||||||
@@ -37,7 +45,7 @@ func (p *Processor) Process() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
return p.processDirectory(p.cli.Path)
|
return p.processDirectory(p.cli.Path, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if IsIgnored(p.cli.Path) {
|
if IsIgnored(p.cli.Path) {
|
||||||
@@ -45,10 +53,10 @@ func (p *Processor) Process() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.processFile(p.cli.Path)
|
return p.processFile(p.cli.Path, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Processor) processDirectory(dirPath string) error {
|
func (p *Processor) processDirectory(dirPath string, cfg *config.Config) error {
|
||||||
var files []string
|
var files []string
|
||||||
|
|
||||||
if p.cli.Recursive {
|
if p.cli.Recursive {
|
||||||
@@ -93,7 +101,7 @@ func (p *Processor) processDirectory(dirPath string) error {
|
|||||||
fmt.Printf("Processing: %s\n", file)
|
fmt.Printf("Processing: %s\n", file)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.processFile(file); err != nil {
|
if err := p.processFile(file, cfg); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error processing %s: %v\n", file, err)
|
fmt.Fprintf(os.Stderr, "Error processing %s: %v\n", file, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -102,7 +110,7 @@ func (p *Processor) processDirectory(dirPath string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Processor) processFile(filename string) error {
|
func (p *Processor) processFile(filename string, cfg *config.Config) error {
|
||||||
language, err := DetectLanguage(filename)
|
language, err := DetectLanguage(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -123,16 +131,10 @@ func (p *Processor) processFile(filename string) error {
|
|||||||
return p.showPreview(filename, language)
|
return p.showPreview(filename, language)
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.processFileInMemory(filename, language)
|
return p.processFileInMemory(filename, language, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Processor) processFileInMemory(filename string, language types.Language) error {
|
func (p *Processor) processFileInMemory(filename string, language types.Language, cfg *config.Config) error {
|
||||||
|
|
||||||
cfg, _, err := config.Load()
|
|
||||||
if err != nil && p.cli.Verbose {
|
|
||||||
fmt.Printf("Warning: failed to load config, using defaults: %v\n", err)
|
|
||||||
cfg = config.Default()
|
|
||||||
}
|
|
||||||
|
|
||||||
file, err := os.Open(filename)
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user