feat: add list_boards task

This commit is contained in:
2025-10-27 00:14:00 +02:00
parent 618535a519
commit 27db0349db
2 changed files with 83 additions and 0 deletions

View File

@@ -1,6 +1,9 @@
create_board:
@poetry run python create_board.py
list_boards:
@poetry run python list_boards.py
list_stacks:
@poetry run python list_stacks.py

80
list_boards.py Normal file
View File

@@ -0,0 +1,80 @@
#!/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()