twigc/src/bootstrap.php
dana 9cbe7e75f9 Significantly rework application: 0.3.0
- Get rid of Symfony Console application/command/input components

  These were causing me serious problems — not least of all was the fact that
  the Console argument parser chokes on command lines lke `twigc -j - foo.twig`.
  I am not happy with the way i've structured this, but i just needed to get it
  *done*, so here we are. If someone has any advice on to how to make this nicer
  (maybe break it up into different classes, &c.), i would be appreciative

- Add GetOpt.php for argument parsing and usage-help printing

  The usage help is really ugly, tbh. But whatever

- Support multiple input data sources at once

- Add `-E` short option for `--env`

- Display an error when `-E` is used without the appropriate `variables_order`
  configuration in place

- Add shell (`sh`) auto-escape method

- Simplify/eliminate a lot of code (handling of version numbers, validation, &c.)

- Change a lot of white space and formatting stuff (RIP `blame`)
2018-06-02 01:58:59 -05:00

60 lines
1.2 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* This file is part of twigc.
*
* @author dana <dana@dana.is>
* @license MIT
*/
/**
* Print an error message.
*
* Uses fprintf() to print to stderr if available; uses echo otherwise.
*
* @param string $string
* (optional) The message to print. Is passed through rtrim(); if the result
* is an empty string, only an empty line is printed; otherwise, the text
* 'twigc: ' is appended to the beginning.
*
* @return void
*/
function twigc_puts_error($string = '') {
$string = rtrim($string);
$string = $string === '' ? '' : "twigc: ${string}";
if ( defined('\\STDERR') ) {
fprintf(\STDERR, "%s\n", $string);
} else {
echo $string, "\n";
}
}
if ( \PHP_SAPI !== 'cli' ) {
twigc_puts_error("This tool must be invoked via PHP's CLI SAPI.");
exit(1);
}
(function () {
$paths = [
// Phar/repo path
__DIR__ . '/../vendor/autoload.php',
// Composer path
__DIR__ . '/../../../autoload.php',
];
foreach ( $paths as $path ) {
if ( file_exists($path) ) {
define('TWIGC_AUTOLOADER', $path);
return;
}
}
})();
if ( ! defined('\\TWIGC_AUTOLOADER') ) {
twigc_puts_error('Auto-loader is missing — try running `composer install`.');
exit(1);
}
require_once \TWIGC_AUTOLOADER;