python tool: added rename feature

This commit is contained in:
quenousimporte 2023-09-14 16:22:49 +02:00
parent 57df8abd1f
commit 6963569a7d
1 changed files with 12 additions and 3 deletions

View File

@ -82,9 +82,12 @@ if len(sys.argv) > 1:
while not (command == "quit" or command == "exit" or command == "q"): while not (command == "quit" or command == "exit" or command == "q"):
delete = False action = None
if command[0:3] == "rm ": if command[0:3] == "rm ":
delete = True action = "delete"
command = command[3:]
elif command[0:3] == "mv ":
action = "rename"
command = command[3:] command = command[3:]
try: try:
@ -93,10 +96,16 @@ while not (command == "quit" or command == "exit" or command == "q"):
except: except:
note = next((note for note in data if note["title"] == command), None) note = next((note for note in data if note["title"] == command), None)
if delete: if action == "delete":
if note and ask("delete '" + note["title"] + "'? "): if note and ask("delete '" + note["title"] + "'? "):
data.remove(note) data.remove(note)
savedata() savedata()
elif action == "rename":
if note:
newname = input("new name: ")
if newname:
note["title"] = newname
savedata()
elif note: elif note:
editnote(note) editnote(note)
else: else: