Skip to content

Commit 53053b3

Browse files
committed
opt
1 parent 7b1f5d1 commit 53053b3

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,36 @@
1919
## 示例
2020

2121
```shell
22-
cloc /src -sort code -order desc
22+
cloc /src -sort code -order asc
23+
```
24+
会打印输出为:
25+
```
26+
│----.gitignore
27+
│----LICENSE
28+
│----README.md
29+
│----cloc
30+
│----dir_command.go ---------->[codes: 112]
31+
│----go.mod
32+
│----go.sum
33+
│----main.go ---------->[codes: 58]
34+
│----options.go ---------->[codes: 112]
35+
│----options_test.go ---------->[codes: 37]
36+
│----page_command.go ---------->[codes: 44]
37+
│----page_judge.go ---------->[codes: 65]
38+
│----page_point.go ---------->[codes: 67]
39+
│----testdata
40+
│----│----dir
41+
│----│----│----heihei
42+
│----│----│----│----here
43+
│----│----│----hello.go ---------->[codes: 0]
44+
│----│----│----text
45+
│----│----heihei.go ---------->[codes: 37]
46+
│----│----hello.html ---------->[codes: 0]
47+
│----│----text
48+
│----util.go ---------->[codes: 20]
49+
50+
[codes total]: 552
51+
2352
```
2453

2554
## 参数说明

dir_command.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1821
func 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:

page_judge.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ func (pj *pageJudge) notHaveNotes() bool {
2525

2626
func (pj *pageJudge) beginWithMultilineNotes(line string) bool {
2727
begin := pj.multilineNotesChars[0]
28-
return strings.HasPrefix(line, begin)
28+
return strings.HasPrefix(strings.TrimSpace(line), begin)
2929
}
3030

3131
func (pj *pageJudge) tailWithMultilineNotes(line string) bool {
3232
tail := pj.multilineNotesChars[1]
33-
return strings.HasSuffix(line, tail)
33+
return strings.HasSuffix(strings.TrimSpace(line), tail)
3434
}
3535

3636
func (pj *pageJudge) isSingleLineNotes(line string) bool {
37-
return strings.HasPrefix(line, pj.singleLineNotesChar)
37+
return strings.HasPrefix(strings.TrimSpace(line), pj.singleLineNotesChar)
3838
}
3939

4040
func (pj *pageJudge) isBlank(line string) bool {

0 commit comments

Comments
 (0)