Skip to content

Commit

Permalink
upgrade to php 8
Browse files Browse the repository at this point in the history
  • Loading branch information
avramovic committed May 14, 2022
1 parent 8371365 commit 36a8a17
Show file tree
Hide file tree
Showing 10 changed files with 432 additions and 121 deletions.
13 changes: 10 additions & 3 deletions Commands/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

use SSHConf\SSHConf;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\OutputInterface;

abstract class BaseCommand extends Command
{
protected static $defaultName = null;
protected $sshConf;
/** @var OutputInterface */
protected $output;
protected SSHConf $sshConf;
protected OutputInterface $output;

public function __construct()
{
Expand Down Expand Up @@ -42,4 +42,11 @@ public function setOutput(&$output)
{
$this->output = $output;
}

public function runCommand(string $cmd, ?array $args = [])
{
$command = $this->getApplication()->find($cmd);

return $command->run(new ArrayInput($args), $this->output);
}
}
2 changes: 2 additions & 0 deletions Commands/EditHostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln('');
$this->info(sprintf('Successfully edited "%s" SSH connection.', $host));

return 0;
}
}
4 changes: 3 additions & 1 deletion Commands/ListHostsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$data = [];

foreach ($this->sshConf->all() as $host => $conf) {
$data[] = [$host, $conf['hostname'] . ($conf['port'] ? ':'.$conf['port'] : ''), $conf['user'] ?? get_current_user()];
$data[] = [$host, $conf['hostname'] . (isset($conf['port']) ? ':'.$conf['port'] : ''), $conf['user'] ?? get_current_user()];
}

$table = new Table($output);
Expand All @@ -34,5 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
->setHeaderTitle('SSH connections')
->setFooterTitle('Total: '.count($this->sshConf->all()))
->render();

return 0;
}
}
2 changes: 2 additions & 0 deletions Commands/RemoveHostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->sshConf->remove($host)->save();

$this->info(sprintf('Successfully removed "%s" SSH connection.', $host));

return 0;
}
}
2 changes: 2 additions & 0 deletions Commands/ViewHostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
->setHeaderTitle('SSH: '.$host)
->setFooterTitle('Total: '.count($data))
->render();

return 0;
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Small CLI utility to manage ssh config file on Linux/Mac
## Requirements

* wget or cURL
* PHP 7.1
* PHP 8.0

## Installation

Expand Down
14 changes: 7 additions & 7 deletions SSHConf/SSHConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

class SSHConf
{


/**
* @var null
*/
protected $sshConfFile;
public $sshConf = [];
protected string $sshConfFile;
protected array $sshConf = [];

public function __construct($sshConfFile = null)
{
Expand Down Expand Up @@ -94,6 +89,11 @@ public function all()
return $this->sshConf;
}

public function count()
{
return count($this->sshConf);
}

public function dump()
{
$text = '';
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
}
],
"require": {
"symfony/console": "^4.3"
"symfony/console": "^6",
"symfony/process": "^6.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 36a8a17

Please sign in to comment.