diff --git a/SPEC.txt b/SPEC.txt new file mode 100644 index 0000000..c98c0f4 --- /dev/null +++ b/SPEC.txt @@ -0,0 +1,44 @@ +PROJECT: mini-todo +AUTHOR: Rashid Buzurtanov 92414781214 +VERSION: v1 +DATE: 2026-05-22 + +=== 1. Overview === +This is a command-line interface (CLI) task management application (mini-todo). +In version V1, the focus is to transition all user-facing outputs and error messages into Turkish, and enforce strict argument checks. + +=== 2. Commands and Behavior === + +The application is executed via: `python solution_v1.py [arguments]` + +* init + - Description: Initializes the storage directory. + - Behavior: Creates a hidden directory named `.minitodo` and an empty `tasks.dat` file inside it. + - Output (Success): "Bos minitodo sistemi '.minitodo/' altinda basariyla olusturuldu." + - Output (Error): If `.minitodo` already exists, prints: + "Hata: Sistem zaten baslatilmis!" + +* add + - Description: Adds a new task to the system. + - Behavior: Appends the task with an auto-incremented ID, status (PENDING), and date to `tasks.dat`. + - Output (Success): "Gorev # eklendi: " + - Output (Error - Missing Argument): If no description is provided, prints: + "Kullanim Hasi: Lutfen gorev aciklamasi yazin. Ornek: add 'Sut al'" + +* list / done / delete + - Description: These commands are placeholders for V1 and are not fully implemented yet. + - Output: "Komut '' gelecek haftalarda yuklenecektir." + +=== 3. Global Error Handling === + +* System Not Initialized: + - If any command (except init) is run before initialization, prints: + "Hata: Sistem henuz baslatilmamis. Once 'init' calistirin." + +* Unknown Command: + - If an invalid command is entered, prints: + "Hata: Bilinmeyen komut -> " + +=== 4. V1 Constraints === +- No loops (`for` or `while`) are allowed in the source code. +- No lists (`[]`) or dynamic structures can be used; arguments must be accessed via direct indices of `sys.argv`. \ No newline at end of file diff --git a/solution_v1.py b/solution_v1.py new file mode 100644 index 0000000..d455d27 --- /dev/null +++ b/solution_v1.py @@ -0,0 +1,58 @@ +import sys +import os + +# ============================================================================== +# V1 GÖREV LİSTESİ (V1 TASK LIST) +# 1. Hata mesajlarının tamamı kullanıcı dostu ve Türkçe hale getirilecek. +# 2. 'add' komutunda argüman eksikliği kontrolü sıkılaştırılacak ve Türkçe kılavuz basılacak. +# 3. 'init' komutunda halihazırda dizin varsa dönen hata mesajı netleştirilecek. +# ============================================================================== + +def initialize(): + if os.path.exists(".minitodo"): + return "Hata: Sistem zaten baslatilmis!" + + os.mkdir(".minitodo") + f = open(".minitodo/tasks.dat", "w") + f.close() + return "Bos minitodo sistemi '.minitodo/' altinda basariyla olusturuldu." + +def add_task(description): + if not os.path.exists(".minitodo"): + return "Hata: Sistem henuz baslatilmamis. Once 'init' calistirin." + + f = open(".minitodo/tasks.dat", "r") + content = f.read() + f.close() + + task_id = content.count("\n") + 1 + + f = open(".minitodo/tasks.dat", "a") + f.write(str(task_id) + "|" + description + "|PENDING|2026-05-22\n") + f.close() + + return "Gorev #" + str(task_id) + " eklendi: " + description + +def show_not_implemented(command_name): + return "Komut '" + command_name + "' gelecek haftalarda yuklenecektir." + +# --- Ana Program --- +if len(sys.argv) < 2: + print("Kullanim: python solution_v1.py [argumanlar]") +else: + command = sys.argv[1] + + if command == "init": + print(initialize()) + + elif command == "add": + if len(sys.argv) < 3: + print("Kullanim Hasi: Lutfen gorev aciklamasi yazin. Ornek: add 'Sut al'") + else: + print(add_task(sys.argv[2])) + + elif command == "list" or command == "done" or command == "delete": + print(show_not_implemented(command)) + + else: + print("Hata: Bilinmeyen komut -> " + command) \ No newline at end of file diff --git a/test_spec.py b/test_spec.py new file mode 100644 index 0000000..adddac2 --- /dev/null +++ b/test_spec.py @@ -0,0 +1,43 @@ +import subprocess +import os +import shutil + +# --- Yardimci Fonksiyon --- +def run_cmd(args): + result = subprocess.run( + ["python", "solution_v1.py"] + args, + capture_output=True, + text=True + ) + return result.stdout.strip() + +# --- Setup ve Temizlik --- +def setup_function(): + if os.path.exists(".minitodo"): + shutil.rmtree(".minitodo") + +# --- V1 Testleri --- + +# 1. 'init' komutunun dizin olusturma testi +def test_init_creates_directory(): + output = run_cmd(["init"]) + assert os.path.exists(".minitodo") + assert "basariyla olusturuldu" in output + +# 2. 'init' komutunun tekrar calistirilma hata testi +def test_init_already_exists(): + run_cmd(["init"]) + output = run_cmd(["init"]) + assert "Sistem zaten baslatilmis" in output + +# 3. 'add' komutu ile tek bir gorev ekleme testi +def test_add_single_task(): + run_cmd(["init"]) + output = run_cmd(["add", "Sut al"]) + assert "Gorev #1 eklendi" in output + +# 4. 'add' komutunda eksik arguman hata testi +def test_missing_arguments_add(): + run_cmd(["init"]) + output = run_cmd(["add"]) + assert "Kullanim Hasi" in output \ No newline at end of file