From 029ba360c09ae0d842c4c0a145f607b4f16eb546 Mon Sep 17 00:00:00 2001 From: Tacio Medeiros Date: Tue, 23 Jun 2026 14:12:57 -0300 Subject: [PATCH] Add latest command to print the most recent note Adds a store.latest() helper and wires it up to a new "notes latest" CLI command. --- lib/store.js | 7 ++++++- notes.js | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/store.js b/lib/store.js index 661b4b2..bc545c3 100644 --- a/lib/store.js +++ b/lib/store.js @@ -45,4 +45,9 @@ function search(term) { return matches(load().notes, term); } -module.exports = { all, add, remove, search, matches }; +function latest() { + const notes = load().notes; + return notes.length === 0 ? null : notes[notes.length - 1]; +} + +module.exports = { all, add, remove, search, matches, latest }; diff --git a/notes.js b/notes.js index df64a18..cb1510d 100644 --- a/notes.js +++ b/notes.js @@ -39,6 +39,15 @@ function main() { } break; } + case "latest": { + const note = store.latest(); + if (!note) { + console.log("No notes yet. Add one with: notes add "); + return; + } + console.log(`#${note.id} ${note.text}`); + break; + } case "delete": { const id = Number(rest[0]); const ok = store.remove(id); @@ -46,7 +55,7 @@ function main() { break; } default: - console.log("Commands: add | list | search | delete "); + console.log("Commands: add | list | search | latest | delete "); console.log(`(Session locks after ${config.SESSION_TIMEOUT_MINUTES} minutes of inactivity.)`); } }