INNER CODE UNIT · Python
list_users
OschAI/VisioFirm · visiofirm/cli.py:26
def list_users():
init_db()
with sqlite3.connect(get_db_path()) as conn:
rows = conn.execute(
"SELECT id, username, email, first_name, last_name, company, api_key "
"FROM users ORDER BY id"
).fetchall()
if not rows:
print("No users found.")
return 0
headers = ["ID", "Username", "Email", "First name", "Last name", "Company", "API key"]
table = [headers] + [[str(c) if c is not None else "" for c in row] for row in rows]
widths = [max(len(row[i]) for row in table) for i in range(len(headers))]
for row in table:
print(" ".join(cell.ljust(widths[i]) for i, cell in enumerate(row)).rstrip())
return 0