code Logika CLI untuk CREATE, READ, UPDATE, DELETE
// Ambil argumen dari command line
const command = Bun.argv[2];
const value = Bun.argv[3];
const extra = Bun.argv[4];
// Periksa perintah yang diberikan
if (command === "list" || command === "view") {
await readNotes();
}
else if (command === "delete") {
// ... kode delete yang sudah ada
}
else if (command === "update") {
if (!value || !extra) {
console.log('⚠️ Contoh: bun run index.ts update 2 "isi baru"');
} else {
const num = parseInt(value);
if (isNaN(num)) {
console.log("❌ Nomor harus berupa angka");
} else {
await updateNote(num, extra);
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(` Edit : bun run index.ts update [nomor] "isi baru"`);
console.log(` Hapus : bun run index.ts delete [nomor]`);
}
const command = Bun.argv[2];
const value = Bun.argv[3];
const extra = Bun.argv[4];
// Periksa perintah yang diberikan
if (command === "list" || command === "view") {
await readNotes();
}
else if (command === "delete") {
// ... kode delete yang sudah ada
}
else if (command === "update") {
if (!value || !extra) {
console.log('⚠️ Contoh: bun run index.ts update 2 "isi baru"');
} else {
const num = parseInt(value);
if (isNaN(num)) {
console.log("❌ Nomor harus berupa angka");
} else {
await updateNote(num, extra);
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(` Edit : bun run index.ts update [nomor] "isi baru"`);
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
UPDATE
Mengedit catatan berdasarkan nomor
bun run index.ts update 2 "Isi baru"
DELETE
Menghapus catatan berdasarkan nomor
bun run index.ts delete 1
Bun.argv[2] = command
Bun.argv[3] = value
Bun.argv[4] = extra (untuk UPDATE)
Bun.argv[3] = value
Bun.argv[4] = extra (untuk UPDATE)