Skip to content

Commit 3cf52de

Browse files
committed
✨ cocnt search support more than one path that separate by comma
1 parent 2360701 commit 3cf52de

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

code_counter/core/argspaser.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from code_counter import __version__
77

88

9-
def config_args_type(args):
9+
def split_args(args):
1010
return list(args.split(','))
1111

1212

@@ -32,19 +32,19 @@ def __init__(self):
3232
def search(self):
3333
parser = argparse.ArgumentParser(
3434
description="Search code in the given path(s)")
35-
parser.add_argument('path',
35+
parser.add_argument('input_path', type=split_args,
3636
help="specify a file or directory path you want to count or use CONFIG placeholder to configure")
3737
parser.add_argument('-v', '--verbose', dest="verbose", action='store_true',
3838
help="show verbose infomation")
3939
parser.add_argument('-g', '--graph', dest='graph', action='store_true',
4040
help="choose to whether to visualize the result")
4141
parser.add_argument('-o', '--output', dest='output_path',
4242
help="specify a output path if you want to store the result")
43-
parser.add_argument('--suffix', dest='suffix', type=config_args_type,
43+
parser.add_argument('--suffix', dest='suffix', type=split_args,
4444
help="what code files do you want to count, this parameter is disposable")
45-
parser.add_argument('--comment', dest='comment', type=config_args_type,
45+
parser.add_argument('--comment', dest='comment', type=split_args,
4646
help="the comment symbol, which can be judged whether the current line is a comment, this parameter is disposable")
47-
parser.add_argument('--ignore', dest='ignore', type=config_args_type,
47+
parser.add_argument('--ignore', dest='ignore', type=split_args,
4848
help="ignore some directories or files that you don't want to count, this parameter is disposable")
4949
return parser.parse_args(sys.argv[2:])
5050

@@ -53,19 +53,19 @@ def config(self):
5353
description="A command-line interface (CLI) utility that can help you easily count code and display detailed results.")
5454
parser.add_argument('--list', dest='show_list', action='store_true',
5555
help="list all variables set in config file, along with their values")
56-
parser.add_argument('--suffix-reset', dest='suffix_reset', type=config_args_type,
56+
parser.add_argument('--suffix-reset', dest='suffix_reset', type=split_args,
5757
help="override 'suffix' in config and count codes according to this value")
58-
parser.add_argument('--suffix-add', dest='suffix_add', type=config_args_type,
58+
parser.add_argument('--suffix-add', dest='suffix_add', type=split_args,
5959
help="append new value for 'suffix' in config and count codes according to this value")
6060

61-
parser.add_argument('--comment-reset', dest='comment_reset', type=config_args_type,
61+
parser.add_argument('--comment-reset', dest='comment_reset', type=split_args,
6262
help="override 'comment' in config and count comment lines according to this value")
63-
parser.add_argument('--comment-add', dest='comment_add', type=config_args_type,
63+
parser.add_argument('--comment-add', dest='comment_add', type=split_args,
6464
help="append new value for 'comment' in config and count comment lines according to this value")
6565

66-
parser.add_argument('--ignore-reset', dest='ignore_reset', type=config_args_type,
66+
parser.add_argument('--ignore-reset', dest='ignore_reset', type=split_args,
6767
help="override 'ignore' in config and ignore some files or directory according to this value")
68-
parser.add_argument('--ignore-add', dest='ignore_add', type=config_args_type,
68+
parser.add_argument('--ignore-add', dest='ignore_add', type=split_args,
6969
help="append new value for 'ignore' in config and ignore some files or directory according to this value")
7070

7171
parser.add_argument('--restore', dest='restore', action='store_true',

code_counter/core/codecounter.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def search(self):
4747
if not self.search_args:
4848
raise Exception('search_args is None, please invoke setSearchArgs first.')
4949

50-
input_path = self.search_args.path
50+
input_path = self.search_args.input_path
5151
output_path = self.search_args.output_path
5252

5353
output_file = open(output_path, 'w') if output_path else None
@@ -69,12 +69,16 @@ def search(self):
6969
# else:
7070
# print('{} is not a validate path.'.format(l))
7171

72-
if os.path.isdir(input_path) or os.path.isfile(input_path):
73-
self.__search(input_path, output_file)
74-
else:
72+
if not input_path:
7573
print('{} is not a validate path.'.format(input_path))
7674
return
7775

76+
for path in input_path:
77+
if os.path.exists(path):
78+
self.__search(path, output_file)
79+
else:
80+
print('{} is not a validate path.'.format(path))
81+
7882
print('\n\t{}'.format("RESULT"), file=output_file)
7983
print("\t{}".format('=' * 20), file=output_file)
8084
print("\t{:<20}:{:>8} ({:>7})"

0 commit comments

Comments
 (0)