diff --git a/.gitignore b/.gitignore index 6d23f618..e175d93a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ /.idea/ # IntelliJ -/out/ -/build/ +/build/coverage +/build/logs +/build/phar +/build/*.phar # JIRA plugin atlassian-ide-plugin.xml diff --git a/README.md b/README.md index 679a817e..ef81cba5 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ This is a parser for API Blueprint files in PHP. ## Usage For direct usage you can run: ```bash -$ ./phpdraft.phar blueprint-file.apib > blueprint-webpage.html +$ ./phpdraft.phar -f blueprint-file.apib > blueprint-webpage.html ``` You can also install it first: ```bash $ cp phpdraft.phar /usr/bin/phpdraft $ chmod +x /usr/bin/phpdraft -$ phpdraft blueprint-file.apib > blueprint-webpage.html +$ phpdraft -f blueprint-file.apib > blueprint-webpage.html ``` ## Including Files diff --git a/build.xml b/build.xml new file mode 100644 index 00000000..d64b209c --- /dev/null +++ b/build.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/binary-phar-autoload.php.in b/build/binary-phar-autoload.php.in new file mode 100755 index 00000000..9b662045 --- /dev/null +++ b/build/binary-phar-autoload.php.in @@ -0,0 +1,34 @@ +#!/usr/bin/env php +')) { + fwrite( + STDERR, + 'This version of PHPDraft requires PHP 5.6; using the latest version of PHP is highly recommended.' . PHP_EOL + ); + + die(1); +} + +if (__FILE__ == realpath($GLOBALS['_SERVER']['SCRIPT_NAME'])) { + $execute = true; +} else { + $execute = false; +} + +define('__PHPDRAFT_PHAR__', str_replace(DIRECTORY_SEPARATOR, '/', __FILE__)); +define('__PHPDRAFT_PHAR_ROOT__', 'phar://___PHAR___'); + +Phar::mapPhar('___PHAR___'); + +___FILELIST___ + +if ($execute) { + if (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == '--manifest') { + print file_get_contents(__PHPDRAFT_PHAR_ROOT__ . '/manifest.txt'); + exit; + } + + require_once __PHPDRAFT_PHAR_ROOT__.DIRECTORY_SEPARATOR.'phpdraft'.DIRECTORY_SEPARATOR.'index.php'; +} + +__HALT_COMPILER(); diff --git a/build/library-phar-autoload.php.in b/build/library-phar-autoload.php.in new file mode 100755 index 00000000..46838561 --- /dev/null +++ b/build/library-phar-autoload.php.in @@ -0,0 +1,9 @@ +&1'); + +if (strpos($tag, '-') === false && strpos($tag, 'No names found') === false) { + print $tag; +} else { + $branch = @exec('git rev-parse --abbrev-ref HEAD'); + $hash = @exec('git log -1 --format="%H"'); + print $branch . '@' . $hash; +} + +print "\n"; diff --git a/build/phar-version.php b/build/phar-version.php new file mode 100755 index 00000000..5dfc51ff --- /dev/null +++ b/build/phar-version.php @@ -0,0 +1,20 @@ +#!/usr/bin/env php +parseToJson()); -$html->get_html($template, $image); +$html->get_html($values['template'], $values['image']); + -function help() -{ - echo 'This is a parser for API Blueprint files in PHP.'.PHP_EOL.PHP_EOL; - echo "The following options can be used:.\n"; - echo "\t-f\tSpecifies the file to parse.\n"; - echo "\t-t\tSpecifies the template to use. (defaults to 'default')\n"; - echo "\t-h\tDisplays this text.\n"; -} ?> diff --git a/src/PHPDraft/Out/UI.php b/src/PHPDraft/Out/UI.php new file mode 100644 index 00000000..3249e9f5 --- /dev/null +++ b/src/PHPDraft/Out/UI.php @@ -0,0 +1,78 @@ + + */ + +namespace PHPDraft\Out; + + +class UI +{ + static function main($argv = []) + { + $options = getopt("f:t::i::hv"); + if(!isset($argv[1])) + { + file_put_contents('php://stderr', 'Not enough arguments'.PHP_EOL); + self::help(); + exit(1); + } + + if (boolval(preg_match('/^\-/',$argv[1]))) + { + if (isset($options['h'])) + { + self::help(); + exit(0); + } + + if (isset($options['v'])) + { + self::version(); + exit(0); + } + + elseif (isset($options['f'])) + { + $file = $options['f']; + } + else + { + file_put_contents('php://stderr', 'No file to parse'.PHP_EOL); + exit(1); + } + } + else + { + $file = $argv[1]; + } + + $template = (isset($options['t']) && $options['t']) ? $options['t']: 'default'; + $image = (isset($options['i']) && $options['i']) ? $options['i']: NULL; + + return [ + 'file' => $file, + 'template' => $template, + 'image' => $image + ]; + } + + static function help() + { + echo 'This is a parser for API Blueprint files in PHP.'.PHP_EOL.PHP_EOL; + echo "The following options can be used:.\n"; + echo "\t-f\tSpecifies the file to parse.\n"; + echo "\t-t\tSpecifies the template to use. (defaults to 'default')\n"; + echo "\t-h\tDisplays this text.\n"; + } + + static function version() + { + $version = (VERSION === '0') ? @exec('git describe --tags 2>&1') : VERSION; + echo 'PHPDraft: '.$version; + } + +} \ No newline at end of file