Skip to content

Commit bb09118

Browse files
committed
✨ feat(scanner): add --max-depth flag for configurable scan depth
1 parent 244e634 commit bb09118

5 files changed

Lines changed: 381 additions & 5 deletions

File tree

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ linters:
127127
- errcheck
128128
- noctx
129129
path: _test\.go
130+
- linters:
131+
- gosec
132+
- gocyclo
133+
path: _test\.go
134+
text: "(G301|G304|cyclomatic complexity)"
130135
presets:
131136
- std-error-handling
132137

cmd/gohome/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func initDependencies(cfg *config.AppConfig) *dependencies {
9999
WithInterval(100 * time.Millisecond)
100100
sp.Start()
101101

102-
repos, err := scanner.ScanGitRepos(absPath)
102+
repos, err := scanner.ScanGitRepos(absPath, cfg.MaxDepth)
103103
sp.Stop()
104104

105105
if err != nil {

internal/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type AppConfig struct {
4242
Author string `json:"author"`
4343
OutputFmt string `json:"format"`
4444
Preset string `json:"preset"`
45+
MaxDepth int `json:"max_depth"`
4546

4647
ShowIcon bool `json:"show_icon"`
4748
ShowScope bool `json:"show_scope"`
@@ -244,6 +245,8 @@ func defineFlags(cfg *AppConfig) {
244245
flag.StringVar(&cfg.Preset, "style", "normal", "")
245246
flag.StringVar(&cfg.Preset, "s", "normal", "")
246247

248+
flag.IntVar(&cfg.MaxDepth, "max-depth", 2, "")
249+
247250
flag.BoolVar(&cfg.ShowIcon, "icon", false, "")
248251
flag.BoolVar(&cfg.ShowIcon, "i", false, "")
249252

@@ -389,6 +392,8 @@ func printUsage() {
389392
fmt.Fprintln(w, "\t")
390393
fmt.Fprintln(w, " -b, --all-branches\tInclude commits from all local branches")
391394
fmt.Fprintln(w, " --branch <string>\tFilter commits by specific branch")
395+
fmt.Fprintln(w, " --max-depth <int>\tMax directory scan depth (default 2)")
396+
fmt.Fprintln(w, "\t")
392397
fmt.Fprintln(w, " -cp, --copy\tCopy output to system clipboard")
393398
fmt.Fprintln(w, " --save\tSave current arguments as default configuration")
394399
fmt.Fprintln(w, "\t")

internal/scanner/scanner.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ import (
77
)
88

99
// ScanGitRepos finds directory paths that contain a .git folder.
10-
// It scans up to 2 levels deep to support structures like github.com/{org}/{repo}.
11-
func ScanGitRepos(rootPath string) ([]string, error) {
10+
// It scans up to maxDepth levels deep to support structures like github.com/{org}/{repo}.
11+
// If maxDepth is 0 or negative, it defaults to 2 levels.
12+
func ScanGitRepos(rootPath string, maxDepth int) ([]string, error) {
1213
var repos []string
1314

15+
// Default to 2 levels if invalid value
16+
if maxDepth <= 0 {
17+
maxDepth = 2
18+
}
19+
1420
// 1. Check root
1521
if isGitRepo(rootPath) {
1622
repos = append(repos, rootPath)
1723
return repos, nil // If root is a git repo, don't scan subdirectories
1824
}
1925

20-
// 2. Scan subdirectories recursively (up to 2 levels deep)
21-
repos, err := scanRecursive(rootPath, 0, 2)
26+
// 2. Scan subdirectories recursively (up to maxDepth levels deep)
27+
repos, err := scanRecursive(rootPath, 0, maxDepth)
2228
if err != nil {
2329
return nil, err
2430
}

0 commit comments

Comments
 (0)