Skip to content

Commit 58e5807

Browse files
Code cleaned up
1 parent 66b0147 commit 58e5807

File tree

1 file changed

+9
-13
lines changed
  • implement-shell-tools/wc

1 file changed

+9
-13
lines changed

implement-shell-tools/wc/wc.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
file_paths = args.path
1616
lines_flag, words_flag, bytes_flag = args.lines, args.words, args.bytes
1717

18-
def format_output(details_list, totals=None):
18+
def format_output(details_list, totals=None, flags=None):
19+
lines_flag, words_flag, bytes_flag = flags
1920
show_all = not (lines_flag or words_flag or bytes_flag)
2021
output_lines = []
2122

@@ -43,7 +44,7 @@ def format_output(details_list, totals=None):
4344
total_line += f"{totals['line_count']:>3} "
4445

4546
if show_all or words_flag:
46-
total_line += f"{totals['word_count']:>3} "
47+
total_line += f"{totals['word_count']:>3} "
4748

4849
if show_all or bytes_flag:
4950
total_line += f"{totals['file_size']:>3} "
@@ -53,12 +54,13 @@ def format_output(details_list, totals=None):
5354

5455
return "\n".join(output_lines)
5556

57+
58+
# Collect file details
5659
file_details_list = []
5760
line_count_total = 0
5861
word_count_total = 0
5962
file_size_total = 0
6063

61-
# Get file details
6264
for file_path in file_paths:
6365
with open(file_path, "r", encoding="utf-8") as f:
6466
content = f.read()
@@ -69,11 +71,10 @@ def format_output(details_list, totals=None):
6971
"file_size": os.path.getsize(file_path),
7072
"file_path": file_path,
7173
}
72-
# Update totals
74+
7375
line_count_total += details["line_count"]
7476
word_count_total += details["word_count"]
7577
file_size_total += details["file_size"]
76-
total_path = "Total"
7778

7879
file_details_list.append(details)
7980

@@ -83,11 +84,6 @@ def format_output(details_list, totals=None):
8384
"file_size": file_size_total,
8485
}
8586

86-
formatted_output = format_output(file_details_list, totals_details)
87-
print(formatted_output)
88-
89-
90-
91-
# print(args)
92-
93-
# 1 4 20 sample-files/1.txt
87+
# Final output
88+
flags = (lines_flag, words_flag, bytes_flag)
89+
print(format_output(file_details_list, totals_details, flags))

0 commit comments

Comments
 (0)