Skip to content

Commit

Permalink
Merge pull request #2 from pantheon-systems/drush
Browse files Browse the repository at this point in the history
Better remote command support.
  • Loading branch information
Josh Koenig committed Feb 25, 2014
2 parents d5291b4 + 6a1a2ac commit 99cce1a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
5 changes: 4 additions & 1 deletion php/Terminus/CommandWithSSH.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ protected function send_command($server, $remote_exec, $args, $assoc_args) {
$cmd = 'ssh -T ' . $server['user'] . '@' . $server['host'] . ' -p ' . $server['port'] . ' -o "AddressFamily inet"' . " '" . $remote_cmd . "'";

passthru( $cmd, $exit_code );
exit( $exit_code );
if ($result == 255) {
\Terminus::error("Failed to connect. Check your credentials, and that you are specifying a valid environment.");
}
return( $exit_code );
}
}
12 changes: 4 additions & 8 deletions php/commands/drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,19 @@ function __invoke( $args, $assoc_args ) {
Terminus::error("Command could not be completed.");
exit;
}
# TODO: validate environment quickly.
#if (!isset($site->environments->$environment)) {
# Terminus::error("The '$environment' environment does not exist.");
#}

# see https://github.com/pantheon-systems/titan-mt/blob/master/dashboardng/app/workshops/site/models/environment.coffee
$server = Array(
'user' => "$environment.$site->site_uuid",
'host' => "appserver.$environment.$site->site_uuid.drush.in",
'port' => '2222'
);

# Sanitize assoc args.
# Sanitize assoc args so we don't try to pass our own flags.
# TODO: DRY this out?
unset($assoc_args['site']);
if (isset($assoc_args['environment'])) {
unset($assoc_args['environment']);
}

# Create user-friendly output
$command = implode( $args, ' ' );
$flags = '';
Expand All @@ -64,7 +60,7 @@ function __invoke( $args, $assoc_args ) {
$flags .= "--$k";
}
}
Terminus::line( "Running drush $command $flags against $site_name-$environment" );
Terminus::line( "Running drush $command $flags on $site_name-$environment" );
$this->send_command($server, 'drush', $args, $assoc_args );
}

Expand Down
11 changes: 5 additions & 6 deletions php/commands/wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ function __invoke( $args, $assoc_args ) {
Terminus::error("Command could not be completed.");
exit;
}
# TODO: validate environment quickly.
#if (!isset($site->environments->$environment)) {
# Terminus::error("The '$environment' environment does not exist.");
#}

# see https://github.com/pantheon-systems/titan-mt/blob/master/dashboardng/app/workshops/site/models/environment.coffee
$server = Array(
Expand All @@ -48,11 +44,13 @@ function __invoke( $args, $assoc_args ) {
'port' => '2222'
);

# Sanitize assoc args.
# Sanitize assoc args so we don't try to pass our own flags.
# TODO: DRY this out?
unset($assoc_args['site']);
if (isset($assoc_args['environment'])) {
unset($assoc_args['environment']);
}

# Create user-friendly output
$command = implode( $args, ' ' );
$flags = '';
Expand All @@ -64,8 +62,9 @@ function __invoke( $args, $assoc_args ) {
$flags .= "--$k";
}
}
Terminus::line( "Running wp-cli $command $flags against $site_name-$environment" );
Terminus::line( "Running drush $command $flags on $site_name-$environment" );
$this->send_command($server, 'wp', $args, $assoc_args );

}

}
Expand Down

0 comments on commit 99cce1a

Please sign in to comment.