-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Config code clean up * WIP: "docker-compose exec" to "docker exec" conversion * Update XdebugTest.php * Update WpTest.php * Add DockerTest.php * add strict types * Add spatie dto * Fix grammar in comment * composer update * WIP: custom command system * Output can't be dependency injected this early, call directly * Don't add half created commands * Rename use statement * Remove done statement from composer command * Fixes #89 * Add support for both yaml array syntaxes for docker env vars * Move runners into their own collection * Don't sort Yaml data, we need it in the order it came in * Add args/options to the command definition * Refactor custom command running to use pipelines * Fix YamlTests * Add CommandFactoryTest.php * Add CommandCollectionTest.php * Set proper method visibility on runners * Add HostCommandRunnerTest.php * Add ServiceCommandRunnerTest.php * Add MultiCommandRunnerTest.php * Add RunnerCollectionTest.php * Update auto completion * Fix env var bug found during testing, update service command to test both env var syntaxes. * Add CustomCommandRunnerTest.php * Allow testing of symfony commands in addition to laravel commands * Run host commands as a string to force Process to use fromShellCommandline() * Add a test command to the tests config file * Add CommandLoaderTest, fix bug in closure command * Add custom command docs and examples * Fix environment variables in example * Remove commented code * Fix test name * Fix strict comparison * composer update * Use sprintf for consistency * Fix line formatting * composer update * Try running directly with php * composer install instead of update * rollback * Pass config file, enable debug, no logging * Remove debug, remove autoloader optimization * Remove @runTestsInSeparateProcesses, only isolate a single test * code/type clean up * Disable global state in other separate processes
- Loading branch information
Showing
41 changed files
with
1,423 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Contracts; | ||
|
||
use App\Services\CustomCommands\CommandDefinition; | ||
use App\Services\Docker\Container; | ||
use Closure; | ||
|
||
/** | ||
* Custom Command Runner run as a Pipeline stage. | ||
*/ | ||
abstract class CustomCommandRunner { | ||
|
||
/** | ||
* The default "docker" arguments. | ||
* | ||
* @var string[] | ||
*/ | ||
protected $execArgs = [ | ||
'exec', | ||
]; | ||
|
||
/** | ||
* @var \App\Services\Docker\Container | ||
*/ | ||
protected $container; | ||
|
||
public function __construct( Container $container ) { | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* Configure a command before execution. | ||
* | ||
* @param \App\Services\CustomCommands\CommandDefinition $command | ||
* @param \Closure $next | ||
*/ | ||
public function run( CommandDefinition $command, Closure $next ) { | ||
$this->execArgs = array_merge( $this->execArgs, array_filter( [ | ||
$command->interactive ? '--interactive' : '', | ||
$command->tty ? '--tty' : '', | ||
'--user', | ||
$command->user, | ||
] ) ); | ||
|
||
// Add environment variables to pass to the container | ||
if ( ! empty( $command->env ) ) { | ||
foreach ( $command->env as $var => $value ) { | ||
|
||
// Support hyphen yaml syntax, e.g. - VAR: value | ||
if ( is_array( $value ) ) { | ||
foreach ( $value as $subVar => $subValue ) { | ||
$this->execArgs[] = '--env'; | ||
$this->execArgs[] = "$subVar=$subValue"; | ||
} | ||
} else { | ||
$this->execArgs[] = '--env'; | ||
$this->execArgs[] = "$var=$value"; | ||
} | ||
} | ||
} | ||
|
||
return $this->execute( $command, $next ); | ||
} | ||
|
||
/** | ||
* Execute the pipe in the pipeline. | ||
* | ||
* @param \App\Services\CustomCommands\CommandDefinition $command | ||
* @param \Closure $next | ||
*/ | ||
abstract protected function execute( CommandDefinition $command, Closure $next ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Providers; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Providers; | ||
|
||
use App\Services\CustomCommands\CommandCollection; | ||
use App\Services\CustomCommands\CommandFactory; | ||
use App\Services\CustomCommands\CommandLoader; | ||
use App\Services\CustomCommands\Runners\HostCommandRunner; | ||
use App\Services\CustomCommands\Runners\MultiCommandRunner; | ||
use App\Services\CustomCommands\Runners\RunnerCollection; | ||
use App\Services\CustomCommands\Runners\ServiceCommandRunner; | ||
use Illuminate\Pipeline\Pipeline; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
/** | ||
* Custom command service. | ||
*/ | ||
class CustomCommandsServiceProvider extends ServiceProvider { | ||
|
||
public function register(): void { | ||
$this->app->bind( | ||
\Illuminate\Contracts\Pipeline\Pipeline::class, | ||
Pipeline::class | ||
); | ||
|
||
// The command runner pipes for the pipeline | ||
$this->app->bind( RunnerCollection::class, function () { | ||
return new RunnerCollection( [ | ||
MultiCommandRunner::class, | ||
HostCommandRunner::class, | ||
ServiceCommandRunner::class, | ||
] ); | ||
} ); | ||
|
||
// Custom commands from a project's squareone.yml | ||
$this->app->when( CommandFactory::class ) | ||
->needs( '$commands' ) | ||
->give( config( 'squareone.commands', [] ) ); | ||
|
||
$this->app->when( CommandLoader::class ) | ||
->needs( CommandCollection::class ) | ||
->give( function () { | ||
return $this->app->get( CommandFactory::class )->make(); | ||
} ); | ||
|
||
// Register custom commands | ||
$this->app->make( CommandLoader::class )->register(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Services\CustomCommands; | ||
|
||
use Illuminate\Foundation\Console\ClosureCommand as ConsoleClosureCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ClosureCommand extends ConsoleClosureCommand { | ||
|
||
/** | ||
* Overload the existing execute method and pass all inputs to the | ||
* callback. | ||
* | ||
* @param \Symfony\Component\Console\Input\InputInterface $input | ||
* @param \Symfony\Component\Console\Output\OutputInterface $output | ||
* | ||
* @return int | ||
*/ | ||
protected function execute( InputInterface $input, OutputInterface $output ): int { | ||
$inputs = array_merge( $input->getArguments(), $input->getOptions() ); | ||
|
||
// Sometimes we're receiving a duplicated command name at index 0. | ||
if ( isset( $inputs[0] ) ) { | ||
unset( $inputs[0] ); | ||
} | ||
|
||
return (int) $this->laravel->call( | ||
$this->callback->bindTo( $this, $this ), $inputs | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Services\CustomCommands; | ||
|
||
use Spatie\DataTransferObject\DataTransferObjectCollection; | ||
|
||
/** | ||
* A collection of custom command definitions. | ||
*/ | ||
class CommandCollection extends DataTransferObjectCollection { | ||
|
||
public function current(): CommandDefinition { | ||
return parent::current(); | ||
} | ||
|
||
} |
Oops, something went wrong.