yanne / api-test

0 stars 0 forks source link

Add support to naming arguments passed to `SSHClient` to ease programmatic usage #97

Closed yanne closed 10 years ago

yanne commented 10 years ago

Currently SSHClient (PythonSSHClient or JavaSSHClient, depending on the interpreter) only accepts *args that it (they) pass to AbstractSSHClient. When using the client programmatically, needing to pass all arguments positionally isn't convenient. It would be better to be able to use something like this:

client = SSHClient('example.com', width=120, heigh=40)

There are two ways to implement this:

1) Add also **kwargs to SSHClient and pass both *args and **kwargs to AbstractSSHClient.

This is trivial to implement and shouldn't have any risks. A problem is that by looking at SSHClient alone, for example using introspection, you cannot see what arguments it actually accepts. This problem obviously exists already now.

2) Change PythonSSHClient and JavaSSHClient so that they don't have init at all. Currently they just call parent class init and set self.client. We could change AbstractSSHClient so that the last step in its init would be self.client = self._get_client() and extending classes would implement _get_client as needed.

A benefit of this approach is that SSHClient arguments are directly visible because init is inherited directly from AbstractSSHClient. This isn't too complicated to implement either. There is a small risk that in the future there would be more needs for extending classes to inherit init. It would be easy to start using _args and *_kwargs then if needed, though.

Needed by a team at NSN using SSHClient programmatically. Targeting to 2.0.1 with high priority, but target can obviously change to 2.1 if that's the next release.

This issue was originally opened at Google Code on Jan 16, 2014.

yanne commented 10 years ago

Original comment by tatu.ka...@eficode.com on Jan 31, 2014.

This issue was updated by revision e0a855a16161 .

Removed init from subclasses, made method for subclasses to to initialize the client

yanne commented 10 years ago

Original comment by pekka.klarck on Feb 3, 2014.

Looks good. Closing.