chore(cli): dry up link + post tag prompt

This commit is contained in:
Cory Dransfeldt 2025-06-16 14:56:55 -07:00
parent efe701f939
commit 555ba74bf6
No known key found for this signature in database
8 changed files with 75 additions and 104 deletions

View file

@ -0,0 +1,65 @@
import inquirer from "inquirer";
import { searchItems, createItem } from "./client.js";
export const promptForTags = async () => {
const tagIds = [];
while (true) {
const { query } = await inquirer.prompt({
name: "query",
message: "🏷 Search for tags (or leave blank to finish):"
});
const trimmedQuery = query.trim();
if (!trimmedQuery) break;
const tags = await searchItems("tags", trimmedQuery);
if (!tags.length) {
console.warn(`⚠️ No tags found matching "${trimmedQuery}"`);
const { shouldCreateTag } = await inquirer.prompt({
type: "confirm",
name: "shouldCreateTag",
message: `Do you want to create a new tag named "${trimmedQuery}"?`,
default: true
});
if (shouldCreateTag) {
const createdTag = await createItem("tags", { name: trimmedQuery });
const newTagId = createdTag.data?.id || createdTag.id;
tagIds.push(newTagId);
}
const { again } = await inquirer.prompt({
type: "confirm",
name: "again",
message: "Search and select more tags?",
default: false
});
if (!again) break;
continue;
}
const { selected } = await inquirer.prompt({
type: "checkbox",
name: "selected",
message: "✔ Select tags to add:",
choices: tags.map((tag) => ({ name: tag.name, value: tag.id }))
});
tagIds.push(...selected);
const { again } = await inquirer.prompt({
type: "confirm",
name: "again",
message: "Search and select more tags?",
default: false
});
if (!again) break;
}
return [...new Set(tagIds)];
};