diff --git a/README.md b/README.md index b93173e..36264b7 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Options: -V, --version Display version information --credits Display dependency credits (including Twig version) -d, --dir=DIR Add search directory to loader (multiple values allowed) + --env Treat environment variables as input data -e, --escape=ESCAPE Set autoescape environment option -j, --json=JSON Pass variables as JSON (dictionary string or file path) -p, --pair=PAIR Pass variable as key=value pair (multiple values allowed) diff --git a/src/Twigc/DefaultCommand.php b/src/Twigc/DefaultCommand.php index ce3d20d..22cc227 100644 --- a/src/Twigc/DefaultCommand.php +++ b/src/Twigc/DefaultCommand.php @@ -63,6 +63,12 @@ class DefaultCommand extends Command { InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Add search directory to loader' ) + ->addOption( + 'env', + null, + InputOption::VALUE_NONE, + 'Treat environment variables as input data' + ) ->addOption( 'escape', 'e', @@ -349,6 +355,10 @@ class DefaultCommand extends Command { } } + if ( $input->getOption('env') ) { + $inputData = array_merge($_ENV, $inputData); + } + // Validate key names now foreach ( $inputData as $key => $value ) { if ( ! preg_match('#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$#', $key) ) {