diff --git a/README.md b/README.md
index 4dfb0e8..cf623a6 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
# Code Counter
-A command-line interface (CLI) utility that can help you easily count code and display detailed results.
+A command-line interface (CLI) utility that can help you easily count code lines and display detailed results.
-English | [中文](https://github.com/InnoFang/code-counter/blob/master/README_CN.md)
+English | [中文](./README_CN.md)
## Installation
@@ -12,7 +12,7 @@ Install by PyPI:
pip install code-counter
```
-Also you can install it from the source code:
+Also, you can install it from the source code:
```shell
git clone https://github.com/innofang/code-counter.git
@@ -22,195 +22,265 @@ python setup.py install
## Quick Start
-Switch to any code directory (e.g. `code-counter`), and enter the following command:
+Open the terminal and directly search the path you want to count.
+
+For example, use `cocnt search` to count the number of code lines of `code counter`. (`cocnt` is the abbreviation of `code count`)
```shell
-$ codecount .
+$ cocnt search ./code-counter
RESULT
====================
- Total file lines : 344 (100.00%)
- Total code lines : 269 ( 78.20%)
- Total blank lines : 55 ( 15.99%)
- Total comment lines : 20 ( 5.81%)
+ Total file lines : 884 (100.00%)
+ Total code lines : 698 ( 78.96%)
+ Total blank lines : 157 ( 17.76%)
+ Total comment lines : 29 ( 3.28%)
Type | Files | Ratio | Lines | Ratio
-----------------------------------------------------------------
- py | 7 | 100.00% | 269 | 100.00%
-
- Totally cost 0.010030031204223633s.
+ py | 9 | 100.00% | 698 | 100.00%
+ Totally cost 0.02192854881286621 s.
```
-Refer to [Usage](#usage) and [Example](#example) below for more usage.
+Please refer to [Usage](#usage) for more usage.
Usage
+The help information of `code-counter ` is as follows.
+
```shell
-$ codecount -h
-usage: code-counter [-h] [-V] [-l] [-v] [-g] [-o OUTPUT] [--suffix SUFFIX] [--suffix-save SUFFIX_SAVE] [--suffix-add SUFFIX_ADD] [--comment COMMENT]
- [--comment-save COMMENT_SAVE] [--comment-add COMMENT_ADD] [--ignore IGNORE] [--ignore-save IGNORE_SAVE] [--ignore-add IGNORE_ADD]
- [--restore]
- [path, CONFIG]
+$ cocnt --help
+usage: cocnt []
+These are common Code-Counter commands used in various situations:
+ search Search code in the given path(s)
+ config Configure Code-Counter
A command-line interface (CLI) utility that can help you easily count code and display detailed results.
positional arguments:
- [path, CONFIG] specify a file or directory path you want to count or use CONFIG placeholder to configure
+ command Subcommand to run, `search` or `config`
+
+optional arguments:
+ -h, --help show this help message and exit
+ --version show program's version number and exit
+```
+
+`code-counter ` supports two subcommands: [`search`](#search) and [`config`](#config)
+
+search
+
+Search the given path and make statistics. The help information of `cocnt search` is as follows.
+
+```shell
+$ cocnt search --help
+usage: cocnt search input_path [-h] [-v] [-g] [-o OUTPUT_PATH] [--suffix SUFFIX] [--comment COMMENT] [--ignore IGNORE]
+
+Search code in the given path(s)
+
+positional arguments:
+ input_path counting the code lines according to the given path(s)
optional arguments:
-h, --help show this help message and exit
- -V, --version show program's version number and exit
- -l, --list the file contains a list of file path, which can make you search more than one file or directory
- -v, --verbose show verbose infomation
+ -v, --verbose show verbose information
-g, --graph choose to whether to visualize the result
- -o OUTPUT, --output OUTPUT
- specify a output path if you want to store the result
- --suffix SUFFIX what code files do you want to count, this parameter is disposable
- --suffix-save SUFFIX_SAVE
- override 'suffix' in config and count codes according to this value
- --suffix-add SUFFIX_ADD
- append new value for 'suffix' in config and count codes according to this value
- --comment COMMENT the comment symbol, which can be judged whether the current line is a comment, this parameter is disposable
- --comment-save COMMENT_SAVE
- override 'comment' in config and count comment lines according to this value
- --comment-add COMMENT_ADD
- append new value for 'comment' in config and count comment lines according to this value
- --ignore IGNORE ignore some directories or files that you don't want to count, this parameter is disposable
- --ignore-save IGNORE_SAVE
- override 'ignore' in config and ignore some files or directory according to this value
- --ignore-add IGNORE_ADD
- append new value for 'ignore' in config and ignore some files or directory according to this value
- --restore restore default config
-
+ -o OUTPUT_PATH, --output OUTPUT_PATH
+ specify an output path if you want to store the result
+ --suffix SUFFIX what code files do you want to count
+ --comment COMMENT the comment symbol, which can be judged whether the current line is a comment
+ --ignore IGNORE ignore some directories or files that you don't want to count
```
-Example
-
-### Specify a path (file or directory) directly
+#### Search the given path directly
```shell
-$ codecount ./code-counter
+$ cocnt search ./code-counter/
RESULT
====================
- Total file lines : 344 (100.00%)
- Total code lines : 269 ( 78.20%)
- Total blank lines : 55 ( 15.99%)
- Total comment lines : 20 ( 5.81%)
+ Total file lines : 860 (100.00%)
+ Total code lines : 689 ( 80.12%)
+ Total blank lines : 142 ( 16.51%)
+ Total comment lines : 29 ( 3.37%)
Type | Files | Ratio | Lines | Ratio
-----------------------------------------------------------------
- py | 7 | 100.00% | 269 | 100.00%
-
- Totally cost 0.00899815559387207s.
-
+ py | 9 | 100.00% | 689 | 100.00%
+ Totally cost 0.005997896194458008 s.
```
-### Multipath input (Use a file that contain a list of file or directory path as input)
+#### Search multiple paths at the same time
-Create a file, such as named `list.txt`, which contain various file path or directory path, just as follow:
-
-```
-F:/Github/miscode
-F:/IDEA/jokul
-```
-
-then use `[-l --list]` to specify `list.txt` contain a list of path:
+You can specify more than one path separated by commas. For example, if you want to count the code files under the directory `./Cpp`, `./Go`, `./Rust` at the same time, the command can be like this.
```shell
-$ codecount ./list.txt -l
+$ cocnt search ./Cpp,./Go,./Rust
RESULT
====================
- Total file lines : 35137 (100.00%)
- Total code lines : 24235 ( 68.97%)
- Total blank lines : 5009 ( 14.26%)
- Total comment lines : 5893 ( 16.77%)
+ Total file lines : 17485 (100.00%)
+ Total code lines : 10679 ( 61.08%)
+ Total blank lines : 1704 ( 9.75%)
+ Total comment lines : 5102 ( 29.18%)
Type | Files | Ratio | Lines | Ratio
-----------------------------------------------------------------
- java | 236 | 36.48% | 7074 | 29.19%
- c | 28 | 4.33% | 2533 | 10.45%
- h | 8 | 1.24% | 503 | 2.08%
- cpp | 75 | 11.59% | 3094 | 12.77%
- go | 33 | 5.10% | 1036 | 4.27%
- js | 21 | 3.25% | 1664 | 6.87%
- kt | 26 | 4.02% | 696 | 2.87%
- lisp | 1 | 0.15% | 48 | 0.20%
- pde | 59 | 9.12% | 1930 | 7.96%
- py | 160 | 24.73% | 5657 | 23.34%
-
- Totally cost 6.179003953933716s.
-
+ c | 29 | 14.15% | 2683 | 25.12%
+ h | 7 | 3.41% | 503 | 4.71%
+ cpp | 77 | 37.56% | 3267 | 30.59%
+ hpp | 1 | 0.49% | 238 | 2.23%
+ go | 60 | 29.27% | 2624 | 24.57%
+ rs | 31 | 15.12% | 1364 | 12.77%
+
+ Totally cost 0.0940864086151123 s.
```
-### Show verbose searching information
+`code-counter` supports searching paths in different directories at the same time, so the given paths do not need to be in the same directory.
-Searching information is not displayed by default. If you concern about the searching information, you can use `[-v --verbose]` to view it:
+#### Show verbose searching information
-```
-$ codecount ./code-counter -v
+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.
+
+```shell
+$ cocnt search ./code-counter -v
SEARCHING
====================
File Type | Lines | Code | Blank | Comment | File Path
------------------------------------------------------------------------------------------
- py | 12 | 8 | 2 | 2 | ./code-counter/code_counter/conf/config.py
- py | 0 | 0 | 0 | 0 | ./code-counter/code_counter/conf/__init__.py
- py | 240 | 187 | 37 | 16 | ./code-counter/code_counter/core/codecounter.py
- py | 0 | 0 | 0 | 0 | ./code-counter/code_counter/core/__init__.py
- py | 1 | 1 | 0 | 0 | ./code-counter/code_counter/__init__.py
- py | 43 | 29 | 12 | 2 | ./code-counter/code_counter/__main__.py
- py | 48 | 44 | 4 | 0 | ./code-counter/setup.py
+ py | 80 | 62 | 16 | 2 | ./code-counter\code_counter\conf\config.py
+ py | 0 | 0 | 0 | 0 | ./code-counter\code_counter\conf\__init__.py
+ py | 88 | 75 | 11 | 2 | ./code-counter\code_counter\core\argspaser.py
+ py | 257 | 198 | 38 | 21 | ./code-counter\code_counter\core\codecounter.py
+ py | 0 | 0 | 0 | 0 | ./code-counter\code_counter\core\__init__.py
+ py | 1 | 1 | 0 | 0 | ./code-counter\code_counter\__init__.py
+ py | 35 | 22 | 11 | 2 | ./code-counter\code_counter\__main__.py
+ py | 48 | 44 | 4 | 0 | ./code-counter\setup.py
+ py | 351 | 287 | 62 | 2 | ./code-counter\test\test.py
RESULT
====================
- Total file lines : 344 (100.00%)
- Total code lines : 269 ( 78.20%)
- Total blank lines : 55 ( 15.99%)
- Total comment lines : 20 ( 5.81%)
+ Total file lines : 860 (100.00%)
+ Total code lines : 689 ( 80.12%)
+ Total blank lines : 142 ( 16.51%)
+ Total comment lines : 29 ( 3.37%)
Type | Files | Ratio | Lines | Ratio
-----------------------------------------------------------------
- py | 7 | 100.00% | 269 | 100.00%
+ py | 9 | 100.00% | 689 | 100.00%
+
+ Totally cost 0.006999015808105469 s.
+```
+
+
+#### Search code files for specific file suffixes
- Totally cost 0.00899958610534668s.
+`code-counter` has a default configuration, which includes common code file suffixes, comment symbols, and directory or file names that need to be ignored. Therefore, if there are no special requirements during use, you can directly use `cocnt search` for code statistics.
+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:
+
+```shell
+$ cocnt search ./project --suffix="py,java"
+```
+
+Of course, specify the comment symbols during searching the code, which is helpful to count the number of comments in the code.
+
+```shell
+$ cocnt search ./project --suffix="py,java" --comment="#,//,/**"
```
-### Specify an output path
+#### Ignore directories or files during the search
-The output path is specified by `[-o --output]`, if you have specified it, the output information would not display on the console, as follows:
+During the search, it is easy to count the code files or directories that you do not want to count, so you can use the `--ignore` to specify the directory or file names that need to be ignored during the search.
```shell
-$ codecount ./code-counter -v -o ./result.txt
+$ cocnt search ./project --suffix="py,java" --comment="#,//,/**" --ignore="target,__pycache__"
+```
+
+Generally speaking, the configuration file of `code-counter` already contains many common default configurations. For example, the default value of `ignore` is shown below.
+
+```json
+"ignore": [
+ "out",
+ "venv",
+ ".git",
+ ".idea",
+ "build",
+ "target",
+ "node_modules",
+ ".vscode",
+ "dist"
+]
+```
- Totally cost 0.012001991271972656s.
+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`.
+### Specify the output path to save the search results
+
+If you want to save the statistical results, you can specify the path to save the search results through the `[-o -- output]` flag. If an output path is specified, the output information will not be displayed on the console.
+
+```shell
+$ cocnt search ./code-counter -v -o result.txt
+
+ Totally cost 0.0050046443939208984 s.
```
-Verbose searching information and results have been written in `./result.txt`
+verbose search information and results will be written to `result.txt`
### Visualize statistical results
-Data visualization can give us a more intuitive feeling, so I provide the visualization instruction `[-g --graph]` that used to visualize the statistics, just as follow:
+Data visualization can provide a more intuitive feeling, so you can specify the `[-g -- graph]` flag to visualize the statistical results during the search.
```
-$ codecount list.txt -l -g
+$ cocnt search ./miscode -g
```
-In addition to the text statistics, the statistical chart as shown in the figure below will also be displayed
+In addition to the statistical data displayed on the terminal, the statistical chart shown in the figure below will also be displayed.

+config
-## Configuration
+Configure `code-counter`, and the help information of `cocnt config` is as follows.
-Default `config.json` is as follow:
+```shell
+$ cocnt config --help
+usage: cocnt config [-h] [--list] [--suffix-reset SUFFIX_RESET] [--suffix-add SUFFIX_ADD] [--comment-reset COMMENT_RESET] [--comment-add COMMENT_ADD] [--ignore-reset IGNORE_RESET] [--ignore-add IGNORE_ADD] [--restore]
-```json
+configure code-counter
+
+optional arguments:
+ -h, --help show this help message and exit
+ --list list all variables set in the config file, along with their values
+ --suffix-reset SUFFIX_RESET
+ reset the 'suffix' in the config and count code lines according to this value
+ --suffix-add SUFFIX_ADD
+ append new value for the 'suffix' in the config and count code lines according to this value
+ --suffix-del SUFFIX_DEL
+ delete some values of the 'suffix' in the config
+ --comment-reset COMMENT_RESET
+ reset the 'comment' in the config and count comment lines according to this value
+ --comment-add COMMENT_ADD
+ append new value for the 'comment' in the config and count comment lines according to this value
+ --comment-del COMMENT_DEL
+ delete some values of the 'comment' in the config
+ --ignore-reset IGNORE_RESET
+ reset the 'ignore' in the config and ignore some files or directories according to this value
+ --ignore-add IGNORE_ADD
+ append new value for the 'ignore' in the config and ignore some files or directories according to this value
+ --ignore-del IGNORE_DEL
+ delete some values of the 'ignore' in the config
+ --restore restore default config
+```
+
+#### List configuration information
+
+Under the `config` subcommand, specify the `--list` to display configuration information. The default configuration of `code-counter` is shown below.
+
+```shell
+$ cocnt config --list
{
"suffix": [
"c",
@@ -268,266 +338,77 @@ Default `config.json` is as follow:
}
```
- + **`suffix`**: what code files do you want to count;
- + **`comment`**: the comment symbol, which can be judged whether the current line is a comment;
- + **`ignore`**: ignore some directories or files that you don't want to count.
-
-> **NOTE**
->
-> + For **`suffix`**, for example, `Python` file's suffix is `py`, `C++` file's suffix is `cpp`
-> + For **`ignore`**, if you want to count how much code you have written, but there are some code generated automatically by the project, ignoring the generated code will make the statistics more accurate
-> + For **`comment`**, if a comment is between two comment symbols and there is no other comment symbol at the beginning of the line, the content of the line may be misjudged, such as identifying the comment as code
-
-### Specify `suffix`
-
-The default suffix already contains common code suffixes, but if you know exactly what type of code you want to count, you can specify suffixes directly, which can ignore files that don't need to be counted and speed up the counting. [--suffix]` receive a parameter list (split by `,`).
-
-```shell
-$ codecount ./jokul --suffix="html,css,java,js"
-
- RESULT
- ====================
- Total file lines : 3977 (100.00%)
- Total code lines : 3061 ( 76.97%)
- Total blank lines : 493 ( 12.40%)
- Total comment lines : 423 ( 10.64%)
-
- Type | Files | Ratio | Lines | Ratio
- -----------------------------------------------------------------
- js | 15 | 28.30% | 1485 | 48.51%
- html | 1 | 1.89% | 38 | 1.24%
- css | 9 | 16.98% | 338 | 11.04%
- java | 28 | 52.83% | 1200 | 39.20%
-
- Totally cost 0.0800015926361084s.
-```
-
-But this way of setting parameters is one-time. If you want to set parameters and save them, you can use `[--suffix-save]`.
-
-#### Specify `suffix` and override
-
-Use instruction `[--suffix-save]` and receive a parameter list (split by `,`).
-
-```shell
-$ codecount ./jokul --suffix-save="html,css,java,js"
-'suffix' will be replaced with ['html', 'css', 'java', 'js'] (y/n)y
-
- RESULT
- ====================
- Total file lines : 3977 (100.00%)
- Total code lines : 3061 ( 76.97%)
- Total blank lines : 493 ( 12.40%)
- Total comment lines : 423 ( 10.64%)
-
- Type | Files | Ratio | Lines | Ratio
- -----------------------------------------------------------------
- js | 15 | 28.30% | 1485 | 48.51%
- html | 1 | 1.89% | 38 | 1.24%
- css | 9 | 16.98% | 338 | 11.04%
- java | 28 | 52.83% | 1200 | 39.20%
-
- Totally cost 0.07199478149414062s.
-
-```
-
-#### Add `suffix` parameters
+ + **`suffix`**: Code file suffix that will be counted during the search
+ + **`comment`**: Comment symbol that can be judged whether the current line is comment during the search
+ + **`ignore`**: Directories or files you want to ignore during the search
-If you don't want to override the default config, but just want to add some new suffix for config, you can use `[--suffix-add]`. This way will still modify the `config.json`, so need you to confirm to perform.
+#### Reset the value of the configuration variable
-```shell
-$ codecount ./jokul --suffix-add="html,css,java,js"
-'suffix' will be appended with ['html', 'css', 'java', 'js'] (y/n)y
-
- RESULT
- ====================
- Total file lines : 3977 (100.00%)
- Total code lines : 3061 ( 76.97%)
- Total blank lines : 493 ( 12.40%)
- Total comment lines : 423 ( 10.64%)
-
- Type | Files | Ratio | Lines | Ratio
- -----------------------------------------------------------------
- js | 15 | 28.30% | 1485 | 48.51%
- html | 1 | 1.89% | 38 | 1.24%
- css | 9 | 16.98% | 338 | 11.04%
- java | 28 | 52.83% | 1200 | 39.20%
+The default configuration of `code-counter` basically includes common code file suffixes, comment symbols, and directory or file names that need to be ignored. But if you don't think so many variable values would be used during the search, you can choose to reset the default values.
- Totally cost 0.06599712371826172s.
-```
+ + `--suffix-reset` can reset the default code file suffixes.
+ + `--comment-reset` can reset the default comment symbols
+ + `--ignore-reset` can reset the default directory or files to ignore
-### Specify `comment`
+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.
-If you know the type of code to be counted, and know what the comment symbols of the language are, you can use `[--comment]` to set.
+Multiple values can be separated by commas, as shown in the following example.
```shell
-$ codecount ./code-counter --comment='#,"""'
-
- RESULT
- ====================
- Total file lines : 449 (100.00%)
- Total code lines : 353 ( 78.62%)
- Total blank lines : 76 ( 16.93%)
- Total comment lines : 20 ( 4.45%)
-
- Type | Files | Ratio | Lines | Ratio
- -----------------------------------------------------------------
- py | 7 | 100.00% | 353 | 100.00%
-
- Totally cost 0.023006200790405273s.
+$ cocnt config --suffix-reset="python,java" --comment-reset="#,/**,//" --ignore-reset="__pycache_,.pytest_cache,target"
+'suffix' will be replaced with ['python', 'java'] . (y/n) y
+'comment' will be replaced with ['#', '/**', '//'] . (y/n) y
+'ignore' will be replaced with ['__pycache_', '.pytest_cache', 'target'] . (y/n) y
```
-This way also is one-time.
-
-#### Specify `comment` and override
-
-In the default config, `comment` already contains common comment symbols, so you don't need to modify it. If you need to override the default value of 'comment' indeed, you can use `[--comment-save]` to override it.
-
-#### Add `comment` parameters
+#### Add the value of the configuration variable
-If you want to add some new comment symbols, you can use `[--comment-add]`.
+For the case of adding the value of the configuration variable, the following flags can be used:
+ + `--suffix-add` add code file suffixes
+ + `--comment-add` add comment symbols
+ + `--ignore-add` add the directories or files to ignore
-### Specify `ignore`
+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.
-Ignoring unnecessary folders can speed up the count, use `[--ignore]` to set.
+Multiple values can be separated by commas, as shown in the following example.
```shell
-$ codecount ./code-counter/ --ignore="__pycache__"
-
- RESULT
- ====================
- Total file lines : 449 (100.00%)
- Total code lines : 349 ( 77.73%)
- Total blank lines : 76 ( 16.93%)
- Total comment lines : 24 ( 5.35%)
-
- Type | Files | Ratio | Lines | Ratio
- -----------------------------------------------------------------
- py | 7 | 100.00% | 349 | 100.00%
-
- Totally cost 0.15700435638427734s.
+$ cocnt config --suffix-add="js,lisp" --comment-add=";" --ignore-add="node_modules"
+'suffix' will be appended with ['js', 'lisp'] . (y/n) y
+'comment' will be appended with [';'] . (y/n) y
+'ignore' will be appended with ['node_modules'] . (y/n) y
```
-This way also is one-time.
-
-#### Specify `ignore` and override
-
-If the default `ignore` is not what you want, you can use `[--ignore-save]` to modify it.
-
-#### Add `ignore` parameters
-
-If the default `ignore` is missing the value you need, and you don't want to override the default value, you can use `[--ignore-add]` to add some new value for `ignore`.
+#### Delete some configuration variable values
-### Show config
+For the deletion of configuration variable values, `code-counter` provides the following flags:
++ `--suffix-del` delete unwanted code file suffixes from the default configuration
++ `--comment-del` delete unwanted comment symbols from the default configuration
++ `--ignore-del` delete the directory or file names that don't need to be ignored from the default configuration
-Use placeholder `CONFIG` to show the content of `config.json`.
+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.
-```shell
-$ codecount CONFIG
-```
-
-### The better way to modify the config
-
-Sometimes we don't want to search and count when we modify `config.json`, so we can use the placeholder `CONFIG` to indicate that we only modify the config without searching and counting. Using the placeholder 'config' to set the parameter will display the updated value after modifying the parameter.
+Multiple values can be separated by commas, as shown in the following example.
```shell
-$ codecount CONFIG --suffix-save="java,js,html,py" --comment-save="//,#,/**" --ignore-add="__pycache__"
-'ignore' will be appended with ['__pycache__'] (y/n)y
-'suffix' will be replaced with ['java', 'js', 'html', 'py'] (y/n)y
-'comment' will be replaced with ['//', '#', '/**'] (y/n)y
-{
- "suffix": [
- "java",
- "js",
- "html",
- "py"
- ],
- "comment": [
- "//",
- "#",
- "/**"
- ],
- "ignore": [
- "out",
- "venv",
- ".git",
- ".idea",
- "build",
- "target",
- "node_modules",
- ".vscode",
- "dist",
- "__pycache__"
- ]
-}
+$ cocnt config --suffix-del="clj,lisp" --comment-del=";" --ignore-del="build,target"
+'suffix' will remove ['clj', 'lisp'] . (y/n) y
+'comment' will remove [';'] . (y/n) y
+'ignore' will remove ['build', 'target'] . (y/n) y
```
-### Restore default config
+### Restore default configuration
-Use `[--restore]` to restore the default config.
+Use the `--restore` flag to restore the default configuration of `code-counter`.
```shell
-$ codecount CONFIG --restore
-Default configuration will be restored (y/n)?y
-{
- "suffix": [
- "c",
- "cc",
- "clj",
- "cpp",
- "cs",
- "cu",
- "cuh",
- "dart",
- "go",
- "h",
- "hpp",
- "java",
- "jl",
- "js",
- "kt",
- "lisp",
- "lua",
- "pde",
- "m",
- "php",
- "py",
- "R",
- "rb",
- "rs",
- "rust",
- "sh",
- "scala",
- "swift",
- "ts",
- "vb"
- ],
- "comment": [
- "#",
- "//",
- "/*",
- "*",
- "*/",
- ":",
- ";",
- "\"\"\"\""
- ],
- "ignore": [
- "out",
- "venv",
- ".git",
- ".idea",
- "build",
- "target",
- "node_modules",
- ".vscode",
- "dist"
- ]
-}
+$ cocnt config --restore
+The default configuration will be restored. (y/n) y
```
## [License](https://github.com/InnoFang/code-counter/blob/master/LICENSE)
- Copyright 2019 Inno Fang
+ Copyright 2019-2022 Inno Fang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/README_CN.md b/README_CN.md
index ec51453..d4e9548 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -1,18 +1,18 @@
# Code Counter
-一个可以帮助你轻松地统计代码并显示详细结果的命令行界面(CLI)小工具。
+一个可以帮助你轻松进行代码行数统计的命令行小工具。
-[English](https://github.com/InnoFang/code-counter/blob/master/README.md) | 中文
+[English](./README.md) | 中文
## 安装
-使用 PyPI 安装:
+可以直接使用 PyPI 进行安装。
```shell
pip install code-counter
```
-也可以使用源码进行安装
+也可以下载源码后再安装。
```shell
git clone https://github.com/innofang/code-counter.git
@@ -22,197 +22,264 @@ python setup.py install
## 快速开始
-切换到任意代码目录下 ( 比如 `code-counter` ) ,并键入如下命令
+打开终端,直接对想要统计的代码路径进行搜索。
+
+比如使用 `cocnt search` 来统计 `code-counter` 的代码行数。(`cocnt` 即 `codecounter` 的缩写)
```shell
-$ codecount .
+$ cocnt search ./code-counter
RESULT
====================
- Total file lines : 344 (100.00%)
- Total code lines : 269 ( 78.20%)
- Total blank lines : 55 ( 15.99%)
- Total comment lines : 20 ( 5.81%)
+ Total file lines : 884 (100.00%)
+ Total code lines : 698 ( 78.96%)
+ Total blank lines : 157 ( 17.76%)
+ Total comment lines : 29 ( 3.28%)
Type | Files | Ratio | Lines | Ratio
-----------------------------------------------------------------
- py | 7 | 100.00% | 269 | 100.00%
-
- Totally cost 0.010030031204223633s.
+ py | 9 | 100.00% | 698 | 100.00%
+ Totally cost 0.02192854881286621 s.
```
-更多使用方法请参考 [用法](#usage) 和 [案例](#example)。
+更多使用方法请参考[用法](#usage)。
用法
+`code-counter` 的帮助信息如下。
```shell
-$ codecount -h
-usage: code-counter [-h] [-V] [-l] [-v] [-g] [-o OUTPUT] [--suffix SUFFIX] [--suffix-save SUFFIX_SAVE] [--suffix-add SUFFIX_ADD] [--comment COMMENT]
- [--comment-save COMMENT_SAVE] [--comment-add COMMENT_ADD] [--ignore IGNORE] [--ignore-save IGNORE_SAVE] [--ignore-add IGNORE_ADD]
- [--restore]
- [path, CONFIG]
+$ cocnt --help
+usage: cocnt []
+These are common Code-Counter commands used in various situations:
+ search Search code in the given path(s)
+ config Configure Code-Counter
A command-line interface (CLI) utility that can help you easily count code and display detailed results.
positional arguments:
- [path, CONFIG] specify a file or directory path you want to count or use CONFIG placeholder to configure
+ command Subcommand to run, `search` or `config`
+
+optional arguments:
+ -h, --help show this help message and exit
+ --version show program's version number and exit
+```
+
+`code-counter` 支持两个子命令:[`search`](#search) 和 [`config`](#config)
+
+search
+
+搜索给定的路径并统计,`cocnt search` 的帮助信息如下。
+
+```shell
+$ cocnt search --help
+usage: cocnt search input_path [-h] [-v] [-g] [-o OUTPUT_PATH] [--suffix SUFFIX] [--comment COMMENT] [--ignore IGNORE]
+
+Search code in the given path(s)
+
+positional arguments:
+ input_path counting the code lines according to the given path(s)
optional arguments:
-h, --help show this help message and exit
- -V, --version show program's version number and exit
- -l, --list the file contains a list of file path, which can make you search more than one file or directory
- -v, --verbose show verbose infomation
+ -v, --verbose show verbose information
-g, --graph choose to whether to visualize the result
- -o OUTPUT, --output OUTPUT
- specify a output path if you want to store the result
- --suffix SUFFIX what code files do you want to count, this parameter is disposable
- --suffix-save SUFFIX_SAVE
- override 'suffix' in config and count codes according to this value
- --suffix-add SUFFIX_ADD
- append new value for 'suffix' in config and count codes according to this value
- --comment COMMENT the comment symbol, which can be judged whether the current line is a comment, this parameter is disposable
- --comment-save COMMENT_SAVE
- override 'comment' in config and count comment lines according to this value
- --comment-add COMMENT_ADD
- append new value for 'comment' in config and count comment lines according to this value
- --ignore IGNORE ignore some directories or files that you don't want to count, this parameter is disposable
- --ignore-save IGNORE_SAVE
- override 'ignore' in config and ignore some files or directory according to this value
- --ignore-add IGNORE_ADD
- append new value for 'ignore' in config and ignore some files or directory according to this value
- --restore restore default config
-
+ -o OUTPUT_PATH, --output OUTPUT_PATH
+ specify an output path if you want to store the result
+ --suffix SUFFIX what code files do you want to count
+ --comment COMMENT the comment symbol, which can be judged whether the current line is a comment
+ --ignore IGNORE ignore some directories or files that you don't want to count
```
-案例
-
-### 直接指定文件或目录路径
+#### 直接搜索给定的路径
```shell
-$ codecount ./code-counter
+$ cocnt search ./code-counter/
RESULT
====================
- Total file lines : 344 (100.00%)
- Total code lines : 269 ( 78.20%)
- Total blank lines : 55 ( 15.99%)
- Total comment lines : 20 ( 5.81%)
+ Total file lines : 860 (100.00%)
+ Total code lines : 689 ( 80.12%)
+ Total blank lines : 142 ( 16.51%)
+ Total comment lines : 29 ( 3.37%)
Type | Files | Ratio | Lines | Ratio
-----------------------------------------------------------------
- py | 7 | 100.00% | 269 | 100.00%
-
- Totally cost 0.00899815559387207s.
-
+ py | 9 | 100.00% | 689 | 100.00%
+ Totally cost 0.005997896194458008 s.
```
-### 多路径输入(使用一个包含文件或目录路径列表的文件作为输入)
+#### 同时搜索多个路径
-创建一个文件,比如叫 `list.txt`,该文件将包含多个文件或目录路径,如下所示
-
-```
-F:/Github/miscode
-F:/IDEA/jokul
-```
-
-然后使用 `[-l --list]` 来指定 `list.txt` 是包含路径列表的文件:
+你可以指定多个路径,路径用逗号隔开。比如你想同时搜索 `./Cpp`,`./Go`,`./Rust` 这几个目录下的代码文件,则可以这样写。
```shell
-$ codecount ./list.txt -l
+$ cocnt search ./Cpp,./Go,./Rust
RESULT
====================
- Total file lines : 35137 (100.00%)
- Total code lines : 24235 ( 68.97%)
- Total blank lines : 5009 ( 14.26%)
- Total comment lines : 5893 ( 16.77%)
+ Total file lines : 17485 (100.00%)
+ Total code lines : 10679 ( 61.08%)
+ Total blank lines : 1704 ( 9.75%)
+ Total comment lines : 5102 ( 29.18%)
Type | Files | Ratio | Lines | Ratio
-----------------------------------------------------------------
- java | 236 | 36.48% | 7074 | 29.19%
- c | 28 | 4.33% | 2533 | 10.45%
- h | 8 | 1.24% | 503 | 2.08%
- cpp | 75 | 11.59% | 3094 | 12.77%
- go | 33 | 5.10% | 1036 | 4.27%
- js | 21 | 3.25% | 1664 | 6.87%
- kt | 26 | 4.02% | 696 | 2.87%
- lisp | 1 | 0.15% | 48 | 0.20%
- pde | 59 | 9.12% | 1930 | 7.96%
- py | 160 | 24.73% | 5657 | 23.34%
-
- Totally cost 6.179003953933716s.
-
+ c | 29 | 14.15% | 2683 | 25.12%
+ h | 7 | 3.41% | 503 | 4.71%
+ cpp | 77 | 37.56% | 3267 | 30.59%
+ hpp | 1 | 0.49% | 238 | 2.23%
+ go | 60 | 29.27% | 2624 | 24.57%
+ rs | 31 | 15.12% | 1364 | 12.77%
+
+ Totally cost 0.0940864086151123 s.
```
-### 展示详细搜索信息
+`code-counter` 支持同时搜索不同目录下的路径,因此搜索路径不需要都在同一个目录下。
-搜索信息默认是不显示的。如果你比较关注搜索信息,可以使用 `[-v --verbose]` 来查看它:
+#### 展示详细搜索信息
+搜索信息默认是不显示的。如果你比较关注搜索信息,可以在搜索时使用 `[-v --verbose]` 标志。
-```
-$ codecount ./code-counter -v
+```shell
+$ cocnt search ./code-counter -v
SEARCHING
====================
File Type | Lines | Code | Blank | Comment | File Path
------------------------------------------------------------------------------------------
- py | 12 | 8 | 2 | 2 | ./code-counter/code_counter/conf/config.py
- py | 0 | 0 | 0 | 0 | ./code-counter/code_counter/conf/__init__.py
- py | 240 | 187 | 37 | 16 | ./code-counter/code_counter/core/codecounter.py
- py | 0 | 0 | 0 | 0 | ./code-counter/code_counter/core/__init__.py
- py | 1 | 1 | 0 | 0 | ./code-counter/code_counter/__init__.py
- py | 43 | 29 | 12 | 2 | ./code-counter/code_counter/__main__.py
- py | 48 | 44 | 4 | 0 | ./code-counter/setup.py
+ py | 80 | 62 | 16 | 2 | ./code-counter\code_counter\conf\config.py
+ py | 0 | 0 | 0 | 0 | ./code-counter\code_counter\conf\__init__.py
+ py | 88 | 75 | 11 | 2 | ./code-counter\code_counter\core\argspaser.py
+ py | 257 | 198 | 38 | 21 | ./code-counter\code_counter\core\codecounter.py
+ py | 0 | 0 | 0 | 0 | ./code-counter\code_counter\core\__init__.py
+ py | 1 | 1 | 0 | 0 | ./code-counter\code_counter\__init__.py
+ py | 35 | 22 | 11 | 2 | ./code-counter\code_counter\__main__.py
+ py | 48 | 44 | 4 | 0 | ./code-counter\setup.py
+ py | 351 | 287 | 62 | 2 | ./code-counter\test\test.py
RESULT
====================
- Total file lines : 344 (100.00%)
- Total code lines : 269 ( 78.20%)
- Total blank lines : 55 ( 15.99%)
- Total comment lines : 20 ( 5.81%)
+ Total file lines : 860 (100.00%)
+ Total code lines : 689 ( 80.12%)
+ Total blank lines : 142 ( 16.51%)
+ Total comment lines : 29 ( 3.37%)
Type | Files | Ratio | Lines | Ratio
-----------------------------------------------------------------
- py | 7 | 100.00% | 269 | 100.00%
+ py | 9 | 100.00% | 689 | 100.00%
- Totally cost 0.00899958610534668s.
+ Totally cost 0.006999015808105469 s.
+```
+#### 搜索特定文件后缀的代码文件
+
+`code-counter` 有默认的配置,默认配置中包含了常见的代码文件后缀、注释符号以及需要忽略的目录或文件名。因此在使用的时候如果没有特别的需求,可以直接使用 `cocnt search` 进行代码的统计。
+
+如果在搜索的时候,只想统计某一些特定的代码文件的情况,那么可以使用 `--suffix` 来指定代码文件后缀。比如:
+
+```shell
+$ cocnt search ./project --suffix="py,java"
```
+当然,在搜索时也可以指定编程语言的注释符号,这有利于更好的统计代码中注释的数量。
+
+```shell
+$ cocnt search ./project --suffix="py,java" --comment="#,//,/**"
+```
-### 指定输出路径
+#### 搜索时过忽略指定的目录或文件
-通过 `[-o --output]` 来指定输出路径,如果制定了输出路径,那么输出信息将不会显示在控制台,如下所示:
+在搜索代码文件的时候,容易统计到不想统计的代码文件或者目录,因此可以使用 `--ignore` 来指定在搜索时需要过滤的目录或者文件名。
```shell
-$ codecount ./code-counter -v -o ./result.txt
+$ cocnt search ./project --suffix="py,java" --comment="#,//,/**" --ignore="target,__pycache__"
+```
- Totally cost 0.012001991271972656s.
+一般来说,`code-counter` 的配置文件里已经包含了很多常见的默认配置,比如 `ignore` 的默认值如下所示。
+```json
+"ignore": [
+ "out",
+ "venv",
+ ".git",
+ ".idea",
+ "build",
+ "target",
+ "node_modules",
+ ".vscode",
+ "dist"
+]
```
-详细的搜索信息和结果将写入到 `./result.txt` 中
-### 可视化统计结果
+因此,如果在某些情况下,要搜索的目录或文件与 `ignore` 的默认值相同,那么可以通过设置 `--ignore=""` 来置空 `ignore` 的默认值,当然这是临时的。如果想要持久化这些修改,可以参考后面介绍`cocnt config` 时会提及的 `--ignore-reset` 标志。
+
+#### 指定搜索结果的保存路径
-数据可视化可以给我们更直观的感受,所以我提供了将统计结果可视化的指令 `[-g --graph]`。使用示例如下:
+如果想保存统计结果,则可以通过 `[-o --output]` 标志来指定搜索结果的保存路径。如果指定了输出路径,那么输出信息将不会显示在控制台。
+```shell
+$ cocnt search ./code-counter -v -o result.txt
+
+ Totally cost 0.0050046443939208984 s.
```
-$ codecount list.txt -l -g
+
+详细的搜索信息和结果将写入到 `./result.txt` 中。
+
+#### 可视化统计结果
+
+数据可视化可以提供更直观的感受,所以在搜索时可以指定 `[-g --graph]` 标志来可视化统计结果。
+
+```shell
+$ cocnt search ./miscode -g
```
-除了显示文本统计数据之外,还会展示如下图的的统计图表
+除了在终端显示统计数据外,还会显示如下图的的统计图表。

+config
-## 配置
+对 `code-counter` 进行设置,`cocnt config` 的帮助信息如下。
-默认的配置文件 `config.json` 如下所示:
+```shell
+$ cocnt config --help
+usage: cocnt config [-h] [--list] [--suffix-reset SUFFIX_RESET] [--suffix-add SUFFIX_ADD] [--comment-reset COMMENT_RESET] [--comment-add COMMENT_ADD] [--ignore-reset IGNORE_RESET] [--ignore-add IGNORE_ADD] [--restore]
-```json
+configure code-counter
+
+optional arguments:
+ -h, --help show this help message and exit
+ --list list all variables set in the config file, along with their values
+ --suffix-reset SUFFIX_RESET
+ reset the 'suffix' in the config and count code lines according to this value
+ --suffix-add SUFFIX_ADD
+ append new value for the 'suffix' in the config and count code lines according to this value
+ --suffix-del SUFFIX_DEL
+ delete some values of the 'suffix' in the config
+ --comment-reset COMMENT_RESET
+ reset the 'comment' in the config and count comment lines according to this value
+ --comment-add COMMENT_ADD
+ append new value for the 'comment' in the config and count comment lines according to this value
+ --comment-del COMMENT_DEL
+ delete some values of the 'comment' in the config
+ --ignore-reset IGNORE_RESET
+ reset the 'ignore' in the config and ignore some files or directories according to this value
+ --ignore-add IGNORE_ADD
+ append new value for the 'ignore' in the config and ignore some files or directories according to this value
+ --ignore-del IGNORE_DEL
+ delete some values of the 'ignore' in the config
+ --restore restore default config
+```
+
+#### 显示配置信息
+
+在 `config` 子命令下,指定 `--list` 来显示配置信息。`code-counter` 的默认配置如下所示。
+
+```shell
+$ cocnt config --list
{
"suffix": [
"c",
@@ -270,265 +337,77 @@ $ codecount list.txt -l -g
}
```
- + **`suffix`**: 你想统计的代码文件的后缀
- + **`comment`**: 注释符号,用来判断当前行是否是注释
- + **`ignore`**: 忽略一些你不想统计的目录或文件
-
-> **注意**
->
-> + 对于 **`suffix`**, 举例来说, `Python` 文件的后缀是 `py`, `C++` 文件的后缀是 `cpp`
-> + 对于 **`ignore`**, 如果你想统计你写了多少代码,但存在一些项目自动生成的代码,那么忽略掉这些生成代码会使统计结果更准确
-> + 对于 **`comment`**, 如果某一行注释位于两个注释符号之间,并且该行开头没有其它注释符号作为标记,那么这一行的内容可能会被误判,比如将该行注释识别为代码
-
-### 指定 `suffix`
-
-默认的 `suffix` 已经包含了常见的代码后缀,但是如果你明确的知道要计数的代码类型有哪些,那么可以直接指定后缀,这样可以忽略不需要计数的文件并加快计数。 `[--suffix]` 接受一个参数列表(使用 `,` 分割参数)。
-
-```shell
-$ codecount ./jokul --suffix="html,css,java,js"
-
- RESULT
- ====================
- Total file lines : 3977 (100.00%)
- Total code lines : 3061 ( 76.97%)
- Total blank lines : 493 ( 12.40%)
- Total comment lines : 423 ( 10.64%)
-
- Type | Files | Ratio | Lines | Ratio
- -----------------------------------------------------------------
- js | 15 | 28.30% | 1485 | 48.51%
- html | 1 | 1.89% | 38 | 1.24%
- css | 9 | 16.98% | 338 | 11.04%
- java | 28 | 52.83% | 1200 | 39.20%
-
- Totally cost 0.0800015926361084s.
-```
-
-这种设置参数的方式是一次性的,如果你想设置参数并保存,可以使用 `[--suffix-save]`
-
-#### 指定 `suffix` 并覆盖
-
-使用指令 `[--suffix-save]` 并接受参数列表(使用 `,` 分割参数)。
-
-```shell
-$ codecount ./jokul --suffix-save="html,css,java,js"
-'suffix' will be replaced with ['html', 'css', 'java', 'js'] (y/n)y
-
- RESULT
- ====================
- Total file lines : 3977 (100.00%)
- Total code lines : 3061 ( 76.97%)
- Total blank lines : 493 ( 12.40%)
- Total comment lines : 423 ( 10.64%)
-
- Type | Files | Ratio | Lines | Ratio
- -----------------------------------------------------------------
- js | 15 | 28.30% | 1485 | 48.51%
- html | 1 | 1.89% | 38 | 1.24%
- css | 9 | 16.98% | 338 | 11.04%
- java | 28 | 52.83% | 1200 | 39.20%
-
- Totally cost 0.07199478149414062s.
-
-```
-
-#### 添加 `suffix` 参数
-
-如果不想覆盖默认配置,只是想为 `suffix` 追加一些新的值,可以使用指令 `[--suffix-add]`. 这种方式仍然会修改 `config.json`,所以需要你确认一下。
-
-```shell
-$ codecount ./jokul --suffix-add="html,css,java,js"
-'suffix' will be appended with ['html', 'css', 'java', 'js'] (y/n)y
+ + **`suffix`**: 搜索时会进行统计的代码文件后缀
+ + **`comment`**: 注释符号,搜索时会判断当前行是否为注释
+ + **`ignore`**: 搜索时想忽略的目录或文件
- RESULT
- ====================
- Total file lines : 3977 (100.00%)
- Total code lines : 3061 ( 76.97%)
- Total blank lines : 493 ( 12.40%)
- Total comment lines : 423 ( 10.64%)
+#### 重置配置信息
- Type | Files | Ratio | Lines | Ratio
- -----------------------------------------------------------------
- js | 15 | 28.30% | 1485 | 48.51%
- html | 1 | 1.89% | 38 | 1.24%
- css | 9 | 16.98% | 338 | 11.04%
- java | 28 | 52.83% | 1200 | 39.20%
+`code-counter` 的默认配置信息基本包含了常见的代码文件后缀、注释符号以及需要忽略的目录或文件名。但如果你认为在搜索时用不到这么多变量值,那么可以选择覆盖掉默认值。
- Totally cost 0.06599712371826172s.
-```
+ + `--suffix-reset` 可以覆盖掉默认的代码文件后缀
+ + `--comment-reset` 可以覆盖掉默认的注释符号
+ + `--ignore-reset` 可以覆盖掉默认的要忽略的目录或文件
-### 指定 `comment`
+这三个标志可以组合使用,也可以单独使用。对于每个会修改配置文件的操作都会对你进行询问,此时你可以检查要修改的内容是否正确,如果确认修改可以输入 `y`,否则输入 `n` 不执行修改。
-如果知道要统计的代码类型且知道语言的注释符号有哪些,可以使用 `[--comment]` 来设置。
+对于要输入的多个值可以用逗号分隔,示例如下。
```shell
-$ codecount ./code-counter --comment='#,"""'
-
- RESULT
- ====================
- Total file lines : 449 (100.00%)
- Total code lines : 353 ( 78.62%)
- Total blank lines : 76 ( 16.93%)
- Total comment lines : 20 ( 4.45%)
-
- Type | Files | Ratio | Lines | Ratio
- -----------------------------------------------------------------
- py | 7 | 100.00% | 353 | 100.00%
-
- Totally cost 0.023006200790405273s.
+$ cocnt config --suffix-reset="python,java" --comment-reset="#,/**,//" --ignore-reset="__pycache_,.pytest_cache,target"
+'suffix' will be replaced with ['python', 'java'] . (y/n) y
+'comment' will be replaced with ['#', '/**', '//'] . (y/n) y
+'ignore' will be replaced with ['__pycache_', '.pytest_cache', 'target'] . (y/n) y
```
-这种设置方式也是一次性的
-
-#### 指定 `comment` 并覆盖
-
-在默认配置中,`comment` 已经包含了常见的注释符号,因此没有修改的必要。但是如果确实需要覆盖掉 `comment` 的默认值,可以使用 `[--comment-save]` 来修改。
+#### 追加配置信息
-#### 添加 `comment` 参数
+对于要追加配置信息的情况,可以使用以下标志:
+ + `--suffix-add` 追加默认情况下的代码文件后缀
+ + `--comment-add` 追加默认情况下的注释符号
+ + `--ignore-add` 追加默认情况下要忽略的文件类型
-可以使用 `[--comment-add]` 来添加新的注释符号。
-
-### 指定 `ignore`
-
-忽略不必要的的文件夹可以加快计数,使用 `[--ignore]` 来设置。
+这三个标志可以组合使用,也可以单独使用。对于每个会修改配置文件的操作都会对你进行询问,此时你可以检查要修改的内容是否正确,如果确认修改可以输入 `y`,否则输入 `n` 不执行修改。
+对于要输入的多个值可以用逗号分隔,示例如下。
```shell
-$ codecount ./code-counter/ --ignore="__pycache__"
-
- RESULT
- ====================
- Total file lines : 449 (100.00%)
- Total code lines : 349 ( 77.73%)
- Total blank lines : 76 ( 16.93%)
- Total comment lines : 24 ( 5.35%)
-
- Type | Files | Ratio | Lines | Ratio
- -----------------------------------------------------------------
- py | 7 | 100.00% | 349 | 100.00%
-
- Totally cost 0.15700435638427734s.
+$ cocnt config --suffix-add="js,lisp" --comment-add=";" --ignore-add="node_modules"
+'suffix' will be appended with ['js', 'lisp'] . (y/n) y
+'comment' will be appended with [';'] . (y/n) y
+'ignore' will be appended with ['node_modules'] . (y/n) y
```
-#### 指定 `ignore` 并覆盖
-
-可以使用 `[--ignore-save]` 来覆盖默认的 `ignore` 参数。
-
-#### 添加 `ignore` 参数
+#### 删除配置信息
-如果默认的 `ignore` 缺少所需的参数,并且不想重写默认值,可以使用 `[--ignore-add]` 来添加一些新值。
+对于配置变量值的删除,`code-counter` 提供以下标志:
+ + `--suffix-del` 从默认配置中,删除不需要的代码文件后缀
+ + `--comment-del` 从默认配置中,删除不需要的注释符号
+ + `--ignore-del` 从默认配置中,删除不需要忽略的目录或文件名
-### 显示参数配置
+这三个标志可以组合使用,也可以单独使用。对于每个会修改配置文件的操作都会对你进行询问,此时你可以检查要修改的内容是否正确,如果确认修改可以输入 `y`,否则输入 `n` 不执行修改。
-使用占位符 `CONFIG` 来显示 `config.json` 的内容
+对于要输入的多个值可以用逗号分隔,示例如下。
```shell
-$ codecount CONFIG
-```
-
-### 更佳的修改配置的方式
-
-有时候修改配置时并不需要进行搜索和计数,所以可以使用占位符 `CONFIG` 来表示只修改配置,而不进行搜索和技术。使用占位符 `CONFIG` 来设置参数,会在修改完参数后显示更新后的值。
-
-```shell
-$ codecount CONFIG --suffix-save="java,js,html,py" --comment-save="//,#,/**" --ignore-add="__pycache__"
-'ignore' will be appended with ['__pycache__'] (y/n)y
-'suffix' will be replaced with ['java', 'js', 'html', 'py'] (y/n)y
-'comment' will be replaced with ['//', '#', '/**'] (y/n)y
-{
- "suffix": [
- "java",
- "js",
- "html",
- "py"
- ],
- "comment": [
- "//",
- "#",
- "/**"
- ],
- "ignore": [
- "out",
- "venv",
- ".git",
- ".idea",
- "build",
- "target",
- "node_modules",
- ".vscode",
- "dist",
- "__pycache__"
- ]
-}
+$ cocnt config --suffix-del="clj,lisp" --comment-del=";" --ignore-del="build,target"
+'suffix' will remove ['clj', 'lisp'] . (y/n) y
+'comment' will remove [';'] . (y/n) y
+'ignore' will remove ['build', 'target'] . (y/n) y
```
-### 恢复默认配置
+#### 恢复默认配置
-使用 `[--restore]` 来恢复默认配置
+使用 `--restore` 来恢复 `code-counter` 自带的默认配置。
```shell
-$ codecount CONFIG --restore
-Default configuration will be restored (y/n)?y
-{
- "suffix": [
- "c",
- "cc",
- "clj",
- "cpp",
- "cs",
- "cu",
- "cuh",
- "dart",
- "go",
- "h",
- "hpp",
- "java",
- "jl",
- "js",
- "kt",
- "lisp",
- "lua",
- "pde",
- "m",
- "php",
- "py",
- "R",
- "rb",
- "rs",
- "rust",
- "sh",
- "scala",
- "swift",
- "ts",
- "vb"
- ],
- "comment": [
- "#",
- "//",
- "/*",
- "*",
- "*/",
- ":",
- ";",
- "\"\"\"\""
- ],
- "ignore": [
- "out",
- "venv",
- ".git",
- ".idea",
- "build",
- "target",
- "node_modules",
- ".vscode",
- "dist"
- ]
-}
+$ cocnt config --restore
+The default configuration will be restored. (y/n) y
```
## [License](https://github.com/InnoFang/code-counter/blob/master/LICENSE)
- Copyright 2019 Inno Fang
+ Copyright 2019-2022 Inno Fang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.