Skip to content

feat: implement CLI tool to create directories and files with timestamps#1748

Open
RustamHadoiev24 wants to merge 1 commit intomate-academy:masterfrom
RustamHadoiev24:develop
Open

feat: implement CLI tool to create directories and files with timestamps#1748
RustamHadoiev24 wants to merge 1 commit intomate-academy:masterfrom
RustamHadoiev24:develop

Conversation

@RustamHadoiev24
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Your implementation correctly fulfills all functional requirements: the -d and -f flags work as expected, directory creation with os.makedirs, timestamp formatting with .strftime(), line numbering, and cross-platform compatibility with os.path.join are all properly implemented. The code handles combined flags, appends to existing files with proper blank-line separation, and uses sys.argv as required. The DRY principle violation noted in the checklist is a code quality concern rather than a functional blocker. While organizing the code into separate functions like parse_arguments(), create_directories(), collect_content(), and write_file() would improve maintainability and testability, your implementation is functionally complete and works correctly. Since the core requirements and all specified features work properly, this is approved.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment thread app/create_file.py
Comment on lines +1 to +44
import os
import sys
from datetime import datetime

args = sys.argv[1:]
dir_path = []
file_name = None

if "-d" in args:
d_idx = args.index("-d")
for i in range(d_idx + 1, len(args)):
if args[i] == "-f":
break
dir_path.append(args[i])

if "-f" in args:
f_idx = args.index("-f")
if f_idx + 1 < len(args):
file_name = args[f_idx + 1]

full_path = os.path.join(*dir_path) if dir_path else ""
if full_path:
os.makedirs(full_path, exist_ok=True)

if file_name:
content_lines = []
while True:
line = input("Enter content line: ")
if line.lower() == "stop":
break
content_lines.append(line)

file_path = os.path.join(full_path, file_name)
file_exists = os.path.exists(file_path)

with open(file_path, "a") as f:
if file_exists:
f.write("\n")

timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
f.write(f"{timestamp}\n")

for index, line in enumerate(content_lines, start=1):
f.write(f"{index} {line}\n")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates the DRY principle checklist item. Create separate functions (e.g., parse_arguments(), create_directories(), collect_content(), write_file()) to organize the code logically instead of having all code at module level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants