-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommaddFactory.py
More file actions
56 lines (47 loc) · 2.34 KB
/
commaddFactory.py
File metadata and controls
56 lines (47 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from commandQueue import CommandQueue
import command
from notes_manager import NoteManager
class CommaddFactory():
def __init__(self, commandQueue:CommandQueue, noteManager:NoteManager) -> None:
self._commandQueue =commandQueue
self._noteManager = noteManager
def concrete_command(self, user_request:list)->command.Command | None:
if user_request[0] == "create":
try:
title_index = user_request.index("-t")
content_index = user_request.index("-c")
return command.CreateNoteCommand(" ".join(user_request[title_index+1:content_index]), " ".join(user_request[content_index+1:]),self._noteManager)
except ValueError:
print("ERROR Please use the following format\ncreate -t <title> -c <content>")
elif user_request[0] == "delete":
if "-id" in user_request:
identifier = user_request.index("-id")+1
return command.DeleteNoteCommand(identifier ,self._noteManager)
elif "-t" in user_request:
identifier = " ".join(user_request[user_request.index("-t")+1:])
return command.DeleteNoteCommand(identifier ,self._noteManager)
else:
print("ERROR Please use the following format\ndelete -t <title> \nor \ndelete -c <content>")
elif user_request[0] == "view":
if "-id" in user_request:
identifier = user_request[user_request.index("-id")+1]
return command.ViewNoteCommand(int(identifier) ,self._noteManager)
elif "-t" in user_request:
identifier = " ".join(user_request[user_request.index("-t")+1:])
return command.ViewNoteCommand(identifier ,self._noteManager)
else:
print("ERROR Please use the following format\nview -t <title> \nor \ndelete -c <content>")
elif user_request[0] == "undo":
return command.UndoLestCommand(self._commandQueue)
else:
print("""Please use the following formats
create -t <title> -c <content>
delete
-t <title>
-c <content>
view
-t <title>
-c <content>
undo
""")
return None