Skip to content

Commit d864e72

Browse files
committed
Allow to run tasks on localhost if no host is defined
1 parent 458d7b6 commit d864e72

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/Command/SelectCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
use Deployer\Deployer;
1111
use Deployer\Exception\Exception;
1212
use Deployer\Host\Host;
13+
use Deployer\Host\Localhost;
1314
use Symfony\Component\Console\Command\Command;
1415
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
1516
use Symfony\Component\Console\Helper\QuestionHelper;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputInterface as Input;
1819
use Symfony\Component\Console\Output\OutputInterface as Output;
1920
use Symfony\Component\Console\Question\ChoiceQuestion;
21+
use function Deployer\localhost;
2022

2123
abstract class SelectCommand extends Command
2224
{
@@ -43,7 +45,9 @@ protected function selectHosts(Input $input, Output $output): array
4345
$selectExpression = is_array($selector) ? implode(',', $selector) : $selector;
4446

4547
if (empty($selectExpression)) {
46-
if (count($this->deployer->hosts) === 1) {
48+
if (count($this->deployer->hosts) === 0) {
49+
$hosts = [localhost(Localhost::extraordinary)];
50+
} else if (count($this->deployer->hosts) === 1) {
4751
$hosts = $this->deployer->hosts->all();
4852
} else if ($input->isInteractive()) {
4953
$hostsAliases = [];

src/Command/WorkerCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Input\InputInterface;
1515
use Symfony\Component\Console\Input\InputOption as Option;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use function Deployer\localhost;
1718

1819
class WorkerCommand extends MainCommand
1920
{
@@ -47,8 +48,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4748
$task = $this->deployer->tasks->get($input->getOption('task'));
4849

4950
$hostName = $input->getOption('host');
50-
if ($hostName === 'local') {
51-
$host = new Localhost('local');
51+
if ($hostName === Localhost::extraordinary) {
52+
$host = localhost(Localhost::extraordinary);
5253
} else {
5354
$host = $this->deployer->hosts->get($input->getOption('host'));
5455
$host->config()->load();

src/Host/Localhost.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
class Localhost extends Host
1111
{
12+
const extraordinary = '@localhost';
13+
1214
public function __construct(string $hostname = 'localhost')
1315
{
1416
parent::__construct($hostname);

0 commit comments

Comments
 (0)