Skip to content

Add result handler to run command #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wagnert
Copy link

@wagnert wagnert commented Jun 15, 2015

Hi,

first i want to say, thanks for that awesome piece of code 👍

We've the requirement, that we want to execute a remote command by invoking the run() method and need to have access to the result.

<?php

return array(

    'hosts' => array(
        'jenkins' => '127.0.0.1',
    ),

    'auth' => array(
        'username' => 'root',
        'password' => NULL,
        'pubkeyfile' => '/home/user/.ssh/id_rsa.pub',
        'privkeyfile' => '/home/user/.ssh/id_rsa',
        'passphrase' => NULL,
    ),

    'tasks' => array(
        'download_test' => function($s) {

            $local = '';
            if (is_file('/tmp/test_encoded.php')) {
                $local = md5_file('/tmp/test_encoded.php');
            }

            $remote = '';
            $resultHandler = function ($resultDio) use (&$remote) {
                $result = explode('  ', $resultDio);
                $remote = array_shift($result);
            };

            $s->run('md5sum test_encoded.php', false, $resultHandler);

            if ($local === $remote) {
                error_log(sprintf('Hashes ARE equal %s/%s', $local, $remote));
            } else {
                error_log(sprintf('Hashes are NOT equal %s/%s', $local, $remote));
                $s->scp()->get('test_encoded.php', '/tmp/test_encoded.php');
            }
        }
    ),
);

The pull request added a third parameter that allows you to specify a closure that can be used to access the command's result. Actually i think there is no possibility to do this, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant