Skip to content

Commit

Permalink
Add debug logs for google#97
Browse files Browse the repository at this point in the history
  • Loading branch information
badouralix committed Apr 9, 2023
1 parent 596e973 commit 837b28e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions command/command.go
Expand Up @@ -113,13 +113,16 @@ func (c *Command) Run() error {

collectedPaths, err := c.collectPaths()
if err != nil {
fmt.Printf("[DEBUG ISSUE 97] collect paths returned err=%#v\n", err)
return err
}
fmt.Printf("[DEBUG ISSUE 97] collect paths returned collectedPaths=%#v\n", collectedPaths)
paths, err := c.analyzePaths(collectedPaths)
if err != nil {
log.Printf("path analysis found the following errors:\n%v", err)
log.Println("Continuing...")
}
fmt.Printf("[DEBUG ISSUE 97] analyze paths returned paths=%#v\n", paths)

switch c.Operation {
case OperationFormat:
Expand Down Expand Up @@ -164,7 +167,12 @@ func (c *Command) Run() error {
}

func (c *Command) collectPaths() ([]string, error) {
fmt.Printf("[DEBUG ISSUE 97] c.Config=%#v\n", c.Config)
fmt.Printf("[DEBUG ISSUE 97] c.Config.FormatterConfig=%#v\n", c.Config.FormatterConfig)

collector := c.makePathCollector()
fmt.Printf("[DEBUG ISSUE 97] collector=%#v\n", collector)

return collector.CollectPaths()
}

Expand Down
10 changes: 10 additions & 0 deletions path_collector.go
@@ -1,6 +1,7 @@
package yamlfmt

import (
"fmt"
"io/fs"
"log"
"os"
Expand All @@ -22,6 +23,7 @@ type FilepathCollector struct {
}

func (c *FilepathCollector) CollectPaths() ([]string, error) {
fmt.Printf("[DEBUG ISSUE 97] entered filepath collector\n")
pathsFound := []string{}
for _, inclPath := range c.Include {
info, err := os.Stat(inclPath)
Expand Down Expand Up @@ -99,18 +101,22 @@ type DoublestarCollector struct {
}

func (c *DoublestarCollector) CollectPaths() ([]string, error) {
fmt.Printf("[DEBUG ISSUE 97] entered doublestar collector\n")
includedPaths := []string{}
for _, pattern := range c.Include {
globMatches, err := doublestar.FilepathGlob(pattern)
if err != nil {
fmt.Printf("[DEBUG ISSUE 97] filepath glob returned err=%#v\n", includedPaths)
return nil, err
}
includedPaths = append(includedPaths, globMatches...)
}
fmt.Printf("[DEBUG ISSUE 97] includedPaths=%#v\n", includedPaths)

pathsToFormatSet := collections.Set[string]{}
for _, path := range includedPaths {
if len(c.Exclude) == 0 {
fmt.Printf("[DEBUG ISSUE 97] included because empty exclude path=%#v\n", path)
pathsToFormatSet.Add(path)
continue
}
Expand All @@ -124,13 +130,17 @@ func (c *DoublestarCollector) CollectPaths() ([]string, error) {
}
match, err := doublestar.PathMatch(filepath.Clean(pattern), absPath)
if err != nil {
fmt.Printf("[DEBUG ISSUE 97] path match returned err=%#v\n", err)
return nil, err
}
if match {
fmt.Printf("[DEBUG ISSUE 97] excluded because of pattern=%#v absPath=%#v\n", pattern, absPath)
excluded = true
}
fmt.Printf("[DEBUG ISSUE 97] no match pattern=%#v absPath=%#v\n", pattern, absPath)
}
if !excluded {
fmt.Printf("[DEBUG ISSUE 97] included because not excluded path=%#v\n", path)
pathsToFormatSet.Add(path)
}
}
Expand Down

0 comments on commit 837b28e

Please sign in to comment.