UNPKG

@latentsearch/timemachine-cli

Version:

CLI tool for TimeMachine API. Generates time entries, lists users/projects, and features an enhanced dry-run output for generation.

51 lines (50 loc) 2.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.listUsers = listUsers; const chalk_1 = __importDefault(require("chalk")); const console_table_printer_1 = require("console-table-printer"); const api_client_1 = require("../utils/api-client"); /** * Lists all users with their details */ async function listUsers(options) { try { console.log(chalk_1.default.blue("Fetching users...")); const api = (0, api_client_1.createApiClient)(options); const response = await api.get("/api/users"); if (response.data && response.data.length > 0) { const table = new console_table_printer_1.Table({ title: "Code Clock Users", columns: [ { name: "id", title: "ID", alignment: "right" }, { name: "name", title: "Name" }, { name: "email", title: "Email" }, { name: "role", title: "Role" } ] }); response.data.forEach(user => { table.addRow({ id: user.id, name: `${user.given_name || ""} ${user.surname || ""}`.trim() || user.username || "N/A", email: user.email || "N/A", role: user.role || "N/A" }); }); table.printTable(); console.log(`\nTotal users: ${response.data.length}`); } else { console.log(chalk_1.default.yellow("No users found")); } } catch (error) { console.error(chalk_1.default.red("Error fetching users:"), error.response?.data?.error || error.message); if (options.verbose && error.response?.data) { console.error(chalk_1.default.gray(JSON.stringify(error.response.data, null, 2))); } process.exit(1); } }