Skip to content

Commit 0233064

Browse files
committed
📝 update README
1 parent 23b091f commit 0233064

File tree

1 file changed

+155
-49
lines changed

1 file changed

+155
-49
lines changed

README.md

Lines changed: 155 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,53 @@ Open the terminal and directly search the path you want to count.
2727
For example, use `cocnt search` to count the number of code lines of `code counter`. (`cocnt` is the abbreviation of `code count`)
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

4646
Please refer to [Usage](#usage) for more usage.
4747

48-
<h2 id="usage">Usage</h2>
48+
* [Usage](#usage)
49+
+ [search](#search)
50+
- [Search the given path directly](#search-the-given-path-directly)
51+
- [Search multiple paths at the same time](#search-multiple-paths-at-the-same-time)
52+
- [Show verbose searching information](#show-verbose-searching-information)
53+
- [Search code files for specific file suffixes](#search-code-files-for-specific-file-suffixes)
54+
- [Ignore directories or files during the search](#ignore-directories-or-files-during-the-search)
55+
+ [Specify the output path to save the search results](#specify-the-output-path-to-save-the-search-results)
56+
+ [Visualize statistical results](#visualize-statistical-results)
57+
+ [remote](#remote)
58+
- [Search and count the remote repository](#search-and-count-the-remote-repository)
59+
+ [config](#config)
60+
- [List configuration information](#list-configuration-information)
61+
- [Reset the value of the configuration variable](#reset-the-value-of-the-configuration-variable)
62+
- [Add the value of the configuration variable](#add-the-value-of-the-configuration-variable)
63+
- [Delete some configuration variable values](#delete-some-configuration-variable-values)
64+
- [Update the access tokens](#update-the-access-tokens)
65+
+ [Restore default configuration](#restore-default-configuration)
66+
67+
## Usage
4968

5069
The help information of `code-counter ` is as follows.
5170

5271
```shell
5372
$ cocnt --help
5473
usage: cocnt <command> [<args>]
5574
These are common Code-Counter commands used in various situations:
56-
search Search code in the given path(s)
75+
search Search and count code lines for the given path(s)
76+
remote Search and count the remote repository
5777
config Configure Code-Counter
5878

5979
A command-line interface (CLI) utility that can help you easily count code and display detailed results.
@@ -66,20 +86,20 @@ optional arguments:
6686
--version show program's version number and exit
6787
```
6888
69-
`code-counter ` supports two subcommands: [`search`](#search) and [`config`](#config)
89+
`code-counter ` supports three subcommands: [`search`](#search), [`remote`](#remote), and [`config`](#config)
7090
71-
<h3 id="search">search</h3>
91+
### search
7292
7393
Search the given path and make statistics. The help information of `cocnt search` is as follows.
7494
7595
```shell
7696
$ cocnt search --help
7797
usage: cocnt search input_path [-h] [-v] [-g] [-o OUTPUT_PATH] [--suffix SUFFIX] [--comment COMMENT] [--ignore IGNORE]
7898
79-
Search code in the given path(s)
99+
Search and count code lines for the given path(s)
80100
81101
positional arguments:
82-
input_path counting the code lines according to the given path(s)
102+
paths counting the code lines according to the given path(s)
83103
84104
optional arguments:
85105
-h, --help show this help message and exit
@@ -99,16 +119,16 @@ $ cocnt search ./code-counter/
99119

100120
RESULT
101121
====================
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%)
122+
Total file lines : 1420 (100.00%)
123+
Total code lines : 1132 ( 79.72%)
124+
Total blank lines : 252 ( 17.75%)
125+
Total comment lines : 36 ( 2.54%)
106126

107127
Type | Files | Ratio | Lines | Ratio
108128
-----------------------------------------------------------------
109-
py | 9 | 100.00% | 689 | 100.00%
129+
py | 19 | 100.00% | 1132 | 100.00%
110130

111-
Totally cost 0.005997896194458008 s.
131+
Totally cost 0.11359143257141113 s.
112132
```
113133

114134
#### Search multiple paths at the same time
@@ -144,34 +164,44 @@ $ cocnt search ./Cpp,./Go,./Rust
144164
Searching information is not displayed by default. If you play more attention to the search information, you can use the `[-v --verbose]` flag to show it when searching.
145165

146166
```shell
147-
$ cocnt search ./code-counter -v
167+
$ cocnt search ./code-counter/ -v
148168

149169
SEARCHING
150170
====================
151171
File Type | Lines | Code | Blank | Comment | File Path
152172
------------------------------------------------------------------------------------------
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
173+
py | 156 | 126 | 28 | 2 | ./code-counter/code_counter\conf\config.py
174+
py | 0 | 0 | 0 | 0 | ./code-counter/code_counter\conf\__init__.py
175+
py | 183 | 154 | 23 | 6 | ./code-counter/code_counter\core\args.py
176+
py | 86 | 68 | 13 | 5 | ./code-counter/code_counter\core\countable\file.py
177+
py | 56 | 45 | 9 | 2 | ./code-counter/code_counter\core\countable\iterator.py
178+
py | 0 | 0 | 0 | 0 | ./code-counter/code_counter\core\countable\__init__.py
179+
py | 133 | 108 | 23 | 2 | ./code-counter/code_counter\core\counter.py
180+
py | 68 | 57 | 8 | 3 | ./code-counter/code_counter\core\visualization.py
181+
py | 0 | 0 | 0 | 0 | ./code-counter/code_counter\core\__init__.py
182+
py | 45 | 35 | 8 | 2 | ./code-counter/code_counter\tools\progress.py
183+
py | 63 | 51 | 10 | 2 | ./code-counter/code_counter\tools\request.py
184+
py | 0 | 0 | 0 | 0 | ./code-counter/code_counter\tools\__init__.py
185+
py | 1 | 1 | 0 | 0 | ./code-counter/code_counter\__init__.py
186+
py | 44 | 30 | 12 | 2 | ./code-counter/code_counter\__main__.py
187+
py | 52 | 44 | 6 | 2 | ./code-counter/setup.py
188+
py | 146 | 123 | 21 | 2 | ./code-counter/tests\test_args.py
189+
py | 327 | 244 | 81 | 2 | ./code-counter/tests\test_config.py
190+
py | 33 | 26 | 5 | 2 | ./code-counter/tests\test_remote.py
191+
py | 27 | 20 | 5 | 2 | ./code-counter/tests\test_search.py
162192

163193
RESULT
164194
====================
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%)
195+
Total file lines : 1420 (100.00%)
196+
Total code lines : 1132 ( 79.72%)
197+
Total blank lines : 252 ( 17.75%)
198+
Total comment lines : 36 ( 2.54%)
169199

170200
Type | Files | Ratio | Lines | Ratio
171201
-----------------------------------------------------------------
172-
py | 9 | 100.00% | 689 | 100.00%
202+
py | 19 | 100.00% | 1132 | 100.00%
173203

174-
Totally cost 0.006999015808105469 s.
204+
Totally cost 0.11509132385253906 s.
175205
```
176206

177207

@@ -182,13 +212,13 @@ $ cocnt search ./code-counter -v
182212
If you only want to count some specific code files when searching, you can use the `--suffix` to specify the code file suffix. For example:
183213

184214
```shell
185-
$ cocnt search ./project --suffix="py,java"
215+
$ cocnt search ./project --suffix="cpp,java"
186216
```
187217

188218
Of course, specify the comment symbols during searching the code, which is helpful to count the number of comments in the code.
189219

190220
```shell
191-
$ cocnt search ./project --suffix="py,java" --comment="#,//,/**"
221+
$ cocnt search ./project --suffix="cpp,java" --comment="//,/*,*" --ignore="target,build"
192222
```
193223

194224
#### Ignore directories or files during the search
@@ -201,9 +231,8 @@ $ cocnt search ./project --suffix="py,java" --comment="#,//,/**" --ignore="targe
201231

202232
Generally speaking, the configuration file of `code-counter` already contains many common default configurations. For example, the default value of `ignore` is shown below.
203233

204-
```json
234+
```
205235
"ignore": [
206-
"out",
207236
"venv",
208237
".git",
209238
".idea",
@@ -215,7 +244,7 @@ Generally speaking, the configuration file of `code-counter` already contains ma
215244
]
216245
```
217246

218-
Therefore, in some cases, if the directory or file to be searched is the same as the default value of `ignore`, you can set `--ignore=""` to empty the default value of `ignore`. Of course, this is temporary. If you want to persist with these changes, you can refer to the `--ignore-reset` flag mentioned later when introducing `cocnt config`.
247+
Therefore, in some cases, if the directory or file to be searched is the same as the default value of `ignore`, you can set `--ignore=""` to empty the default value of `ignore`. Of course, this is temporary. If you want to persist with these changes, you can refer to the [`--ignore-reset` flag](#reset-the-value-of-the-configuration-variable) mentioned later when introducing [`cocnt config`](#config).
219248

220249
### Specify the output path to save the search results
221250

@@ -241,7 +270,71 @@ In addition to the statistical data displayed on the terminal, the statistical c
241270

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

244-
<h3 id="config">config</h3>
273+
### remote
274+
275+
Search and count the remote `Git` repository, the help information of `cocnt remote` is as follows.
276+
277+
```shell
278+
$ cocnt remote --help
279+
usage: cocnt remote <repository> [-h] [-v] [-g] [-o OUTPUT_PATH] [--suffix SUFFIX] [--comment COMMENT] [--ignore IGNORE]
280+
281+
Search and count the remote repository with a given Github or Gitee HTTP link
282+
283+
positional arguments:
284+
repository search and count a remote repository
285+
286+
optional arguments:
287+
-h, --help show this help message and exit
288+
-v, --verbose show verbose information
289+
-g, --graph choose to whether to visualize the result
290+
-o OUTPUT_PATH, --output OUTPUT_PATH
291+
specify an output path if you want to store the result
292+
--suffix SUFFIX what code files do you want to count
293+
--comment COMMENT the comment symbol, which can be judged whether the current line is a comment
294+
--ignore IGNORE ignore some directories or files that you don't want to count
295+
```
296+
297+
`cocnt remote` in addition to supporting the searching of the remote repository, the usage of its various flags is the same as `cocnt search`
298+
299+
#### Search and count the remote repository
300+
301+
Given the `HTTPS` or `SSH` link of the remote repository, `code-counter` can search and count the remote repository.
302+
At present, it supports access to the repository of `Github` and `Gitee`.
303+
304+
Because of the API access limit for `Github` and `Gitee`, they are only used a very small number of times per day.
305+
So we recommend that users follow the instructions and enter the access token corresponding to `Github` or `Gitee` into `code-counter` during the initial search to get at least 5000 uses per day.
306+
307+
When first accessing a `Github` repository, the user is prompted for a `Github` access token, and the same is true for accessing a `Gitee` repository. `code-counter` will display different prompts for different remote repositories.
308+
Of course, you can use the remote search feature without entering an access token, but when the API usage limit is reached, `code-counter` will still prompt the user for an access token, otherwise you will not be able to continue using it that day.
309+
310+
The access tokens for different remote repositories are generated as follows.
311+
+ `Github`: [https://github.com/settings/tokens/new](https://github.com/settings/tokens/new)
312+
+ Just select `public_repo` in `Select scopes`, then click `Generate token` to generate the token and enter it into `code-counter`.
313+
+ `Gitee`: [https://gitee.com/profile/personal_access_tokens/new](https://gitee.com/profile/personal_access_tokens/new)
314+
+ Just select `projects` and click `Submit` to generate the access token and enter it into `code-counter`
315+
316+
Once the correct access token has been entered it will work properly.
317+
318+
```shell
319+
$ cocnt remote https://github.com/InnoFang/code-counter.git
320+
321+
RESULT
322+
====================
323+
Total file lines : 1403 (100.00%)
324+
Total code lines : 997 ( 71.06%)
325+
Total blank lines : 264 ( 18.82%)
326+
Total comment lines : 142 ( 10.12%)
327+
328+
Type | Files | Ratio | Lines | Ratio
329+
-----------------------------------------------------------------
330+
py | 18 | 100.00% | 997 | 100.00%
331+
332+
Totally cost 37.77419900894165 s.
333+
```
334+
335+
If you want to update the access token at any time, then you can refer to the [`--github-token` and `--gitee-token` flags](#update-the-access-tokens) that will be mentioned later in the introduction of [`cocnt config`](#config).
336+
337+
### config
245338
246339
Configure `code-counter`, and the help information of `cocnt config` is as follows.
247340
@@ -325,7 +418,6 @@ $ cocnt config --list
325418
"\"\"\"\""
326419
],
327420
"ignore": [
328-
"out",
329421
"venv",
330422
".git",
331423
".idea",
@@ -350,15 +442,15 @@ The default configuration of `code-counter` basically includes common code file
350442
+ `--comment-reset` can reset the default comment symbols
351443
+ `--ignore-reset` can reset the default directory or files to ignore
352444

353-
These 3 flags can be used in combination or separately. You will be asked for each operation that will modify the configuration file, you can check whether the content to be modified is correct. If you are sure to modify, you can enter `y`, otherwise enter `n` to not modify.
445+
These 3 flags can be used in combination or separately. You will be asked for each operation that will modify the configuration file, you can check if what you want to change is correct. If you confirm the change you can enter `y`, otherwise enter `n` to not perform the change.
354446

355447
Multiple values can be separated by commas, as shown in the following example.
356448

357449
```shell
358-
$ cocnt config --suffix-reset="python,java" --comment-reset="#,/**,//" --ignore-reset="__pycache_,.pytest_cache,target"
359-
'suffix' will be replaced with ['python', 'java'] . (y/n) y
360-
'comment' will be replaced with ['#', '/**', '//'] . (y/n) y
361-
'ignore' will be replaced with ['__pycache_', '.pytest_cache', 'target'] . (y/n) y
450+
$ cocnt config --suffix-reset="cpp,java" --comment-reset="//,/*,*" --ignore-reset="build,target"
451+
'suffix' will be replaced with ['cpp', 'java'] . (y/n) y
452+
'comment' will be replaced with ['//', '/*', '*'] . (y/n) y
453+
'ignore' will be replaced with ['build', 'target'] . (y/n) y
362454
```
363455

364456
#### Add the value of the configuration variable
@@ -368,7 +460,7 @@ For the case of adding the value of the configuration variable, the following fl
368460
+ `--comment-add` add comment symbols
369461
+ `--ignore-add` add the directories or files to ignore
370462

371-
These 3 flags can be used in combination or separately. You will be asked for each operation that will modify the configuration file, you can check whether the content to be modified is correct. If you are sure to modify, you can enter `y`, otherwise enter `n` to not modify.
463+
These 3 flags can be used in combination or separately. You will be asked for each operation that will modify the configuration file, you can check if what you want to change is correct. If you confirm the change you can enter `y`, otherwise enter `n` to not perform the change.
372464

373465
Multiple values can be separated by commas, as shown in the following example.
374466

@@ -386,7 +478,7 @@ For the deletion of configuration variable values, `code-counter` provides the f
386478
+ `--comment-del` delete unwanted comment symbols from the default configuration
387479
+ `--ignore-del` delete the directory or file names that don't need to be ignored from the default configuration
388480
389-
These 3 flags can be used in combination or separately. You will be asked for each operation that will modify the configuration file, you can check whether the content to be modified is correct. If you are sure to modify, you can enter `y`, otherwise enter `n` to not modify.
481+
These 3 flags can be used in combination or separately. You will be asked for each operation that will modify the configuration file, you can check if what you want to change is correct. If you confirm the change you can enter `y`, otherwise enter `n` to not perform the change.
390482
391483
Multiple values can be separated by commas, as shown in the following example.
392484
@@ -397,6 +489,20 @@ $ cocnt config --suffix-del="clj,lisp" --comment-del=";" --ignore-del="build,tar
397489
'ignore' will remove ['build', 'target'] . (y/n) y
398490
```
399491
492+
#### Update the access tokens
493+
494+
For updates to access tokens for `Github` and `Gitee`, `code-counter` provides the following flags.
495+
+ `--github-token` update the access token for `Github`
496+
+ `--gitee-token` update the access token for `Gitee`
497+
498+
These 2 flags can be used in combination or separately. You will be asked for each operation that will modify the configuration file, you can check if what you want to change is correct. If you confirm the change you can enter `y`, otherwise enter `n` to not perform the change.
499+
500+
```shell
501+
$ cocnt config --github-token=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 --gitee-token=d7ca1490523aac54a38434bf96c76ff8
502+
the old Github access token will be updated to `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` . (y/n) y
503+
the old Gitee access token will be updated to `d7ca1490523aac54a38434bf96c76ff8` . (y/n) y
504+
```
505+
400506
### Restore default configuration
401507
402508
Use the `--restore` flag to restore the default configuration of `code-counter`.

0 commit comments

Comments
 (0)