Skip to content

Commit

Permalink
Merge commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mleko committed Aug 22, 2017
1 parent e3c499f commit 41b4773
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Formatting file: ./composer.json
Install `mleko/wingman` as dependency
```
$ composer require --dev mleko/wingman
$ vendor/bin/wingman register
$ vendor/bin/wingman --register
Register wingman in file: ./composer.json
Wingman registered
Formatting file: ./composer.json
Expand Down
1 change: 0 additions & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public function __construct()
parent::__construct("Wingman");

$this->add(new FormatCommand());
$this->add(new RegisterCommand());

$this->setDefaultCommand("format");
}
Expand Down
6 changes: 4 additions & 2 deletions src/Console/FormatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class FormatCommand extends Command
Expand All @@ -23,14 +24,15 @@ protected function configure()
parent::configure();
$this->setName("format")
->setDescription("Format composer.json file")
->addArgument("path", InputArgument::OPTIONAL, "Path to composer.json file", "./composer.json");
->addArgument("path", InputArgument::OPTIONAL, "Path to composer.json file", "./composer.json")
->addOption("register", null, InputOption::VALUE_NONE, "Register wingman as post-update script");
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getArgument("path");
$wingman = new Wingman();
$wingman->formatFile($path, new ConsoleOutputAdapter($output));
$wingman->formatFile($path, new ConsoleOutputAdapter($output), $input->getOption("register"));
}

}
36 changes: 0 additions & 36 deletions src/Console/RegisterCommand.php

This file was deleted.

9 changes: 2 additions & 7 deletions src/Wingman.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,9 @@ public function format($composerJson)
return Formatter::format($composerJson, $this->rules);
}

public function formatFile($path, Output $output)
public function formatFile($path, Output $output, $register = false)
{
return $this->processFile($path, $output);
}

public function registerInFile($path, Output $output)
{
return $this->processFile($path, $output, true);
return $this->processFile($path, $output, $register);
}

public function register($composerJson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;

class RegisterCommandTest extends TestCase
class FormatCommandTest extends TestCase
{
/**
* @var vfsStreamDirectory
Expand All @@ -36,12 +36,13 @@ public function testRegisterCommand()
$virtualFile->setContent(json_encode(["name" => "acme/test"]));

$application = new Application();
$registerCommand = $application->find("register");
$registerCommand = $application->find("format");
$commandTester = new CommandTester($registerCommand);

$resultCode = $commandTester->execute([
"command" => $registerCommand->getName(),
"path" => $virtualFile->url()
"path" => $virtualFile->url(),
"--register" => true
]);

$this->assertEquals(0, $resultCode);
Expand Down

0 comments on commit 41b4773

Please sign in to comment.