Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local opt = table.remove(args, 1)
- local notes = {}
- local path = shell.resolve '.notes-data'
- local function loadNotes()
- local file = fs.open(path, 'r')
- if file then
- for line in file.readLine do
- table.insert(notes, line)
- end
- file.close()
- end
- end
- local function saveNotes()
- local file = fs.open(path, 'w')
- assert(file, 'Notes path is read-only')
- for i=1, #notes do
- file.writeLine(notes[i])
- end
- file.close()
- end
- if opt == 'add' then
- loadNotes()
- local newNote = table.concat(args, ' ')
- table.insert(notes, newNote)
- saveNotes()
- print('Added "'..newNote..'"')
- elseif opt == 'remove'
- or opt == 'delete' then
- loadNotes()
- local noteID = tonumber(args[1])
- assert(noteID, 'invalid note ID')
- local removed = table.remove(notes, noteID)
- saveNotes()
- print('Removed note '..noteID..': "'..removed..'"')
- elseif opt == 'list' then
- loadNotes()
- for i=1, #notes do
- local space = string.rep(' ', 4 - #tostring(i))
- print(i..space..notes[i])
- end
- else
- print [[
- Usage:
- notes add <note>
- notes remove <note #>
- notes delete <note #>
- notes list
- ]]
- end
Advertisement
Add Comment
Please, Sign In to add comment