Skip to content

Commit

Permalink
added argument for update:tasks command
Browse files Browse the repository at this point in the history
  • Loading branch information
dgncan committed Sep 9, 2019
1 parent f8d4fb5 commit afec31e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Init is a console application that helps to make for php projects first configur

To install Init by using Composer:
```bash
$ composer require dgncan/init "^0.5"
$ composer require dgncan/init "^0.6"
```

Example composer.json file:
```bash
{
"require": {
"dgncan/init": "^0.5",
"dgncan/init": "^0.6",
}
}
```
Expand Down Expand Up @@ -50,7 +50,8 @@ Create an init.php file with the following contents:
'update-tasks'=>
[
'Sample dummy process'=>
function () {
function ($args) {
print_r($args);
echo "sample dummy processed\n";
},
/*
Expand Down
2 changes: 1 addition & 1 deletion bin/init
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use Init\Command\UpdateTasksCommand;
# set current working directory as main project root directory
chdir(__DIR__."/../../../../");

$application = new Application('Init', '0.5');
$application = new Application('Init', '0.6');


// ... register commands
Expand Down
3 changes: 2 additions & 1 deletion example-project/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
'update-tasks'=>
[
'Sample dummy process'=>
function () {
function ($args) {
print_r($args);
echo "sample dummy processed\n";
}
],
Expand Down
3 changes: 2 additions & 1 deletion init.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ return [
'update-tasks'=>
[
'Sample dummy process'=>
function () {
function ($args) {
print_r($args);
echo "sample dummy processed\n";
}
],
Expand Down
9 changes: 8 additions & 1 deletion src/Command/UpdateTasksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Init\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand All @@ -26,6 +27,9 @@ protected function configure()
->setDescription('Runs functions written as closure.')
->setHelp('Runs functions written as closure.')
;
$this
->addArgument('env', InputArgument::OPTIONAL, 'if not selected, it is Dev as a default.')
;
}

protected function setup(SymfonyStyle $io)
Expand Down Expand Up @@ -53,10 +57,13 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->setup($io);

$env = $input->getArgument('env') =='' ? 'dev' : $input->getArgument('env');
$args = ['env'=>$env];

foreach ($this->functions as $name => $function) {
$io->section($name);
try {
$function();
$function($args);
} catch (\Exception $e) {
$io->error($e->getMessage());
exit(1);
Expand Down

0 comments on commit afec31e

Please sign in to comment.