27 lines
662 B
JavaScript
27 lines
662 B
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Detect "todo [task]" pattern in text
|
|
* Usage: node detect-todo.js "I need to todo [Setup CI/CD]"
|
|
* Output: Setup CI/CD (or empty if no match)
|
|
*/
|
|
|
|
const text = process.argv[2] || '';
|
|
|
|
// Match: "todo [text]" or "todo: text" or "todo text"
|
|
const patterns = [
|
|
/\btodo\s*\[\s*([^\]]+)\s*\]/i, // todo [text]
|
|
/\btodo:\s*([^\n]+?)(?:\s*$|\s*[.!?])/i, // todo: text or todo: text.
|
|
/\btodo\s+([^\n.!?]+?)(?:\s*$|\s*[.!?])/i, // todo text
|
|
];
|
|
|
|
for (const pattern of patterns) {
|
|
const match = text.match(pattern);
|
|
if (match && match[1]) {
|
|
console.log(match[1].trim());
|
|
process.exit(0);
|
|
}
|
|
}
|
|
|
|
// No match
|
|
process.exit(1);
|