···44import sys
5566import click
77+import httpx
7889from pyzotero import __version__, zotero
910from pyzotero.zotero import chunks
···348349 # Output as JSON array
349350 click.echo(json.dumps(item_types, indent=2))
350351352352+ except Exception as e:
353353+ click.echo(f"Error: {e!s}", err=True)
354354+ sys.exit(1)
355355+356356+357357+@main.command()
358358+@click.pass_context
359359+def test(ctx):
360360+ """Test connection to local Zotero instance.
361361+362362+ This command checks whether Zotero is running and accepting local connections.
363363+364364+ Examples:
365365+ pyzotero test
366366+367367+ """
368368+ try:
369369+ locale = ctx.obj.get("locale", "en-US")
370370+ zot = _get_zotero_client(locale)
371371+372372+ # Call settings() to test the connection
373373+ # This should return {} if Zotero is running and listening
374374+ result = zot.settings()
375375+376376+ # If we get here, the connection succeeded
377377+ click.echo("✓ Connection successful: Zotero is running and listening locally.")
378378+ if result == {}:
379379+ click.echo(" Received expected empty settings response.")
380380+ else:
381381+ click.echo(f" Received response: {json.dumps(result)}")
382382+383383+ except httpx.ConnectError:
384384+ click.echo(
385385+ "✗ Connection failed: Could not connect to Zotero.\n\n"
386386+ "Possible causes:\n"
387387+ " • Zotero might not be running\n"
388388+ " • Local connections might not be enabled\n\n"
389389+ "To enable local connections:\n"
390390+ " Zotero > Settings > Advanced > Allow other applications on this computer to communicate with Zotero",
391391+ err=True,
392392+ )
393393+ sys.exit(1)
351394 except Exception as e:
352395 click.echo(f"Error: {e!s}", err=True)
353396 sys.exit(1)