Skip to content

Commit 1417082

Browse files
committed
📝 update README_CN
1 parent 0233064 commit 1417082

File tree

1 file changed

+159
-53
lines changed

1 file changed

+159
-53
lines changed

README_CN.md

Lines changed: 159 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,57 @@ python setup.py install
2727
比如使用 `cocnt search` 来统计 `code-counter` 的代码行数。(`cocnt``codecounter` 的缩写)
2828

2929
```shell
30-
$ cocnt search ./code-counter
30+
$ cocnt search ./code-counter/
3131

3232
RESULT
3333
====================
34-
Total file lines : 884 (100.00%)
35-
Total code lines : 698 ( 78.96%)
36-
Total blank lines : 157 ( 17.76%)
37-
Total comment lines : 29 ( 3.28%)
34+
Total file lines : 1420 (100.00%)
35+
Total code lines : 1132 ( 79.72%)
36+
Total blank lines : 252 ( 17.75%)
37+
Total comment lines : 36 ( 2.54%)
3838

3939
Type | Files | Ratio | Lines | Ratio
4040
-----------------------------------------------------------------
41-
py | 9 | 100.00% | 698 | 100.00%
41+
py | 19 | 100.00% | 1132 | 100.00%
4242

43-
Totally cost 0.02192854881286621 s.
43+
Totally cost 0.11359143257141113 s.
4444
```
4545

46-
更多使用方法请参考[用法](#usage)
47-
48-
<h2 id="usage">用法</h2>
46+
更多使用方法请参考[用法](#用法)
47+
48+
- [Code Counter](#code-counter)
49+
- [安装](#安装)
50+
- [快速开始](#快速开始)
51+
- [用法](#用法)
52+
- [search](#search)
53+
- [直接搜索给定的路径](#直接搜索给定的路径)
54+
- [同时搜索多个路径](#同时搜索多个路径)
55+
- [展示详细搜索信息](#展示详细搜索信息)
56+
- [搜索特定文件后缀的代码文件](#搜索特定文件后缀的代码文件)
57+
- [搜索时过忽略指定的目录或文件](#搜索时过忽略指定的目录或文件)
58+
- [指定搜索结果的保存路径](#指定搜索结果的保存路径)
59+
- [可视化统计结果](#可视化统计结果)
60+
- [remote](#remote)
61+
- [搜索并统计远端仓库的代码](#搜索并统计远端仓库的代码)
62+
- [config](#config)
63+
- [显示配置信息](#显示配置信息)
64+
- [重置配置信息](#重置配置信息)
65+
- [追加配置信息](#追加配置信息)
66+
- [删除配置信息](#删除配置信息)
67+
- [更新访问令牌](#更新访问令牌)
68+
- [恢复默认配置](#恢复默认配置)
69+
- [License](#license)
70+
71+
## 用法
4972

5073
`code-counter` 的帮助信息如下。
5174

5275
```shell
5376
$ cocnt --help
5477
usage: cocnt <command> [<args>]
5578
These are common Code-Counter commands used in various situations:
56-
search Search code in the given path(s)
79+
search Search and count code lines for the given path(s)
80+
remote Search and count the remote repository
5781
config Configure Code-Counter
5882

5983
A command-line interface (CLI) utility that can help you easily count code and display detailed results.
@@ -66,20 +90,20 @@ optional arguments:
6690
--version show program's version number and exit
6791
```
6892
69-
`code-counter` 支持两个子命令:[`search`](#search) 和 [`config`](#config)
93+
`code-counter` 支持 3 个子命令:[`search`](#search), [`remote`](#remote) 和 [`config`](#config)
7094
71-
<h3 id="search">search</h3>
95+
### search
7296
7397
搜索给定的路径并统计,`cocnt search` 的帮助信息如下。
7498
7599
```shell
76100
$ cocnt search --help
77101
usage: cocnt search input_path [-h] [-v] [-g] [-o OUTPUT_PATH] [--suffix SUFFIX] [--comment COMMENT] [--ignore IGNORE]
78102
79-
Search code in the given path(s)
103+
Search and count code lines for the given path(s)
80104
81105
positional arguments:
82-
input_path counting the code lines according to the given path(s)
106+
paths counting the code lines according to the given path(s)
83107
84108
optional arguments:
85109
-h, --help show this help message and exit
@@ -99,16 +123,16 @@ $ cocnt search ./code-counter/
99123

100124
RESULT
101125
====================
102-
Total file lines : 860 (100.00%)
103-
Total code lines : 689 ( 80.12%)
104-
Total blank lines : 142 ( 16.51%)
105-
Total comment lines : 29 ( 3.37%)
126+
Total file lines : 1420 (100.00%)
127+
Total code lines : 1132 ( 79.72%)
128+
Total blank lines : 252 ( 17.75%)
129+
Total comment lines : 36 ( 2.54%)
106130

107131
Type | Files | Ratio | Lines | Ratio
108132
-----------------------------------------------------------------
109-
py | 9 | 100.00% | 689 | 100.00%
133+
py | 19 | 100.00% | 1132 | 100.00%
110134

111-
Totally cost 0.005997896194458008 s.
135+
Totally cost 0.11359143257141113 s.
112136
```
113137

114138
#### 同时搜索多个路径
@@ -144,34 +168,45 @@ $ cocnt search ./Cpp,./Go,./Rust
144168
搜索信息默认是不显示的。如果你比较关注搜索信息,可以在搜索时使用 `[-v --verbose]` 标志。
145169

146170
```shell
147-
$ cocnt search ./code-counter -v
171+
$ cocnt search ./code-counter/ -v
148172

149173
SEARCHING
150174
====================
151175
File Type | Lines | Code | Blank | Comment | File Path
152176
------------------------------------------------------------------------------------------
153-
py | 80 | 62 | 16 | 2 | ./code-counter\code_counter\conf\config.py
154-
py | 0 | 0 | 0 | 0 | ./code-counter\code_counter\conf\__init__.py
155-
py | 88 | 75 | 11 | 2 | ./code-counter\code_counter\core\argspaser.py
156-
py | 257 | 198 | 38 | 21 | ./code-counter\code_counter\core\codecounter.py
157-
py | 0 | 0 | 0 | 0 | ./code-counter\code_counter\core\__init__.py
158-
py | 1 | 1 | 0 | 0 | ./code-counter\code_counter\__init__.py
159-
py | 35 | 22 | 11 | 2 | ./code-counter\code_counter\__main__.py
160-
py | 48 | 44 | 4 | 0 | ./code-counter\setup.py
161-
py | 351 | 287 | 62 | 2 | ./code-counter\test\test.py
177+
py | 156 | 126 | 28 | 2 | ./code-counter/code_counter\conf\config.py
178+
py | 0 | 0 | 0 | 0 | ./code-counter/code_counter\conf\__init__.py
179+
py | 183 | 154 | 23 | 6 | ./code-counter/code_counter\core\args.py
180+
py | 86 | 68 | 13 | 5 | ./code-counter/code_counter\core\countable\file.py
181+
py | 56 | 45 | 9 | 2 | ./code-counter/code_counter\core\countable\iterator.py
182+
py | 0 | 0 | 0 | 0 | ./code-counter/code_counter\core\countable\__init__.py
183+
py | 133 | 108 | 23 | 2 | ./code-counter/code_counter\core\counter.py
184+
py | 68 | 57 | 8 | 3 | ./code-counter/code_counter\core\visualization.py
185+
py | 0 | 0 | 0 | 0 | ./code-counter/code_counter\core\__init__.py
186+
py | 45 | 35 | 8 | 2 | ./code-counter/code_counter\tools\progress.py
187+
py | 63 | 51 | 10 | 2 | ./code-counter/code_counter\tools\request.py
188+
py | 0 | 0 | 0 | 0 | ./code-counter/code_counter\tools\__init__.py
189+
py | 1 | 1 | 0 | 0 | ./code-counter/code_counter\__init__.py
190+
py | 44 | 30 | 12 | 2 | ./code-counter/code_counter\__main__.py
191+
py | 52 | 44 | 6 | 2 | ./code-counter/setup.py
192+
py | 146 | 123 | 21 | 2 | ./code-counter/tests\test_args.py
193+
py | 327 | 244 | 81 | 2 | ./code-counter/tests\test_config.py
194+
py | 33 | 26 | 5 | 2 | ./code-counter/tests\test_remote.py
195+
py | 27 | 20 | 5 | 2 | ./code-counter/tests\test_search.py
162196

163197
RESULT
164198
====================
165-
Total file lines : 860 (100.00%)
166-
Total code lines : 689 ( 80.12%)
167-
Total blank lines : 142 ( 16.51%)
168-
Total comment lines : 29 ( 3.37%)
199+
Total file lines : 1420 (100.00%)
200+
Total code lines : 1132 ( 79.72%)
201+
Total blank lines : 252 ( 17.75%)
202+
Total comment lines : 36 ( 2.54%)
169203

170204
Type | Files | Ratio | Lines | Ratio
171205
-----------------------------------------------------------------
172-
py | 9 | 100.00% | 689 | 100.00%
206+
py | 19 | 100.00% | 1132 | 100.00%
207+
208+
Totally cost 0.11509132385253906 s.
173209

174-
Totally cost 0.006999015808105469 s.
175210
```
176211

177212
#### 搜索特定文件后缀的代码文件
@@ -181,28 +216,24 @@ $ cocnt search ./code-counter -v
181216
如果在搜索的时候,只想统计某一些特定的代码文件的情况,那么可以使用 `--suffix` 来指定代码文件后缀。比如:
182217

183218
```shell
184-
$ cocnt search ./project --suffix="py,java"
219+
$ cocnt search ./project --suffix="cpp,java"
185220
```
186221

187222
当然,在搜索时也可以指定编程语言的注释符号,这有利于更好的统计代码中注释的数量。
188223

189224
```shell
190-
$ cocnt search ./project --suffix="py,java" --comment="#,//,/**"
225+
$ cocnt search ./project --suffix="cpp,java" --comment="//,/*,*"
191226
```
192227

193228
#### 搜索时过忽略指定的目录或文件
194229

195230
在搜索代码文件的时候,容易统计到不想统计的代码文件或者目录,因此可以使用 `--ignore` 来指定在搜索时需要过滤的目录或者文件名。
196-
197-
```shell
198-
$ cocnt search ./project --suffix="py,java" --comment="#,//,/**" --ignore="target,__pycache__"
199-
```
231+
c
200232

201233
一般来说,`code-counter` 的配置文件里已经包含了很多常见的默认配置,比如 `ignore` 的默认值如下所示。
202234

203-
```json
235+
```
204236
"ignore": [
205-
"out",
206237
"venv",
207238
".git",
208239
".idea",
@@ -214,7 +245,7 @@ $ cocnt search ./project --suffix="py,java" --comment="#,//,/**" --ignore="targe
214245
]
215246
```
216247

217-
因此,如果在某些情况下,要搜索的目录或文件与 `ignore` 的默认值相同,那么可以通过设置 `--ignore=""` 来置空 `ignore` 的默认值,当然这是临时的。如果想要持久化这些修改,可以参考后面介绍`cocnt config` 时会提及的 `--ignore-reset` 标志。
248+
因此,如果在某些情况下,要搜索的目录或文件与 `ignore` 的默认值相同,那么可以通过设置 `--ignore=""` 来置空 `ignore` 的默认值,当然这是临时的。如果想要持久化这些修改,可以参考后面介绍 [`cocnt config`](#config) 时会提及的 [`--ignore-reset` 标志](#重置配置信息)
218249

219250
#### 指定搜索结果的保存路径
220251

@@ -240,7 +271,69 @@ $ cocnt search ./miscode -g
240271

241272
![](https://cdn.jsdelivr.net/gh/innofang/jotter/source/code-counter/result.png)
242273

243-
<h3 id="config">config</h3>
274+
### remote
275+
276+
搜索并统计远端 `Git` 仓库,`cocnt remote` 的帮助信息如下。
277+
278+
```shell
279+
$ cocnt remote --help
280+
usage: cocnt remote <repository> [-h] [-v] [-g] [-o OUTPUT_PATH] [--suffix SUFFIX] [--comment COMMENT] [--ignore IGNORE]
281+
282+
Search and count the remote repository with a given Github or Gitee HTTP link
283+
284+
positional arguments:
285+
repository search and count a remote repository
286+
287+
optional arguments:
288+
-h, --help show this help message and exit
289+
-v, --verbose show verbose information
290+
-g, --graph choose to whether to visualize the result
291+
-o OUTPUT_PATH, --output OUTPUT_PATH
292+
specify an output path if you want to store the result
293+
--suffix SUFFIX what code files do you want to count
294+
--comment COMMENT the comment symbol, which can be judged whether the current line is a comment
295+
--ignore IGNORE ignore some directories or files that you don't want to count
296+
```
297+
298+
`cocnt remote` 除了支持搜索远端仓库外,其各个标志的用法与 `cocnt search` 相同。
299+
300+
#### 搜索并统计远端仓库的代码
301+
302+
给定远端仓库的 HTTPS 或 SSH 链接,`code-counter` 就可以对远端仓库进行搜索,目前支持对 `Github` 和 `Gitee` 的仓库进行访问。
303+
304+
由于 `Github` 和 `Gitee` 的 API 访问次数限制,因此每天只有很少的使用次数。所以我们建议用户按照提示,在初次搜索时将 `Github` 或 `Gitee` 对应的访问令牌输入到 `code-counter` 中,这样每天至少有 5000 次的使用次数。
305+
306+
初次访问 `Github` 仓库时,会提示用户输入 `Github` 的访问令牌,访问 `Gitee` 的仓库也是一样的。 `code-counter` 会为不同的远端仓库展示不同的提示信息。
307+
当然你不输入访问令牌也可以使用远端搜索的功能,但是当 API 使用次数达到上限时,`code-counter` 仍然会提示用户输入访问令牌,否则当天无法继续使用。
308+
309+
不同远端仓库的访问令牌的生成方式:
310+
+ `Github`: [https://github.com/settings/tokens/new](https://github.com/settings/tokens/new)
311+
+ 只需要在 `Select scopes` 中选择 `public_repo`、,然后点击 `Generate token` 生成令牌并把令牌输入到 `code-counter` 中即可
312+
+ `Gitee`: [https://gitee.com/profile/personal_access_tokens/new](https://gitee.com/profile/personal_access_tokens/new)
313+
+ 只需要选择 `projects` 并点击 `提交` 就可以生成访问令牌,然后把令牌输入到 `code-counter` 中即可
314+
315+
当输入了正确的访问令牌后就可以正常使用了。
316+
317+
```shell
318+
$ cocnt remote https://github.com/InnoFang/code-counter.git
319+
320+
RESULT
321+
====================
322+
Total file lines : 1403 (100.00%)
323+
Total code lines : 997 ( 71.06%)
324+
Total blank lines : 264 ( 18.82%)
325+
Total comment lines : 142 ( 10.12%)
326+
327+
Type | Files | Ratio | Lines | Ratio
328+
-----------------------------------------------------------------
329+
py | 18 | 100.00% | 997 | 100.00%
330+
331+
Totally cost 37.77419900894165 s.
332+
```
333+
334+
如果想随时更新访问令牌,那么可以参考后面介绍 [`cocnt config`](#config) 时会提及的 [`--github-token` 和 `--gitee-token` 标志](#更新访问令牌)。
335+
336+
### config
244337
245338
对 `code-counter` 进行设置,`cocnt config` 的帮助信息如下。
246339
@@ -324,7 +417,6 @@ $ cocnt config --list
324417
"\"\"\"\""
325418
],
326419
"ignore": [
327-
"out",
328420
"venv",
329421
".git",
330422
".idea",
@@ -354,10 +446,10 @@ $ cocnt config --list
354446
对于要输入的多个值可以用逗号分隔,示例如下。
355447
356448
```shell
357-
$ cocnt config --suffix-reset="python,java" --comment-reset="#,/**,//" --ignore-reset="__pycache_,.pytest_cache,target"
358-
'suffix' will be replaced with ['python', 'java'] . (y/n) y
359-
'comment' will be replaced with ['#', '/**', '//'] . (y/n) y
360-
'ignore' will be replaced with ['__pycache_', '.pytest_cache', 'target'] . (y/n) y
449+
$ cocnt config --suffix-reset="cpp,java" --comment-reset="//,/*,*" --ignore-reset="build,target"
450+
'suffix' will be replaced with ['cpp', 'java'] . (y/n) y
451+
'comment' will be replaced with ['//', '/*', '*'] . (y/n) y
452+
'ignore' will be replaced with ['build', 'target'] . (y/n) y
361453
```
362454
363455
#### 追加配置信息
@@ -396,9 +488,23 @@ $ cocnt config --suffix-del="clj,lisp" --comment-del=";" --ignore-del="build,tar
396488
'ignore' will remove ['build', 'target'] . (y/n) y
397489
```
398490
491+
#### 更新访问令牌
492+
493+
对于 `Github` 和 `Gitee` 的访问令牌的更新,`code-counter` 提供以下标志:
494+
+ `--github-token` 更新 `Github` 的访问令牌
495+
+ `--gitee-token` 更新 `Gitee` 的访问令牌
496+
497+
这两个标志可以组合使用,也可以单独使用。对于每个会修改配置文件的操作都会对你进行询问,此时你可以检查要修改的内容是否正确,如果确认修改可以输入 `y`,否则输入 `n` 不执行修改。
498+
499+
```shell
500+
$ cocnt config --github-token=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 --gitee-token=d7ca1490523aac54a38434bf96c76ff8
501+
the old Github access token will be updated to `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` . (y/n) y
502+
the old Gitee access token will be updated to `d7ca1490523aac54a38434bf96c76ff8` . (y/n) y
503+
```
504+
399505
#### 恢复默认配置
400506
401-
使用 `--restore` 来恢复 `code-counter` 自带的默认配置。
507+
使用 `--restore` 来恢复 `code-counter` 自带的默认配置。恢复默认配置不会重置访问令牌。
402508
403509
```shell
404510
$ cocnt config --restore

0 commit comments

Comments
 (0)