code Logika CLI untuk CREATE, READ, DELETE
// Ambil argumen dari command line
const command = Bun.argv[2];
const value = Bun.argv[3];
// Periksa perintah yang diberikan
if (command === "list" || command === "view") {
await readNotes();
}
else if (command === "delete") {
if (!value) {
console.log("⚠️ Contoh: bun run index.ts delete 1");
} else {
const num = parseInt(value);
if (isNaN(num)) {
console.log("❌ Nomor harus berupa angka");
} else {
await deleteNote(num);
await readNotes();
}
}
}
else if (command) {
await addNote(command);
await readNotes();
}
else {
console.log(`📘 DAILY NOTES - CLI`);
console.log(`Perintah:`);
console.log(` Tambah : bun run index.ts "isi catatan"`);
console.log(` Lihat : bun run index.ts list`);
console.log(` Hapus : bun run index.ts delete [nomor]`);
}
const command = Bun.argv[2];
const value = Bun.argv[3];
// Periksa perintah yang diberikan
if (command === "list" || command === "view") {
await readNotes();
}
else if (command === "delete") {
if (!value) {
console.log("⚠️ Contoh: bun run index.ts delete 1");
} else {
const num = parseInt(value);
if (isNaN(num)) {
console.log("❌ Nomor harus berupa angka");
} else {
await deleteNote(num);
await readNotes();
}
}
}
else if (command) {
await addNote(command);
await readNotes();
}
else {
console.log(`📘 DAILY NOTES - CLI`);
console.log(`Perintah:`);
console.log(` Tambah : bun run index.ts "isi catatan"`);
console.log(` Lihat : bun run index.ts list`);
console.log(` Hapus : bun run index.ts delete [nomor]`);
}
CREATE
Menambah catatan baru
bun run index.ts "Catatan baru"
READ
Menampilkan semua catatan
bun run index.ts list
DELETE
Menghapus catatan berdasarkan nomor
bun run index.ts delete 1
Bun.argv[2] = command
Bun.argv[3] = value
Bun.argv[3] = value