Skip to content

Commit 835f92f

Browse files
committed
✨ support remove some values of config
1 parent 52b6603 commit 835f92f

File tree

3 files changed

+88
-66
lines changed

3 files changed

+88
-66
lines changed

code_counter/conf/config.json

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
{
22
"suffix": [
3-
"lisp",
4-
"py",
5-
"clj",
6-
"vb",
7-
"hpp",
8-
"ts",
9-
"cc",
10-
"rb",
11-
"dart",
12-
"pde",
13-
"cu",
14-
"sh",
3+
"java",
154
"swift",
16-
"cs",
17-
"js",
18-
"rs",
5+
"dart",
6+
"rb",
7+
"cc",
8+
"go",
199
"php",
20-
"c",
21-
"rust",
10+
"sh",
2211
"lua",
23-
"jl",
24-
"java",
12+
"m",
13+
"cu",
14+
"c",
15+
"vb",
16+
"clj",
17+
"js",
2518
"cuh",
19+
"hpp",
2620
"R",
27-
"go",
21+
"cs",
22+
"kt",
23+
"ts",
2824
"scala",
29-
"m",
25+
"rust",
26+
"py",
3027
"cpp",
28+
"rs",
3129
"h",
32-
"kt"
30+
"jl",
31+
"pde",
32+
"lisp"
3333
],
3434
"comment": [
35-
"*",
35+
"//",
3636
":",
37+
"*",
3738
"*/",
38-
"\"\"\"\"",
3939
";",
40-
"/*",
41-
"//",
42-
"#"
40+
"#",
41+
"\"\"\"\"",
42+
"/*"
4343
],
4444
"ignore": [
45-
".git",
46-
"target",
45+
"venv",
4746
"dist",
47+
"target",
4848
"build",
49-
".vscode",
50-
"node_modules",
51-
"out",
5249
".idea",
53-
"venv"
50+
"node_modules",
51+
".vscode",
52+
".git",
53+
"out"
5454
]
5555
}

code_counter/conf/config.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import json
55
import pkg_resources
66

7+
78
class SetEncoder(json.JSONEncoder):
89
def default(self, obj):
910
if isinstance(obj, set):
1011
return list(obj)
1112
return json.JSONEncoder.default(self, obj)
1213

14+
1315
class Config:
1416

1517
def __init__(self):
@@ -23,10 +25,12 @@ def invoke(self, args):
2325
if args.restore:
2426
self.restore()
2527
else:
26-
if any([args.suffix_add, args.comment_add, args.ignore_add]):
27-
self.__append_config(args.suffix_add, args.comment_add, args.ignore_add)
2828
if any([args.suffix_reset, args.comment_reset, args.ignore_reset]):
2929
self.__reset_config(args.suffix_reset, args.comment_reset, args.ignore_reset)
30+
if any([args.suffix_add, args.comment_add, args.ignore_add]):
31+
self.__append_config(args.suffix_add, args.comment_add, args.ignore_add)
32+
if any([args.suffix_del, args.comment_del, args.ignore_del]):
33+
self.__remove_config(args.suffix_del, args.comment_del, args.ignore_del)
3034
if args.show_list:
3135
self.show()
3236

@@ -37,29 +41,42 @@ def __confirm(self, tips):
3741
check = input(tips)
3842
return check.strip().lower() == 'y'
3943

44+
def __reset_config(self, suffix_reset, comment_reset, ignore_reset):
45+
if suffix_reset:
46+
if self.__confirm("'suffix' will be replaced with {} . (y/n) ".format(suffix_reset)):
47+
self.suffix = set(suffix_reset)
48+
if comment_reset:
49+
if self.__confirm("'comment' will be replaced with {} . (y/n) ".format(comment_reset)):
50+
self.comment = set(comment_reset)
51+
if ignore_reset:
52+
if self.__confirm("'ignore' will be replaced with {} . (y/n) ".format(ignore_reset)):
53+
self.ignore = set(ignore_reset)
54+
55+
self.__update()
56+
4057
def __append_config(self, suffix_add, comment_add, ignore_add):
4158
if suffix_add:
42-
if self.__confirm("'suffix' will be appended with {} (y/n)".format(suffix_add)):
59+
if self.__confirm("'suffix' will be appended with {} . (y/n) ".format(suffix_add)):
4360
self.suffix.update(suffix_add)
4461
if comment_add:
45-
if self.__confirm("'comment' will be appended with {} (y/n)".format(comment_add)):
62+
if self.__confirm("'comment' will be appended with {} . (y/n) ".format(comment_add)):
4663
self.comment.update(comment_add)
4764
if ignore_add:
48-
if self.__confirm("'ignore' will be appended with {} (y/n)".format(ignore_add)):
65+
if self.__confirm("'ignore' will be appended with {} . (y/n) ".format(ignore_add)):
4966
self.ignore.update(ignore_add)
5067

5168
self.__update()
5269

53-
def __reset_config(self, suffix_reset, comment_reset, ignore_reset):
54-
if suffix_reset:
55-
if self.__confirm("'suffix' will be replaced with {} (y/n)".format(suffix_reset)):
56-
self.suffix = set(suffix_reset)
57-
if comment_reset:
58-
if self.__confirm("'comment' will be replaced with {} (y/n)".format(comment_reset)):
59-
self.comment = set(comment_reset)
60-
if ignore_reset:
61-
if self.__confirm("'ignore' will be replaced with {} (y/n)".format(ignore_reset)):
62-
self.ignore = set(ignore_reset)
70+
def __remove_config(self, suffix_del, comment_del, ignore_del):
71+
if suffix_del:
72+
if self.__confirm("'suffix' will remove {} . (y/n) ".format(suffix_del)):
73+
self.suffix.difference_update(suffix_del)
74+
if comment_del:
75+
if self.__confirm("'comment' will remove {} . (y/n) ".format(comment_del)):
76+
self.comment.difference_update(comment_del)
77+
if ignore_del:
78+
if self.__confirm("'ignore' will remove {} . (y/n) ".format(ignore_del)):
79+
self.ignore.difference_update(ignore_del)
6380

6481
self.__update()
6582

@@ -81,5 +98,5 @@ def restore(self):
8198
self.comment = {"#", "//", "/*", "*", "*/", ":", ";", '""""'}
8299
self.ignore = {"out", "venv", ".git", ".idea", "build", "target", "node_modules", ".vscode", "dist"}
83100

84-
if self.__confirm('The default configuration will be restored (y/n)?'):
101+
if self.__confirm('The default configuration will be restored. (y/n) '):
85102
self.__update()

code_counter/core/args.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,19 @@ def __search(self):
6161
usage="cocnt search input_path [-h] [-v] [-g] "
6262
"[-o OUTPUT_PATH] [--suffix SUFFIX] [--comment COMMENT] [--ignore IGNORE]")
6363
parser.add_argument('input_path', type=split_args,
64-
help="counting the code lines according the given path(s)")
64+
help="counting the code lines according to the given path(s)")
6565
parser.add_argument('-v', '--verbose', dest="verbose", action='store_true',
66-
help="show verbose infomation")
66+
help="show verbose information")
6767
parser.add_argument('-g', '--graph', dest='graph', action='store_true',
6868
help="choose to whether to visualize the result")
6969
parser.add_argument('-o', '--output', dest='output_path',
70-
help="specify a output path if you want to store the result")
70+
help="specify an output path if you want to store the result")
7171
parser.add_argument('--suffix', dest='suffix', type=split_args,
72-
help="what code files do you want to count, this parameter is disposable")
72+
help="what code files do you want to count")
7373
parser.add_argument('--comment', dest='comment', type=split_args,
74-
help="the comment symbol, which can be judged whether the current line is a comment, "
75-
"this parameter is disposable")
74+
help="the comment symbol, which can be judged whether the current line is a comment")
7675
parser.add_argument('--ignore', dest='ignore', type=split_args,
77-
help="ignore some directories or files that you don't want to count, "
78-
"this parameter is disposable")
76+
help="ignore some directories or files that you don't want to count")
7977
return parser.parse_args(sys.argv[2:])
8078

8179
def __config(self):
@@ -87,24 +85,31 @@ def __config(self):
8785
"[--comment-add COMMENT_ADD] [--ignore-reset IGNORE_RESET] "
8886
"[--ignore-add IGNORE_ADD] [--restore] ")
8987
parser.add_argument('--list', dest='show_list', action='store_true',
90-
help="list all variables set in config file, along with their values")
88+
help="list all variables set in the config file, along with their values")
9189
parser.add_argument('--suffix-reset', dest='suffix_reset', type=split_args,
92-
help="override 'suffix' in config and count codes according to this value")
90+
help="reset the 'suffix' in the config and count code lines according to this value")
9391
parser.add_argument('--suffix-add', dest='suffix_add', type=split_args,
94-
help="append new value for 'suffix' in config and count codes according to this value")
92+
help="append new value for the 'suffix' in the config "
93+
"and count code lines according to this value")
94+
parser.add_argument('--suffix-del', dest='suffix_del', type=split_args,
95+
help="delete some values of the 'suffix' in the config")
9596

9697
parser.add_argument('--comment-reset', dest='comment_reset', type=split_args,
97-
help="override 'comment' in config and count comment lines according to this value")
98+
help="reset the 'comment' in the config and count comment lines according to this value")
9899
parser.add_argument('--comment-add', dest='comment_add', type=split_args,
99-
help="append new value for 'comment' in config "
100+
help="append new value for the 'comment' in the config "
100101
"and count comment lines according to this value")
102+
parser.add_argument('--comment-del', dest='comment_del', type=split_args,
103+
help="delete some values of the 'comment' in the config")
101104

102105
parser.add_argument('--ignore-reset', dest='ignore_reset', type=split_args,
103-
help="override 'ignore' in config "
104-
"and ignore some files or directory according to this value")
106+
help="reset the 'ignore' in the config "
107+
"and ignore some files or directories according to this value")
105108
parser.add_argument('--ignore-add', dest='ignore_add', type=split_args,
106-
help="append new value for 'ignore' in config "
107-
"and ignore some files or directory according to this value")
109+
help="append new value for the 'ignore' in the config "
110+
"and ignore some files or directories according to this value")
111+
parser.add_argument('--ignore-del', dest='ignore_del', type=split_args,
112+
help="delete some values of the 'ignore' in the config")
108113

109114
parser.add_argument('--restore', dest='restore', action='store_true',
110115
help="restore default config")

0 commit comments

Comments
 (0)