Skip to content

Commit 33f629e

Browse files
authored
add --host command line argument (#20)
* add --host command line argument * update readme and changelog * fix version and changelog
1 parent cc9881e commit 33f629e

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Added
10+
- Add support for `--host` flag ([#20])
11+
912
## [1.1.1] - 2020-02-06
1013
### Added
1114
- Add support for `--dry-run` flag ([#14])
@@ -36,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3639
[1.0.1]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.1
3740
[1.0.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.0
3841

42+
[#20]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/20
3943
[#14]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/14
4044
[#12]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/12
4145
[#8]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/8

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ Cloud Run and Cloud Run on GKE both implement the [Knative Serving API](https://
124124

125125
You can configure the Functions Framework using command-line flags or environment variables. If you specify both, the environment variable will be ignored.
126126

127-
Command-line flag | Environment variable | Description
128-
------------------------- | ------------------------- | -----------
129-
`--port` | `PORT` | The port on which the Functions Framework listens for requests. Default: `8080`
130-
`--target` | `FUNCTION_TARGET` | The name of the exported function to be invoked in response to requests. Default: `function`
131-
`--signature-type` | `FUNCTION_SIGNATURE_TYPE` | The signature used when writing your function. Controls unmarshalling rules and determines which arguments are used to invoke your function. Default: `http`; accepted values: `http` or `event`
132-
`--source` | `FUNCTION_SOURCE` | The path to the file containing your function. Default: `main.py` (in the current working directory)
133-
`--debug` | `DEBUG` | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False`
127+
| Command-line flag | Environment variable | Description |
128+
| ------------------ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
129+
| `--host` | `HOST` | The host on which the Functions Framework listens for requests. Default: `0.0.0.0` |
130+
| `--port` | `PORT` | The port on which the Functions Framework listens for requests. Default: `8080` |
131+
| `--target` | `FUNCTION_TARGET` | The name of the exported function to be invoked in response to requests. Default: `function` |
132+
| `--signature-type` | `FUNCTION_SIGNATURE_TYPE` | The signature used when writing your function. Controls unmarshalling rules and determines which arguments are used to invoke your function. Default: `http`; accepted values: `http` or `event` |
133+
| `--source` | `FUNCTION_SOURCE` | The path to the file containing your function. Default: `main.py` (in the current working directory) |
134+
| `--debug` | `DEBUG` | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False` |
134135

135136
# Enable CloudEvents
136137

src/functions_framework/cli.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
type=click.Choice(["http", "event"]),
2929
default="http",
3030
)
31+
@click.option("--host", envvar="HOST", type=click.STRING, default="0.0.0.0")
3132
@click.option("--port", envvar="PORT", type=click.INT, default=8080)
3233
@click.option("--debug", envvar="DEBUG", is_flag=True)
3334
@click.option("--dry-run", envvar="DRY_RUN", is_flag=True)
34-
def cli(target, source, signature_type, port, debug, dry_run):
35-
host = "0.0.0.0"
35+
def cli(target, source, signature_type, host, port, debug, dry_run):
3636
app = create_app(target, source, signature_type)
3737
if dry_run:
3838
click.echo("Function: {}".format(target))

tests/test_cli.py

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ def test_cli_no_arguments():
8888
[pretend.call("foo", None, "http")],
8989
[],
9090
),
91+
(
92+
["--target", "foo", "--host", "127.0.0.1"],
93+
{},
94+
[pretend.call("foo", None, "http")],
95+
[pretend.call("127.0.0.1", 8080, False)],
96+
),
9197
],
9298
)
9399
def test_cli_arguments(create_app, run, args, env, create_app_calls, run_calls):

0 commit comments

Comments
 (0)