#!/usr/bin/env python3 from __future__ import annotations import argparse import json import sys import requests from common import ( add_domain_and_auth_args, build_session, resolve_domain_and_auth, ) def list_boards(session: requests.Session, base_url: str): url = f"{base_url}/index.php/apps/deck/api/v1.0/boards" headers = {"OCS-APIRequest": "true", "Accept": "application/json"} resp = session.get(url, headers=headers) if resp.status_code != 200: raise RuntimeError(f"Deck API error: {resp.status_code} {resp.text}") return resp.json() def main() -> None: parser = argparse.ArgumentParser( description="List all boards (id + name) for a Nextcloud Deck instance." ) # Domain and auth flags (no board-id since we're listing all boards) add_domain_and_auth_args(parser) # Script-specific flags parser.add_argument( "--json", action="store_true", help="Output raw JSON instead of a table", ) args = parser.parse_args() # Resolve domain and auth (ENV -> CLI -> prompt) try: base_url, username, password = resolve_domain_and_auth( cli_domain=args.domain, cli_username=args.username, cli_password=args.password, ) except Exception as e: print(f"❌ {e}", file=sys.stderr) sys.exit(2) session = build_session(username, password) try: boards = list_boards(session, base_url) except Exception as e: print(f"❌ Failed to fetch boards: {e}", file=sys.stderr) sys.exit(1) if args.json: print(json.dumps(boards, ensure_ascii=False, indent=2)) return if not boards: print("No boards found.") return print(f"Boards at {base_url}:") print("-" * 60) print(f"{'ID':<8} {'NAME'}") print("-" * 60) for b in boards: bid = b.get("id") title = b.get("title", "") print(f"{str(bid):<8} {title}") print("-" * 60) print("Tip: use the ID with --board-id in other scripts.") if __name__ == "__main__": main()