Skip to content

Commit

Permalink
add --host command line argument (#20)
Browse files Browse the repository at this point in the history
* add --host command line argument

* update readme and changelog

* fix version and changelog
  • Loading branch information
kanekv authored Feb 20, 2020
1 parent cc9881e commit 33f629e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add support for `--host` flag ([#20])

## [1.1.1] - 2020-02-06
### Added
- Add support for `--dry-run` flag ([#14])
Expand Down Expand Up @@ -36,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[1.0.1]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.1
[1.0.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.0

[#20]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/20
[#14]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/14
[#12]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/12
[#8]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/8
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ Cloud Run and Cloud Run on GKE both implement the [Knative Serving API](https://

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

Command-line flag | Environment variable | Description
------------------------- | ------------------------- | -----------
`--port` | `PORT` | The port on which the Functions Framework listens for requests. Default: `8080`
`--target` | `FUNCTION_TARGET` | The name of the exported function to be invoked in response to requests. Default: `function`
`--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`
`--source` | `FUNCTION_SOURCE` | The path to the file containing your function. Default: `main.py` (in the current working directory)
`--debug` | `DEBUG` | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False`
| Command-line flag | Environment variable | Description |
| ------------------ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--host` | `HOST` | The host on which the Functions Framework listens for requests. Default: `0.0.0.0` |
| `--port` | `PORT` | The port on which the Functions Framework listens for requests. Default: `8080` |
| `--target` | `FUNCTION_TARGET` | The name of the exported function to be invoked in response to requests. Default: `function` |
| `--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` |
| `--source` | `FUNCTION_SOURCE` | The path to the file containing your function. Default: `main.py` (in the current working directory) |
| `--debug` | `DEBUG` | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False` |

# Enable CloudEvents

Expand Down
4 changes: 2 additions & 2 deletions src/functions_framework/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
type=click.Choice(["http", "event"]),
default="http",
)
@click.option("--host", envvar="HOST", type=click.STRING, default="0.0.0.0")
@click.option("--port", envvar="PORT", type=click.INT, default=8080)
@click.option("--debug", envvar="DEBUG", is_flag=True)
@click.option("--dry-run", envvar="DRY_RUN", is_flag=True)
def cli(target, source, signature_type, port, debug, dry_run):
host = "0.0.0.0"
def cli(target, source, signature_type, host, port, debug, dry_run):
app = create_app(target, source, signature_type)
if dry_run:
click.echo("Function: {}".format(target))
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ def test_cli_no_arguments():
[pretend.call("foo", None, "http")],
[],
),
(
["--target", "foo", "--host", "127.0.0.1"],
{},
[pretend.call("foo", None, "http")],
[pretend.call("127.0.0.1", 8080, False)],
),
],
)
def test_cli_arguments(create_app, run, args, env, create_app_calls, run_calls):
Expand Down

0 comments on commit 33f629e

Please sign in to comment.