Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --host command line argument #20

Merged
merged 5 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.2] - 2020-02-20
### Added
- Add support for `--host` flag ([#20])
di marked this conversation as resolved.
Show resolved Hide resolved

## [1.1.1] - 2020-02-06
### Added
- Add support for `--dry-run` flag ([#14])
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

setup(
name="functions-framework",
version="1.1.1",
version="1.1.2",
description="An open source FaaS (Function as a service) framework for writing portable Python functions -- brought to you by the Google Cloud Functions team.",
long_description=long_description,
long_description_content_type="text/markdown",
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