feat(cli): add support for repeated directus tasks
This commit is contained in:
parent
8a12e83b13
commit
1f9e2d856f
11 changed files with 601 additions and 5 deletions
43
cli/lib/tasks/updateReadingProgress.js
Normal file
43
cli/lib/tasks/updateReadingProgress.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
import inquirer from 'inquirer';
|
||||
import { loadConfig } from '../config.js';
|
||||
import { initDirectusClient, searchItems, updateItem } from '../directus/client.js';
|
||||
|
||||
export const updateReadingProgress = async () => {
|
||||
const config = await loadConfig();
|
||||
|
||||
initDirectusClient(config);
|
||||
|
||||
const readingBooks = await searchItems('books', '', { read_status: 'started' });
|
||||
|
||||
if (!readingBooks.length) {
|
||||
console.log('📖 No books currently marked as "started".');
|
||||
return;
|
||||
}
|
||||
|
||||
const { bookId } = await inquirer.prompt({
|
||||
type: 'list',
|
||||
name: 'bookId',
|
||||
message: '📚 Select a book to update progress:',
|
||||
choices: readingBooks.map(book => {
|
||||
const title = book.title || book.name || `Book #${book.id}`;
|
||||
const progress = book.progress ?? 0;
|
||||
|
||||
return {
|
||||
name: `${title} (${progress}%)`,
|
||||
value: book.id
|
||||
};
|
||||
})
|
||||
});
|
||||
const { progress } = await inquirer.prompt({
|
||||
name: 'progress',
|
||||
message: '📕 New progress percentage (0–100):',
|
||||
validate: input => {
|
||||
const num = Number(input);
|
||||
return !isNaN(num) && num >= 0 && num <= 100 || 'Enter a number from 0 to 100';
|
||||
}
|
||||
});
|
||||
|
||||
await updateItem('books', bookId, { progress: Number(progress) });
|
||||
|
||||
console.log(`✅ Updated book progress to ${progress}%`);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue