diff --git a/docs/function/local-development.md b/docs/function/local-development.md index 025046e0c..6fe40633e 100644 --- a/docs/function/local-development.md +++ b/docs/function/local-development.md @@ -80,6 +80,14 @@ Hello world # With JSON event data $ vendor/bin/bref-local my-function.php '{"name": "Jane"}' Hello Jane + +# With a path to a file containing a JSON event. +$ cat event.json +{ + "name": "Alex" +} +$ vendor/bin/bref-local --path event.json my-function.php +Hello Alex ``` If you want to run your function in Docker: diff --git a/src/bref-local b/src/bref-local index d370bc924..63e77d5ac 100755 --- a/src/bref-local +++ b/src/bref-local @@ -18,6 +18,16 @@ if (file_exists(__DIR__ . '/../vendor/autoload.php')) { $handler = $argv[1] ?? ''; $data = $argv[2] ?? null; +$opts = getopt('', ['path:']); + +if (isset($opts['path'])) { + if (! file_exists($opts['path'])) { + throw new Exception('The file ' . $opts['path'] . ' could not be found.'); + } + + $handler = $argv[array_key_last($argv)]; + $data = file_get_contents($opts['path']); +} try { $handler = Bref::getContainer()->get($handler);