SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

Add interface to SshCommand

Open eugencowie opened this issue 1 year ago • 3 comments

Changes:

  • Add ISshCommand interface containing all public properties and methods of SshCommand
  • Update SshClient methods to return ISshCommand instead of SshCommand

Closes #1507

eugencowie avatar Sep 26 '24 16:09 eugencowie

I am a bit uneasy about this one because of the breaking changes it introduces

Rob-Hague avatar Oct 06 '24 12:10 Rob-Hague

what exact breaking change are you referring to? As I understand the only problem might occur if the user had a code like this

SshCommand command = client.CreateCommand("ls");

But this code would be quite rare as the modern preferred coding style is

var command = client.CreateCommand("ls");

Every release there are small breaking changes. This change won't be very big and would be caught during compile time.

We might introduce another interface ISshClient2 which returns ISshCommand instead of SshCommand. But it won't make much sense as we anyway have to replace the main interface ISsshClient with it.

k0ka avatar Jul 31 '25 10:07 k0ka

Yes that is the breaking change I am referring to.

But this code would be quite rare as the modern preferred coding style is

It is not my preferred coding style :-)

The breaking changes in each release are considered based on how many people it is going to benefit vs inconvenience. You can see my thoughts on mocking the library here https://github.com/sshnet/SSH.NET/issues/1667#issuecomment-3065200031, but in short, I don't consider it an important feature for which is worth inconveniencing an unknown but possibly large number of people.

If we want to compare the proposed change here against prior changes:

  1. #812. IMO this was a mistake. Even so, it is less inconvenient than this change due to implicit conversion in foreach loops (so foreach (SftpFile file in client.ListDirectory(...)) still compiles)
  2. #1628. Also a breaking change, but since these interfaces seem to only exist for people to mock, then it is more like "you get what you asked for"

Rob-Hague avatar Aug 03 '25 17:08 Rob-Hague