askexperts
Version:
AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol
52 lines • 1.54 kB
JavaScript
import { debugError } from "../../../common/debug.js";
import { DB } from "../../../db/DB.js";
import { APP_DB_PATH } from "../../../common/constants.js";
import { addCommonOptions } from "./index.js";
/**
* Execute the list users command
*
* @param options Command line options
*/
export async function executeListUsersCommand(options) {
try {
// Initialize the database
const db = new DB(APP_DB_PATH);
// Get all users
const users = await db.listUsers();
if (users.length === 0) {
console.log("No users found.");
return;
}
console.log(`Found ${users.length} user(s):`);
// Print user ID and pubkey for each user
users.forEach(user => {
console.log(`ID: ${user.id}, Pubkey: ${user.pubkey}`);
});
}
catch (error) {
debugError("Failed to list users:", error);
throw error;
}
}
/**
* Register the list users command with the CLI
*
* @param program The commander program
*/
export function registerListCommand(program) {
const command = program
.command("list")
.description("List all users")
.action(async (options) => {
try {
await executeListUsersCommand(options);
}
catch (error) {
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
});
// Add common options (debug)
addCommonOptions(command);
}
//# sourceMappingURL=list.js.map