Skip to content

Commit

Permalink
Now showing help message when no template is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
nsrosenqvist committed Mar 15, 2017
1 parent 0904853 commit a3acf6f
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -6,6 +6,8 @@ Blade CLI is a command line compiler for the Laravel Blade templating engine. Yo
## Installation
To install you can either clone this repo and run `composer install && composer build` or simply retrieving the latest PHAR from the [releases page](https://www.github.com/nsrosenqvist/blade-cli/releases/latest).

I also have a convenience feature configured that install the PHAR to `/usr/bin` by running `composer build:install` but it makes a whole lot of assumptions of your OS and probably only works on Linux and macOS. Use at your own risk.

## Usage
`compile [options] [--] <template> (<template>)...`

Expand Down
28 changes: 27 additions & 1 deletion bin/blade
Expand Up @@ -5,16 +5,42 @@ require __DIR__.'/../vendor/autoload.php';

use NSRosenqvist\Blade\Console\Command;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\EventDispatcher\EventDispatcher;

// Create App
$application = new Application('Blade', '1.0.0');
$application = new Application('Blade CLI', '1.0.1');
$dispatcher = new EventDispatcher();

//Add compile command
$compile = new Command\Compile();
$application->add($compile);

// Run help if no arguments are set
$dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) use ($compile) {
$input = $event->getInput();
$output = $event->getOutput();
$command = $event->getCommand();

if ($command->getName() == 'compile') {
$template = $input->getArgument('template');

// Show help message if no arguments are set
if (empty($template)) {
$help = new HelpCommand();
$help->setCommand($compile);
$help->run($input, $output);

$event->disableCommand();
}
}
});

// Single command application
$application->setDefaultCommand($compile->getName(), true);

// Run
$application->setDispatcher($dispatcher);
$application->run();
6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -18,12 +18,14 @@
"require": {
"php": "^7.0",
"symfony/console": "^3.2",
"nsrosenqvist/blade-compiler": "^1.0.0"
"nsrosenqvist/blade-compiler": "^1.0.0",
"symfony/event-dispatcher": "^3.2"
},
"scripts": {
"build": "mkdir -p dist && php ./phar-composer.phar build . dist",
"test": "php bin/blade test/index.blade.php --data=test/variables.json --data=test/variables.php --data='{\"nameString\":\"John Doe\"}'",
"test:build": "php dist/blade-cli.phar test/index.blade.php --data=test/variables.json --data=test/variables.php --data='{\"nameString\":\"John Doe\"}'"
"build:test": "php dist/blade-cli.phar test/index.blade.php --data=test/variables.json --data=test/variables.php --data='{\"nameString\":\"John Doe\"}'",
"build:install": "sudo cp dist/blade-cli.phar /usr/bin/blade && sudo chmod +x /usr/bin/blade"
},
"bin": ["bin/blade"]
}
62 changes: 61 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a3acf6f

Please sign in to comment.