Skip to content

Commit 3030d81

Browse files
author
Diego Hernandes
committed
Merge branch 'release/1.0.6'
2 parents 5bc697f + d8b76b0 commit 3030d81

File tree

9 files changed

+79
-46
lines changed

9 files changed

+79
-46
lines changed

bin/yoke

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ Y_PATH=$(which yokephp)
1010
Y_PHP_PATH=$(which php)
1111

1212
# If the current command is to connect.
13-
if [ "$Y_COMMAND" == "connect" ]; then
13+
if [ "${Y_COMMAND}" == "connect" ]; then
1414
# save the execution return into a variable for later parsing.
15-
Y_RETURN=$($Y_PHP_PATH $Y_PATH $Y_COMMAND $Y_ARGUMENT)
15+
Y_RETURN=$(${Y_PHP_PATH} ${Y_PATH} ${Y_COMMAND} ${Y_ARGUMENT})
1616
else
1717
# If the command is other than connect, pass through.
18-
$Y_PHP_PATH $Y_PATH $Y_COMMAND $Y_ARGUMENT
18+
${Y_PHP_PATH} ${Y_PATH} ${Y_COMMAND} ${Y_ARGUMENT}
1919
# Define a empty Y_RETURN
2020
Y_RETURN=""
2121
fi
2222

2323
# If the return starts with ssh.
24-
if [[ $Y_RETURN =~ ^ssh.* ]]; then
24+
if [[ ${Y_RETURN} =~ ^ssh.* ]]; then
2525
# Execute the returned line into the terminal (connect).
26-
$Y_RETURN
26+
${Y_RETURN}
2727
fi
2828

2929
# If the return starts with Password.
30-
if [[ $Y_RETURN =~ ^Password.* ]]; then
30+
if [[ ${Y_RETURN} =~ ^Password.* ]]; then
3131
# Break the return into the password helper and command variables.
32-
Y_PASSWORD_HELPER=$(echo -e "$Y_RETURN" | awk 'NR==1')
33-
Y_PASSWORD_COMMAND=$(echo -e "$Y_RETURN" | awk 'NR==2')
32+
Y_PASSWORD_HELPER=$(echo -e "${Y_RETURN}" | awk 'NR==1')
33+
Y_PASSWORD_COMMAND=$(echo -e "${Y_RETURN}" | awk 'NR==2')
3434

3535
# Display the
36-
echo $Y_PASSWORD_HELPER
37-
$Y_PASSWORD_COMMAND
38-
fi
36+
echo ${Y_PASSWORD_HELPER}
37+
${Y_PASSWORD_COMMAND}
38+
fi

src/Console/Commands/AddCommand.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
namespace Yoke\Console\Commands;
4+
use Symfony\Component\Console\Input\InputArgument;
5+
use Symfony\Component\Console\Input\InputInterface;
46

57
/**
68
* Class AddCommand.
@@ -19,20 +21,32 @@ class AddCommand extends BaseCommand
1921
*/
2022
protected $description = 'Store a new connection configuration.';
2123

24+
protected $arguments = [
25+
['alias', InputArgument::OPTIONAL, 'Connection Alias'],
26+
];
27+
2228
/**
2329
* Execute the command.
30+
*
31+
* @param InputInterface $input
2432
*/
25-
protected function fire()
33+
protected function fire(InputInterface $input)
2634
{
2735
// Greetings.
2836
$this->info('Registering a new Server Configuration!');
2937

3038
// Read initial connection data.
31-
$serverData['alias'] = $this->ask('Server connection alias (server1):', 'server1');
39+
if (!$serverData['alias'] = $input->getArgument('alias')) {
40+
$serverData['alias'] = $this->ask('Server connection alias (server1):', 'server1');
41+
}
42+
3243
$serverData['user'] = $this->ask('Server username (none):');
3344
$serverData['host'] = $this->ask('Server hostname or IP Address (192.168.0.1):', '192.168.0.1');
3445
$serverData['port'] = $this->ask('Server Port (22):', 22);
35-
$serverData['authenticationMethod'] = $this->ask('Authentication Method:[system|key|password] (system):', 'system');
46+
$serverData['authenticationMethod'] = $this->ask(
47+
'Authentication Method:[system|key|password] (system):',
48+
'system'
49+
);
3650

3751
if ($serverData['authenticationMethod'] == 'key') {
3852
// Ask for private key if key was selected as authentication method.

src/Console/Commands/BaseCommand.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ abstract class BaseCommand extends Command
5555
/**
5656
* Main Command method, calls the fire command on it's child commands.
5757
*
58-
* @param InputInterface $input Application provided input handler.
58+
* @param InputInterface $input Application provided input handler.
5959
* @param OutputInterface $output Application provided output handler.
60+
*
61+
* @return int|null|void
6062
*/
6163
protected function execute(InputInterface $input, OutputInterface $output)
6264
{
@@ -71,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7173
$this->manager = new Manager();
7274

7375
// Call the child command fire() method.
74-
$this->fire();
76+
return $this->fire($input);
7577
}
7678

7779
/**
@@ -93,15 +95,19 @@ protected function configure()
9395

9496
/**
9597
* Abstract fire method to be implemented on child commands.
98+
*
99+
* @param InputInterface $input
100+
*
101+
* @return
96102
*/
97-
abstract protected function fire();
103+
abstract protected function fire(InputInterface $input);
98104

99105
/**
100106
* Abstracts the question process into a single method.
101107
* Some options are defined by convention, like formatting.
102-
*
103-
* @param string $question The question being asked.
104-
* @param null $default Default value in case the user does not provide an answer.
108+
*
109+
* @param string $question The question being asked.
110+
* @param null $default Default value in case the user does not provide an answer.
105111
*
106112
* @return string The user input or the default value.
107113
*/
@@ -116,10 +122,10 @@ protected function ask($question, $default = null)
116122

117123
/**
118124
* Asks a Confirmation (Yes/No) Question.
119-
*
125+
*
120126
* Inputs like Y, Yes will make this method return true.
121127
* Any other input will return false.
122-
*
128+
*
123129
* @param string $question The question to be confirmed.
124130
*
125131
* @return bool Confirmed or Not.
@@ -149,7 +155,7 @@ protected function format($text, $type = 'info')
149155
/**
150156
* Write a string into the console output.
151157
*
152-
* @param string $text The string to be displayed.
158+
* @param string $text The string to be displayed.
153159
* @param string $format The coloring format.
154160
*/
155161
protected function writeln($text, $format = 'info')
@@ -160,7 +166,7 @@ protected function writeln($text, $format = 'info')
160166

161167
/**
162168
* Write a not formatted string into the console output.
163-
*
169+
*
164170
* @param string $text The string to be displayed.
165171
*/
166172
protected function writelnPlain($text)

src/Console/Commands/ConnectCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Yoke\Console\Commands;
44

55
use Symfony\Component\Console\Input\InputArgument;
6+
use Symfony\Component\Console\Input\InputInterface;
67

78
class ConnectCommand extends BaseCommand
89
{
@@ -26,8 +27,10 @@ class ConnectCommand extends BaseCommand
2627

2728
/**
2829
* Execute the command.
30+
*
31+
* @param InputInterface $input
2932
*/
30-
protected function fire()
33+
protected function fire(InputInterface $input)
3134
{
3235
// Gets the desired connection alias.
3336
$alias = $this->argument('alias');

src/Console/Commands/DeleteCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Yoke\Console\Commands;
44

55
use Symfony\Component\Console\Input\InputArgument;
6+
use Symfony\Component\Console\Input\InputInterface;
67

78
/**
89
* Class DeleteCommand.
@@ -29,7 +30,12 @@ class DeleteCommand extends BaseCommand
2930
['alias', InputArgument::REQUIRED, 'The connection to be removed.'],
3031
];
3132

32-
protected function fire()
33+
/**
34+
* Execute the command.
35+
*
36+
* @param InputInterface $input
37+
*/
38+
protected function fire(InputInterface $input)
3339
{
3440
// Find the server.
3541
$alias = $this->argument('alias');

src/Console/Commands/ServersCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Yoke\Console\Commands;
44

55
use Symfony\Component\Console\Helper\Table;
6+
use Symfony\Component\Console\Input\InputInterface;
67
use Yoke\Servers\Exceptions\NotFoundException;
78

89
/**
@@ -24,16 +25,18 @@ class ServersCommand extends BaseCommand
2425

2526
/**
2627
* Execute the command.
28+
*
29+
* @param InputInterface $input
2730
*/
28-
protected function fire()
31+
protected function fire(InputInterface $input)
2932
{
3033
// Get the available servers.
3134
$servers = $this->manager->getServers();
3235

3336
// If there is no servers registered.
3437
if (!count($servers)) {
3538
throw new NotFoundException('No servers available.');
36-
// Otherwise.
39+
// Otherwise.
3740
} else {
3841
// Render the servers table.
3942
$this->serversTable($servers);
@@ -55,6 +58,7 @@ protected function serversTable(array $servers)
5558

5659
// Loop on available connections to build the rows.
5760
$rows = [];
61+
5862
foreach ($servers as $server) {
5963
$rows[] = [$server->alias, $server->host, $server->user, $server->port, $server->authenticationMethod];
6064
}

src/Servers/Manager.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/**
99
* Class Manager.
10-
*
10+
*
1111
* Server connections manager.
1212
*/
1313
class Manager
@@ -50,22 +50,22 @@ protected function loadServers()
5050

5151
/**
5252
* Register a configuration array as a server instance.
53-
*
53+
*
5454
* @param array $data Server connection information.
5555
*/
5656
public function registerServer(array $data)
5757
{
58-
// Generate a new server connection instance.
58+
// Generate a new server connection instance.
5959
$server = new Server($data);
6060

61-
// Register the server connection into the servers list.
61+
// Register the server connection into the servers list.
6262
$this->servers[$server->alias] = $server;
6363
}
6464

6565
/**
6666
* Create a server connection instance with the provided configuration
6767
* data and write the configuration server with the updated information.
68-
*
68+
*
6969
* @param array $data Server connection information.
7070
*/
7171
public function createServer(array $data)
@@ -79,7 +79,7 @@ public function createServer(array $data)
7979

8080
/**
8181
* Deletes a server connection from instance and storage.
82-
*
82+
*
8383
* @param string $alias Alias of the server connection to be deleted.
8484
*/
8585
public function deleteServer($alias)
@@ -111,7 +111,7 @@ protected function writeServers()
111111

112112
/**
113113
* Get a server instance.
114-
*
114+
*
115115
* @param string $alias Server connection alias.
116116
*
117117
* @return Server The Server connection instance.
@@ -129,7 +129,7 @@ public function getServer($alias)
129129

130130
/**
131131
* Get all the server connection instances.
132-
*
132+
*
133133
* @return array A array containing all the server connection instances.
134134
*/
135135
public function getServers()
@@ -139,8 +139,8 @@ public function getServers()
139139

140140
/**
141141
* Is a given connection alias registered?
142-
*
143-
* @param string $alias The given server connection instance alias.
142+
*
143+
* @param string $alias The given server connection instance alias.
144144
*
145145
* @return bool Registered or not.
146146
*/

src/Servers/Server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public function __construct(array $config)
6969
/**
7070
* Magic __set method.
7171
*
72-
* @param string $key Attribute name.
73-
* @param mixed $value Attribute value
72+
* @param string $key Attribute name.
73+
* @param mixed $value Attribute value
7474
*/
7575
public function __set($key, $value)
7676
{

src/Storage/Manager.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public function getConfiguration($type = 'servers')
7676

7777
/**
7878
* Write a given array into a encrypted storage file.
79-
*
80-
* @param array $data The data to be stored.
79+
*
80+
* @param array $data The data to be stored.
8181
* @param string $type The actual filename without the .yml extension to store the information.
8282
*/
8383
public function writeConfiguration(array $data, $type = 'servers')
@@ -134,7 +134,7 @@ protected function path($file = null)
134134

135135
/**
136136
* Check for a file existence.
137-
*
137+
*
138138
* @param string $file Relative file name.
139139
*
140140
* @return bool Exists or not.
@@ -146,8 +146,8 @@ protected function fileExists($file)
146146

147147
/**
148148
* Create or replace a given file with the given contents.
149-
*
150-
* @param string $name File name.
149+
*
150+
* @param string $name File name.
151151
* @param string $contents File contents.
152152
*/
153153
protected function storeFile($name, $contents)
@@ -157,7 +157,7 @@ protected function storeFile($name, $contents)
157157

158158
/**
159159
* Reads a given file contents.
160-
*
160+
*
161161
* @param string $name Desired file.
162162
*
163163
* @return string The file contents.

0 commit comments

Comments
 (0)