readr-cli 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +51 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -173,11 +173,59 @@ function showStats() {
|
|
|
173
173
|
console.log('');
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
+
async function editBook() {
|
|
177
|
+
const store = loadStore();
|
|
178
|
+
if (store.books.length === 0) {
|
|
179
|
+
console.log(chalk.gray('\n No books yet. Add one with: readr add\n'));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
header();
|
|
183
|
+
console.log(chalk.bold(' Your books:\n'));
|
|
184
|
+
store.books.forEach((b, i) => {
|
|
185
|
+
console.log(` ${chalk.bold.cyan(i + 1 + '.')} ${b.title} ${chalk.gray(`— page ${b.currentPage}/${b.totalPages}`)}`);
|
|
186
|
+
});
|
|
187
|
+
const choiceStr = await prompt(chalk.cyan('\n Pick a book to edit (number): '));
|
|
188
|
+
const choice = parseInt(choiceStr) - 1;
|
|
189
|
+
const book = store.books[choice];
|
|
190
|
+
if (!book) {
|
|
191
|
+
console.log(chalk.red(' ✗ Invalid choice.'));
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
console.log(chalk.gray('\n Press Enter to keep the current value.\n'));
|
|
195
|
+
const title = await prompt(chalk.cyan(` Title (${book.title}): `));
|
|
196
|
+
const author = await prompt(chalk.cyan(` Author (${book.author}): `));
|
|
197
|
+
const totalPagesStr = await prompt(chalk.cyan(` Total pages (${book.totalPages}): `));
|
|
198
|
+
const currentPageStr = await prompt(chalk.cyan(` Current page (${book.currentPage}): `));
|
|
199
|
+
const totalPages = totalPagesStr ? parseInt(totalPagesStr) : book.totalPages;
|
|
200
|
+
const currentPage = currentPageStr ? parseInt(currentPageStr) : book.currentPage;
|
|
201
|
+
if (isNaN(totalPages) || isNaN(currentPage)) {
|
|
202
|
+
console.log(chalk.red(' ✗ Invalid page number.'));
|
|
203
|
+
process.exit(1);
|
|
204
|
+
}
|
|
205
|
+
if (currentPage > totalPages) {
|
|
206
|
+
console.log(chalk.red(' ✗ Current page cannot exceed total pages.'));
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
book.title = title || book.title;
|
|
210
|
+
book.author = author || book.author;
|
|
211
|
+
book.totalPages = totalPages;
|
|
212
|
+
book.currentPage = currentPage;
|
|
213
|
+
if (currentPage >= totalPages && !book.finishedAt) {
|
|
214
|
+
book.finishedAt = new Date().toISOString();
|
|
215
|
+
}
|
|
216
|
+
else if (currentPage < totalPages) {
|
|
217
|
+
delete book.finishedAt;
|
|
218
|
+
}
|
|
219
|
+
saveStore(store);
|
|
220
|
+
console.log(chalk.green(`\n ✓ Updated "${book.title}"!`));
|
|
221
|
+
printBookCard(book, store.sessions);
|
|
222
|
+
}
|
|
176
223
|
function showHelp() {
|
|
177
224
|
header();
|
|
178
225
|
console.log(chalk.bold(' Commands:\n'));
|
|
179
226
|
const cmds = [
|
|
180
227
|
['readr add', 'Add a new book'],
|
|
228
|
+
['readr edit', 'Edit a book\'s details'],
|
|
181
229
|
['readr start', 'Start a reading session'],
|
|
182
230
|
['readr pause', 'Pause or resume current session'],
|
|
183
231
|
['readr stop', 'End session & log pages read'],
|
|
@@ -195,6 +243,9 @@ function showHelp() {
|
|
|
195
243
|
case 'add':
|
|
196
244
|
await addBook();
|
|
197
245
|
break;
|
|
246
|
+
case 'edit':
|
|
247
|
+
await editBook();
|
|
248
|
+
break;
|
|
198
249
|
case 'start':
|
|
199
250
|
await startSession();
|
|
200
251
|
break;
|