Skip to content

Commit

Permalink
shell commands refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-ivona committed Jan 9, 2021
1 parent 4fecd8a commit 8822260
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 133 deletions.
2 changes: 0 additions & 2 deletions app/Containers/Commands/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ class Composer extends Command

protected $signature = 'composer';
protected $description = 'Runs a composer command';

protected string $target_command = 'composer';
}
47 changes: 10 additions & 37 deletions app/Containers/Commands/Node.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,18 @@
<?php /** @noinspection PhpUnhandledExceptionInspection */
<?php
/** @noinspection PhpUnhandledExceptionInspection */

/** @noinspection PhpMissingFieldTypeInspection */


namespace App\Containers\Commands;

use App\Services\DockerService;
use App\Services\TerminalService;
use LaravelZero\Framework\Commands\Command;
use App\Traits\ExecutesShellCommands;
use LaravelZero\Framework\Commands\Command;

class Node extends Command{
protected $signature = 'node';
class Node extends Command
{
use ExecutesShellCommands;

protected $description = 'Runs a node command';

public function __construct()
{
parent::__construct();
$this->ignoreValidationErrors();
}

public function handle(DockerService $docker_service, TerminalService $terminal): int
{
$terminal->init($this->output);

$arguments = (string) $this->input;

if (empty($arguments)) {
$this->info('Log into Node Shell');

return $terminal->execute([
'docker-compose',
'run',
'--rm',
'node',
'bash',
]);
} else {
$node_commands = explode(' ', $arguments);
$commands = array_merge(['node'], $node_commands);
return $docker_service->service('node')->run($terminal, $commands);
}
}
}
protected $signature = 'node';
protected $description = 'Runs a node command';
}
1 change: 0 additions & 1 deletion app/Containers/Commands/Npm.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ class Npm extends Command
protected $description = 'Runs an npm command';

protected string $target_service = 'node';
protected string $target_command = 'npm';
}
44 changes: 9 additions & 35 deletions app/Containers/Commands/Php.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,15 @@
<?php


namespace App\Containers\Commands;
namespace App\Containers\Commands;

use App\Exceptions\DockerServiceNotFoundException;
use App\Services\DockerService;
use App\Services\TerminalService;
use Illuminate\Contracts\Container\BindingResolutionException;
use LaravelZero\Framework\Commands\Command;
use App\Traits\ExecutesShellCommands;
use LaravelZero\Framework\Commands\Command;

class Php extends Command{
protected $signature = 'php
{commands* : php commands to execute} ';
class Php extends Command
{
use ExecutesShellCommands;

protected $description = 'Executes an php command';

/**
* @param DockerService $docker_service
* @param TerminalService $terminal
* @return int
* @throws DockerServiceNotFoundException
* @throws BindingResolutionException
*/
public function handle(DockerService $docker_service, TerminalService $terminal){

$terminal->init($this->output);

$commands = [
"php",
];

$composer_commands = $this->argument("commands");
if(!empty($composer_commands)){
$commands = array_merge($commands, $composer_commands);
}
return $docker_service->service('php')->execute($terminal, $commands);


}
}
protected $signature = 'php';
protected $description = 'Executes an php command';
}
43 changes: 5 additions & 38 deletions app/Recipes/Laravel/Commands/Artisan.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,15 @@
namespace App\Recipes\Laravel\Commands;


use App\Exceptions\DockerServiceNotFoundException;
use App\Services\DockerService;
use App\Services\TerminalService;
use Illuminate\Contracts\Container\BindingResolutionException;
use App\Traits\ExecutesShellCommands;
use LaravelZero\Framework\Commands\Command;

class Artisan extends Command{
protected $signature = 'artisan
{commands?* : artisan commmands to execute}
';
use ExecutesShellCommands;

protected $signature = 'artisan';
protected $description = 'Executes an Artisan command';

/**
* @param DockerService $docker_service
* @param TerminalService $terminal
* @return int
* @throws DockerServiceNotFoundException
* @throws BindingResolutionException
*/
public function handle(DockerService $docker_service, TerminalService $terminal){

$terminal->init($this->output);

$artisan_commands = $this->argument("commands");

if(empty($artisan_commands)){
$this->info('Log into Artisan Shell');

return $terminal->execute([
'docker-compose',
'exec',
'php',
'bash',
]);
}else{
$commands = array_merge(['php', 'artisan'], $artisan_commands);
return $docker_service->service('php')->execute($terminal, $commands);
}




}
protected string $target_service = 'php';
protected string $target_command = 'php';
}
1 change: 1 addition & 0 deletions app/Recipes/Laravel/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function handle(DockerService $docker_service, TerminalService $terminal)

if(!$this->task("Laravel Installation", function()use($docker_service, $terminal){
return $docker_service->service('composer')->run($terminal, [
"composer",
"create-project",
'--prefer-dist',
'laravel/laravel',
Expand Down
1 change: 0 additions & 1 deletion app/Recipes/Laravel/Commands/Larastan.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function handle(DockerService $docker_service, TerminalService $terminal)

$terminal->init($this->output);


$commands = array_merge([
'php',
'./vendor/bin/phpstan',
Expand Down
2 changes: 1 addition & 1 deletion app/Traits/ExecutesShellCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function handle(DockerService $docker_service, TerminalService $terminal)

$arguments = (string) $this->input;

if (empty($arguments)) {
if ($arguments==$target_command) {
$this->info('Log into Shell');

return $terminal->execute([
Expand Down
18 changes: 0 additions & 18 deletions app/Updater/GithubStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,14 @@

namespace App\Updater;

use Humbug\SelfUpdate\Updater;
use Illuminate\Support\Str;
use LaravelZero\Framework\Components\Updater\Strategy\StrategyInterface;

final class GithubStrategy extends \Humbug\SelfUpdate\Strategy\GithubStrategy implements StrategyInterface
{
public function getCurrentLocalVersion(Updater $updater): string
{
$version = parent::getCurrentLocalVersion($updater);

echo "Local version: {$version}\n";
return $version;
}

public function getCurrentRemoteVersion(Updater $updater): string
{
$version = parent::getCurrentRemoteVersion($updater);
echo "Remote version: {$version}\n";
return $version;
}

protected function getDownloadUrl(array $package): string
{
$url = parent::getDownloadUrl($package);
return Str::of($url)->append('dock');
}


}

0 comments on commit 8822260

Please sign in to comment.