readr-cli 1.0.2 → 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/README.md +7 -7
- package/dist/index.js +58 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,13 +11,13 @@ npm install -g readr-cli
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
readr add # Add a new book
|
|
15
|
+
readr start # Start a reading session
|
|
16
|
+
readr pause # Pause or resume current session
|
|
17
|
+
readr stop # End session & log pages read
|
|
18
|
+
readr list # All books with progress & ETA
|
|
19
|
+
readr stats # Overall reading statistics
|
|
20
|
+
readr help # Show help
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Features
|
package/dist/index.js
CHANGED
|
@@ -173,17 +173,65 @@ 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
|
-
['
|
|
181
|
-
['
|
|
182
|
-
['
|
|
183
|
-
['
|
|
184
|
-
['
|
|
185
|
-
['
|
|
186
|
-
['
|
|
227
|
+
['readr add', 'Add a new book'],
|
|
228
|
+
['readr edit', 'Edit a book\'s details'],
|
|
229
|
+
['readr start', 'Start a reading session'],
|
|
230
|
+
['readr pause', 'Pause or resume current session'],
|
|
231
|
+
['readr stop', 'End session & log pages read'],
|
|
232
|
+
['readr list', 'List all books with progress'],
|
|
233
|
+
['readr stats', 'Overall reading statistics'],
|
|
234
|
+
['readr help', 'Show this help'],
|
|
187
235
|
];
|
|
188
236
|
for (const [cmd, desc] of cmds) {
|
|
189
237
|
console.log(` ${chalk.bold.green(cmd.padEnd(14))} ${chalk.gray(desc)}`);
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "readr-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Beautiful CLI to track reading sessions, speed, and book completion ETA",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"
|
|
7
|
+
"readr": "./dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "tsx src/index.ts",
|