Skip to content

Commit ab27b8e

Browse files
authored
Merge pull request #4 from InnoFang/dev
❇️ 🎨 🐛 search support more than one path that separate by comma, and optimize some code format
2 parents 97cd1cf + 3cf52de commit ab27b8e

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

code_counter/conf/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def invoke(self, args):
2222
self.__append_config(args.suffix_add, args.comment_add, args.ignore_add)
2323
if any([args.suffix_reset, args.comment_reset, args.ignore_reset]):
2424
self.__reset_config(args.suffix_reset, args.comment_reset, args.ignore_reset)
25-
if args.list:
25+
if args.show_list:
2626
self.show()
2727

2828
def show(self):

code_counter/core/argspaser.py

Lines changed: 12 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

@@ -26,24 +26,25 @@ def __init__(self):
2626
if not hasattr(self, args.command):
2727
print("Unrecognized command")
2828
parser.print_help()
29+
exit(1)
2930
self.args = {args.command: getattr(self, args.command)()}
3031

3132
def search(self):
3233
parser = argparse.ArgumentParser(
3334
description="Search code in the given path(s)")
34-
parser.add_argument('path',
35+
parser.add_argument('input_path', type=split_args,
3536
help="specify a file or directory path you want to count or use CONFIG placeholder to configure")
3637
parser.add_argument('-v', '--verbose', dest="verbose", action='store_true',
3738
help="show verbose infomation")
3839
parser.add_argument('-g', '--graph', dest='graph', action='store_true',
3940
help="choose to whether to visualize the result")
4041
parser.add_argument('-o', '--output', dest='output_path',
4142
help="specify a output path if you want to store the result")
42-
parser.add_argument('--suffix', dest='suffix', type=config_args_type,
43+
parser.add_argument('--suffix', dest='suffix', type=split_args,
4344
help="what code files do you want to count, this parameter is disposable")
44-
parser.add_argument('--comment', dest='comment', type=config_args_type,
45+
parser.add_argument('--comment', dest='comment', type=split_args,
4546
help="the comment symbol, which can be judged whether the current line is a comment, this parameter is disposable")
46-
parser.add_argument('--ignore', dest='ignore', type=config_args_type,
47+
parser.add_argument('--ignore', dest='ignore', type=split_args,
4748
help="ignore some directories or files that you don't want to count, this parameter is disposable")
4849
return parser.parse_args(sys.argv[2:])
4950

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

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

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

7071
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)