Skip to content

Commit 58deaf1

Browse files
authored
refactor: replace --gateway flag with --asgi boolean flag (#383)
* refactor: replace --gateway flag with --asgi boolean flag Simplify the CLI by replacing `--gateway asgi` with `--asgi`. The new flag is more intuitive as WSGI remains the default and ASGI is opt-in. Also updates the environment variable to FUNCTION_USE_ASGI for clarity. * fix: update conformance tests to use --asgi flag
1 parent a576a8f commit 58deaf1

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

.github/workflows/conformance-asgi.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,39 +52,39 @@ jobs:
5252
functionType: 'http'
5353
useBuildpacks: false
5454
validateMapping: false
55-
cmd: "'functions-framework --source tests/conformance/async_main.py --target write_http --signature-type http --gateway asgi'"
55+
cmd: "'functions-framework --source tests/conformance/async_main.py --target write_http --signature-type http --asgi'"
5656

5757
- name: Run CloudEvents conformance tests
5858
uses: GoogleCloudPlatform/functions-framework-conformance/action@72a4f36b10f1c6435ab1a86a9ea24bda464cc262 # v1.8.6
5959
with:
6060
functionType: 'cloudevent'
6161
useBuildpacks: false
6262
validateMapping: false
63-
cmd: "'functions-framework --source tests/conformance/async_main.py --target write_cloud_event --signature-type cloudevent --gateway asgi'"
63+
cmd: "'functions-framework --source tests/conformance/async_main.py --target write_cloud_event --signature-type cloudevent --asgi'"
6464

6565
- name: Run HTTP conformance tests declarative
6666
uses: GoogleCloudPlatform/functions-framework-conformance/action@72a4f36b10f1c6435ab1a86a9ea24bda464cc262 # v1.8.6
6767
with:
6868
functionType: 'http'
6969
useBuildpacks: false
7070
validateMapping: false
71-
cmd: "'functions-framework --source tests/conformance/async_main.py --target write_http_declarative --gateway asgi'"
71+
cmd: "'functions-framework --source tests/conformance/async_main.py --target write_http_declarative --asgi'"
7272

7373
- name: Run CloudEvents conformance tests declarative
7474
uses: GoogleCloudPlatform/functions-framework-conformance/action@72a4f36b10f1c6435ab1a86a9ea24bda464cc262 # v1.8.6
7575
with:
7676
functionType: 'cloudevent'
7777
useBuildpacks: false
7878
validateMapping: false
79-
cmd: "'functions-framework --source tests/conformance/async_main.py --target write_cloud_event_declarative --gateway asgi'"
79+
cmd: "'functions-framework --source tests/conformance/async_main.py --target write_cloud_event_declarative --asgi'"
8080

8181
- name: Run HTTP concurrency tests declarative
8282
uses: GoogleCloudPlatform/functions-framework-conformance/action@72a4f36b10f1c6435ab1a86a9ea24bda464cc262 # v1.8.6
8383
with:
8484
functionType: 'http'
8585
useBuildpacks: false
8686
validateConcurrency: true
87-
cmd: "'functions-framework --source tests/conformance/async_main.py --target write_http_declarative_concurrent --gateway asgi'"
87+
cmd: "'functions-framework --source tests/conformance/async_main.py --target write_http_declarative_concurrent --asgi'"
8888

8989
# Note: Event (legacy) and Typed tests are not supported in ASGI mode
9090
# Note: validateMapping is set to false for CloudEvent tests because ASGI mode

src/functions_framework/_cli.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@
3333
@click.option("--port", envvar="PORT", type=click.INT, default=8080)
3434
@click.option("--debug", envvar="DEBUG", is_flag=True)
3535
@click.option(
36-
"--gateway",
37-
envvar="FUNCTION_GATEWAY",
38-
type=click.Choice(["wsgi", "asgi"]),
39-
default="wsgi",
40-
help="Server gateway interface type (wsgi for sync, asgi for async)",
36+
"--asgi",
37+
envvar="FUNCTION_USE_ASGI",
38+
is_flag=True,
39+
help="Use ASGI server for function execution",
4140
)
42-
def _cli(target, source, signature_type, host, port, debug, gateway):
43-
if gateway == "asgi": # pragma: no cover
41+
def _cli(target, source, signature_type, host, port, debug, asgi):
42+
if asgi: # pragma: no cover
4443
from functions_framework.aio import create_asgi_app
4544

4645
app = create_asgi_app(target, source, signature_type)

tests/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_asgi_cli(monkeypatch):
119119
monkeypatch.setattr(functions_framework._cli, "create_server", create_server)
120120

121121
runner = CliRunner()
122-
result = runner.invoke(_cli, ["--target", "foo", "--gateway", "asgi"])
122+
result = runner.invoke(_cli, ["--target", "foo", "--asgi"])
123123

124124
assert result.exit_code == 0
125125
assert create_asgi_app.calls == [pretend.call("foo", None, "http")]

0 commit comments

Comments
 (0)