Skip to content

Commit 4e67f13

Browse files
committed
Added support to exclude multiple folders with --excl-dir flag
1 parent 296c085 commit 4e67f13

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

utils/handle_files.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ func GetFiles(
8686
guardDir <- struct{}{}
8787
wgDir.Add(1)
8888

89-
err := walkDirConcur(folder_location, folder_count, &files, is_git_initialized, wgDir, muDir, guardDir, skipDir)
89+
skipFilePathList := _getPathList(skipDir)
90+
91+
err := walkDirConcur(folder_location, folder_count, &files, is_git_initialized, wgDir, muDir, guardDir, skipFilePathList)
9092
wgDir.Wait()
9193

9294
return files, err
9395
}
9496

95-
func walkDirConcur(folder_location string, folder_count *int32, files *[]File_info, is_git_initialized *bool, wgDir *sync.WaitGroup, muDir *sync.RWMutex, guardDir chan struct{}, skipDir string) error {
97+
func walkDirConcur(folder_location string, folder_count *int32, files *[]File_info, is_git_initialized *bool, wgDir *sync.WaitGroup, muDir *sync.RWMutex, guardDir chan struct{}, skipDir []string) error {
9698
defer wgDir.Done()
9799

98100
visitFolder := func(
@@ -114,17 +116,19 @@ func walkDirConcur(folder_location string, folder_count *int32, files *[]File_in
114116
}
115117
muDir.Unlock()
116118
}
117-
if skipDir != "" && _path == skipDir {
119+
if len(skipDir) != 0 && _isPresent(skipDir, _path) {
118120
return filepath.SkipDir
119121
}
120122
// if it is a folder, then increase the folder count
121-
if f.IsDir() && _path != folder_location && _path != path.Join(folder_location, skipDir) {
123+
// if f.IsDir() && _path != folder_location && _path != path.Join(folder_location, skipDir) {
124+
125+
if f.IsDir() && _path != folder_location && !_isPresent(skipDir, _path) {
122126
muDir.Lock()
123127
*folder_count++
124128
muDir.Unlock()
125129
guardDir <- struct{}{}
126130
wgDir.Add(1)
127-
go walkDirConcur(_path, folder_count, files, is_git_initialized, wgDir, muDir, guardDir, "")
131+
go walkDirConcur(_path, folder_count, files, is_git_initialized, wgDir, muDir, guardDir, skipDir)
128132
return filepath.SkipDir
129133
}
130134
if f.Type().IsRegular() {
@@ -150,3 +154,20 @@ func walkDirConcur(folder_location string, folder_count *int32, files *[]File_in
150154
<-guardDir
151155
return err
152156
}
157+
158+
func _getPathList(filePath string) []string {
159+
var filePathList []string
160+
for _, elem := range strings.Split(filePath, ",") {
161+
filePathList = append(filePathList, strings.TrimSpace(elem))
162+
}
163+
return filePathList
164+
}
165+
166+
func _isPresent(filePathList []string, filePath string) bool {
167+
for _, elem := range filePathList {
168+
if elem == filePath {
169+
return true
170+
}
171+
}
172+
return false
173+
}

utils/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ This emits help text when --help tag is called
5050
*/
5151
func EmitHelpText() string {
5252

53-
versionDetails := `0.1.10`
53+
versionDetails := `0.1.11`
5454
authorDetails := `mainak55512 (mbhattacharjee432@gmail.com)`
5555
flagDetails := "--help\n--ext [list extension name]\n--excl-ext [list of extension name]\n--excl-dir folder-name\n--json\n--yaml\n--sort"
5656
helpFlagDetails := "--help\tShows the usage details\n\n\tstto --help or,\n\tstto -help\n\n"
5757
extFlagDetails := "--ext\tFilters output based on the given extension\n\n\tstto --ext [extension name] [(optional) folder name] or,\n\tstto -ext [extension name] [(optional) folder name]\n\n"
5858
exclextFlagDetails := "--excl-ext\tFilters out files from output based on the given extension\n\n\tstto --excl-ext [extension name] [(optional) folder name] or,\n\tstto -excl-ext [extension name] [(optional) folder name]\n\n"
59-
exclDirFlagDetails := "--excl-dir\tFilters out folder from output\n\n\tstto --excl-dir [folder name] or,\n\tstto -excl-dir [folder name]\n\n"
59+
exclDirFlagDetails := "--excl-dir\tFilters out folder from output\n\n\tstto --excl-dir [comma separated folder names] or,\n\tstto -excl-dir [comma separated folder names]\n\n"
6060
jsonFlagDetails := "--json\tEmits output in JSON format\n\n\tstto --json\n\n"
6161
yamlFlagDetails := "--yaml\tEmits output in YAML format\n\n\tstto --yaml\n\n"
6262
sortFlagDetails := "--sort\tSorts output based on descending line count\n\n\tstto --sort\n\n"

0 commit comments

Comments
 (0)