@@ -15,20 +15,17 @@ import (
15
15
16
16
// Shared Utilities
17
17
18
- func ListSubfolders (dir string ) ([]string , error ) {
19
- folderNames := []string {}
20
-
18
+ func ListSubfolders (dir string ) (folderNames []string , err error ) {
21
19
files , err := os .ReadDir (dir )
22
20
if err != nil {
23
- return folderNames , err
21
+ return
24
22
}
25
-
26
23
for _ , file := range files {
27
24
if file .IsDir () && ! (strings .HasPrefix (file .Name (), "." )) {
28
25
folderNames = append (folderNames , file .Name ())
29
26
}
30
27
}
31
- return folderNames , nil
28
+ return
32
29
}
33
30
34
31
// Sort Helpers
@@ -66,7 +63,7 @@ func summarize(file ExtDirEntry) string {
66
63
func calculateStats (dir string ) (stats []ExtDirEntry , err error ) {
67
64
files , err := os .ReadDir (dir )
68
65
if err != nil {
69
- return stats , err
66
+ return
70
67
}
71
68
72
69
for _ , file := range files {
@@ -79,13 +76,13 @@ func calculateStats(dir string) (stats []ExtDirEntry, err error) {
79
76
stats = append (stats , stat )
80
77
}
81
78
}
82
- return stats , nil
79
+ return
83
80
}
84
81
85
82
func getStats (syncDir string ) (stats []ExtDirEntry , err error ) {
86
83
folderNames , err := ListSubfolders (syncDir )
87
84
if err != nil {
88
- return stats , err
85
+ return
89
86
}
90
87
for _ , name := range folderNames {
91
88
subStats , err := calculateStats (filepath .Join (syncDir , name ))
@@ -94,7 +91,7 @@ func getStats(syncDir string) (stats []ExtDirEntry, err error) {
94
91
}
95
92
stats = append (stats , subStats ... )
96
93
}
97
- return stats , nil
94
+ return
98
95
}
99
96
100
97
func AttachList (cli * clir.Cli ) {
@@ -112,13 +109,13 @@ func AttachList(cli *clir.Cli) {
112
109
outputFormat := "text"
113
110
listCmd .StringFlag ("output" , "Output format" , & outputFormat )
114
111
115
- listCmd .Action (func () error {
112
+ listCmd .Action (func () ( err error ) {
116
113
sortMethod := map [string ]SortMethod {"name" : sortFileName , "mod" : sortFileModTime }[sortMethodStr ]
117
114
output := map [string ]OutputFormat {"text" : summarize }[outputFormat ]
118
115
119
116
stats , err := getStats (syncDir )
120
117
if err != nil {
121
- return err
118
+ return
122
119
}
123
120
sortMethod (stats )
124
121
if sortAsc {
@@ -127,6 +124,6 @@ func AttachList(cli *clir.Cli) {
127
124
for _ , s := range stats {
128
125
fmt .Println (output (s ))
129
126
}
130
- return nil
127
+ return
131
128
})
132
129
}
0 commit comments