mirror of
https://github.com/simonw/dclient.git
synced 2026-07-25 02:14:32 +02:00
Add databases command to list databases on an instance
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d1dfdbf6db
commit
8b98d971dd
1 changed files with 28 additions and 0 deletions
|
|
@ -56,6 +56,34 @@ def get(path, instance, token):
|
|||
click.echo(response.text)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("url_or_alias", default=None, required=False)
|
||||
@click.option("--token", help="API token")
|
||||
def databases(url_or_alias, token):
|
||||
"""
|
||||
List databases available on a Datasette instance
|
||||
|
||||
Example usage:
|
||||
|
||||
\b
|
||||
dclient databases https://latest.datasette.io
|
||||
"""
|
||||
url = _resolve_url(url_or_alias)
|
||||
token = _resolve_token(token, url)
|
||||
headers = {}
|
||||
if token:
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
response = httpx.get(
|
||||
url.rstrip("/") + "/-/databases.json",
|
||||
headers=headers,
|
||||
follow_redirects=True,
|
||||
timeout=30.0,
|
||||
)
|
||||
if response.status_code != 200:
|
||||
raise click.ClickException(f"{response.status_code} error")
|
||||
click.echo(json.dumps(response.json(), indent=2))
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("url_or_alias")
|
||||
@click.argument("sql")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue