Brian McGee
5711caebb9
Introduces a `--walk` flag which can be used to tell `treefmt` how to traverse the directory specified by `--tree-root`. By default, it will attempt to use `git ls-files`. If this fails, it falls back to using the filesystem. You can explicitly traverse the filesystem instead of using git by providing `--walk filesystem`. Close #1 Reviewed-on: #19 Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com> Co-authored-by: Brian McGee <brian@bmcgee.ie> Co-committed-by: Brian McGee <brian@bmcgee.ie>
23 lines
342 B
Go
23 lines
342 B
Go
package walk
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
)
|
|
|
|
type filesystem struct {
|
|
root string
|
|
}
|
|
|
|
func (f filesystem) Root() string {
|
|
return f.root
|
|
}
|
|
|
|
func (f filesystem) Walk(_ context.Context, fn filepath.WalkFunc) error {
|
|
return filepath.Walk(f.root, fn)
|
|
}
|
|
|
|
func NewFilesystem(root string) (Walker, error) {
|
|
return filesystem{root}, nil
|
|
}
|