- CLI tool for managing Bring! shopping lists - Environment variable-based configuration - Commands: add, list, remove, recent - Complete English documentation - Security: credentials via env vars, not hardcoded Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
140 lines
3.6 KiB
JavaScript
Executable File
140 lines
3.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const bringApi = require('bring-shopping');
|
|
|
|
// Load credentials from environment variables
|
|
const CREDENTIALS = {
|
|
mail: process.env.BRING_EMAIL,
|
|
password: process.env.BRING_PASSWORD
|
|
};
|
|
|
|
const LIST_UUID = process.env.BRING_LIST_UUID;
|
|
|
|
// Validate required environment variables
|
|
if (!CREDENTIALS.mail || !CREDENTIALS.password || !LIST_UUID) {
|
|
console.error('Error: Missing required environment variables');
|
|
console.error('Please set: BRING_EMAIL, BRING_PASSWORD, BRING_LIST_UUID');
|
|
console.error('See SKILL.md for setup instructions');
|
|
process.exit(1);
|
|
}
|
|
|
|
async function main() {
|
|
const args = process.argv.slice(2);
|
|
const command = args[0];
|
|
|
|
if (!command) {
|
|
console.error('Usage: bring <add|list|remove|recent> [args...]');
|
|
process.exit(1);
|
|
}
|
|
|
|
const bring = new bringApi(CREDENTIALS);
|
|
|
|
try {
|
|
await bring.login();
|
|
|
|
switch (command) {
|
|
case 'add':
|
|
await addItem(bring, args.slice(1));
|
|
break;
|
|
case 'list':
|
|
await listItems(bring);
|
|
break;
|
|
case 'remove':
|
|
await removeItem(bring, args.slice(1));
|
|
break;
|
|
case 'recent':
|
|
await recentItems(bring);
|
|
break;
|
|
default:
|
|
console.error(`Unknown command: ${command}`);
|
|
console.error('Available commands: add, list, remove, recent');
|
|
process.exit(1);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add an item to the shopping list
|
|
*/
|
|
async function addItem(bring, args) {
|
|
const itemName = args[0];
|
|
const specification = args.slice(1).join(' ') || '';
|
|
|
|
if (!itemName) {
|
|
console.error('Usage: bring add <item> [specification]');
|
|
process.exit(1);
|
|
}
|
|
|
|
await bring.saveItem(LIST_UUID, itemName, specification);
|
|
|
|
if (specification) {
|
|
console.log(`✓ "${itemName}" (${specification}) added to shopping list`);
|
|
} else {
|
|
console.log(`✓ "${itemName}" added to shopping list`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* List all items currently on the shopping list
|
|
*/
|
|
async function listItems(bring) {
|
|
const items = await bring.getItems(LIST_UUID);
|
|
|
|
if (items.purchase.length === 0) {
|
|
console.log('Shopping list is empty');
|
|
return;
|
|
}
|
|
|
|
console.log('Shopping list:');
|
|
console.log('');
|
|
items.purchase.forEach((item, index) => {
|
|
if (item.specification) {
|
|
console.log(`${index + 1}. ${item.name} (${item.specification})`);
|
|
} else {
|
|
console.log(`${index + 1}. ${item.name}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Remove an item from the shopping list (mark as purchased)
|
|
*/
|
|
async function removeItem(bring, args) {
|
|
const itemName = args.join(' ');
|
|
|
|
if (!itemName) {
|
|
console.error('Usage: bring remove <item>');
|
|
process.exit(1);
|
|
}
|
|
|
|
await bring.removeItem(LIST_UUID, itemName);
|
|
console.log(`✓ "${itemName}" removed from shopping list`);
|
|
}
|
|
|
|
/**
|
|
* Show recently purchased items
|
|
*/
|
|
async function recentItems(bring) {
|
|
const items = await bring.getItems(LIST_UUID);
|
|
|
|
if (items.recently.length === 0) {
|
|
console.log('No recently purchased items');
|
|
return;
|
|
}
|
|
|
|
console.log('Recently purchased:');
|
|
console.log('');
|
|
items.recently.slice(0, 10).forEach((item, index) => {
|
|
if (item.specification) {
|
|
console.log(`${index + 1}. ${item.name} (${item.specification})`);
|
|
} else {
|
|
console.log(`${index + 1}. ${item.name}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
main();
|