Skip to content
/ cli Public
forked from spatie/ssh

A lightweight package to execute commands over an SSH connection

License

Notifications You must be signed in to change notification settings

ramonpego/cli

 
 

Repository files navigation

A lightweight package to execute commands on your local machine.

Latest Version on Packagist GitHub Tests Action Status Quality Score Total Downloads

You can execute a command on your local machine like this:

CLI::create('path', 'user')->execute('your favorite command');

It will return an instance of Symfony's Process.

This package is based on the spatie/ssh package please consider support them.

Support them

Installation

You can install the package via composer:

composer require spatie/ssh

Usage

You can execute an SSH command like this:

$process = CLI::create('path', 'user')->execute('your favorite command');

It will return an instance of Symfony's Process.

If you don't want to wait until the execute commands complete, you can call executeAsync

$process = CLI::create('path', 'user')->executeAsync('your favorite command');

Getting the result of a command

To check if your command ran ok

$process->isSuccessful();

This is how you can get the output

$process->getOutput();

Running multiple commands

To run multiple commands pass an array to the execute method.

$process = CLI::create('path', 'user')->execute([
   'first command',
   'second command',
]);

Modifying the Symfony process

Behind the scenes all commands will be performed using Symfonys Process.

You can configure to the Process by using the configureProcess method. Here's an example where we disable the timeout.

CLI::create('user', 'host')->configureProcess(fn (Process $process) => $process->setTimeout(null));

Immediately responding to output

You can get notified whenever your command produces output by passing a closure to onOutput.

CLI::create('user', 'host')->onOutput(fn($type, $line) => echo $line)->execute('whoami');

Whenever there is output that closure will get called with two parameters:

  • type: this can be Symfony\Component\Process\Process::OUT for regular output and Symfony\Component\Process\Process::ERR for error output
  • line: the output itself

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email ramon.pego.stl@gmail.com instead of using the issue tracker.

Credits

The CLI class contains code taken from laravel/envoy

License

The MIT License (MIT). Please see License File for more information.

About

A lightweight package to execute commands over an SSH connection

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%