Run cog with --extra test

Previously it kept on adding stuff to cli-reference.rst
that came from other plugins installed for my global environment
This commit is contained in:
Simon Willison 2025-11-04 18:11:20 -08:00
commit 9f74dc22a8
2 changed files with 26 additions and 6 deletions

View file

@ -21,11 +21,11 @@ export DATASETTE_SECRET := "not_a_secret"
@lint: codespell @lint: codespell
uv run black . --check uv run black . --check
uv run flake8 uv run flake8
uv run cog --check README.md docs/*.rst uv run --extra test cog --check README.md docs/*.rst
# Rebuild docs with cog # Rebuild docs with cog
@cog: @cog:
uv run cog -r README.md docs/*.rst uv run --extra test cog -r README.md docs/*.rst
# Serve live docs on localhost:8000 # Serve live docs on localhost:8000
@docs: cog blacken-docs @docs: cog blacken-docs

View file

@ -442,6 +442,11 @@ def uninstall(packages, yes):
"--get", "--get",
help="Run an HTTP GET request against this path, print results and exit", help="Run an HTTP GET request against this path, print results and exit",
) )
@click.option(
"--headers",
is_flag=True,
help="Include HTTP headers in --get output (requires --get)",
)
@click.option( @click.option(
"--token", "--token",
help="API token to send with --get requests", help="API token to send with --get requests",
@ -510,6 +515,7 @@ def serve(
secret, secret,
root, root,
get, get,
headers,
token, token,
actor, actor,
version_note, version_note,
@ -658,19 +664,33 @@ def serve(
# Run async soundness checks - but only if we're not under pytest # Run async soundness checks - but only if we're not under pytest
run_sync(lambda: check_databases(ds)) run_sync(lambda: check_databases(ds))
if headers and not get:
raise click.ClickException("--headers can only be used with --get")
if token and not get: if token and not get:
raise click.ClickException("--token can only be used with --get") raise click.ClickException("--token can only be used with --get")
if get: if get:
client = TestClient(ds) client = TestClient(ds)
headers = {} request_headers = {}
if token: if token:
headers["Authorization"] = "Bearer {}".format(token) request_headers["Authorization"] = "Bearer {}".format(token)
cookies = {} cookies = {}
if actor: if actor:
cookies["ds_actor"] = client.actor_cookie(json.loads(actor)) cookies["ds_actor"] = client.actor_cookie(json.loads(actor))
response = client.get(get, headers=headers, cookies=cookies) response = client.get(get, headers=request_headers, cookies=cookies)
click.echo(response.text)
if headers:
# Output HTTP status code, headers, two newlines, then the response body
click.echo(f"HTTP/1.1 {response.status}")
for key, value in response.headers.items():
click.echo(f"{key}: {value}")
if response.text:
click.echo()
click.echo(response.text)
else:
click.echo(response.text)
exit_code = 0 if response.status == 200 else 1 exit_code = 0 if response.status == 200 else 1
sys.exit(exit_code) sys.exit(exit_code)
return return