@@ -12,7 +12,10 @@ type dirCmd struct {
1212 orderOpt Optioner
1313 sortOpt Optioner
1414
15- files int
15+ files int64
16+ codesTotal int64
17+ blanksTotal int64
18+ commentsTotal int64
1619}
1720
1821func newDirCmd (path string ) cmder {
@@ -30,9 +33,19 @@ func (cmd *dirCmd) run(opts map[string]string) (int, error) {
3033 return ExitCodeFailed , fmt .Errorf ("the count of directory does not support options: [%s]" , serializeMap (opts ))
3134 }
3235 cmd .readFileNames (cmd .path , "" )
33- if cmd .sortOpt .value () == sortValueFiles {
34- fmt .Println ()
36+ fmt .Println ()
37+ switch cmd .sortOpt .value () {
38+ case sortValueFiles :
3539 fmt .Printf ("the all files number: %d\n " , cmd .files )
40+ case sortValueBlank :
41+ fmt .Printf ("[blanks total]: %d\n " , cmd .blanksTotal )
42+ case sortValueCode :
43+ fmt .Printf ("[codes total]: %d\n " , cmd .codesTotal )
44+ case sortValueComment :
45+ fmt .Printf ("[comments total]: %d\n " , cmd .commentsTotal )
46+ default :
47+ fmt .Printf ("[total]: codes: %d, comments: %d, blanks: %d\n \n " , cmd .codesTotal ,
48+ cmd .commentsTotal , cmd .blanksTotal )
3649 }
3750 return ExitCodeSuccess , nil
3851}
@@ -74,6 +87,13 @@ func (cmd *dirCmd) readFileNames(path, prefix string) {
7487 fmt .Println (prefix + e .Name () + " [ERROR: read failed]" )
7588 continue
7689 }
90+
91+ // total directory page messages
92+ cmd .codesTotal += int64 (pp .codes )
93+ cmd .commentsTotal += int64 (pp .comments )
94+ cmd .blanksTotal += int64 (pp .blanks )
95+
96+ // print the result
7797 var tail string
7898 switch sortValue {
7999 case sortValueCode :
0 commit comments