Open Hamzali opened 4 years ago
@apocas would it be wise for us to consider exposing this as a utility function for users of the lib to call so that they may explicitly pass this into the constructor rather than it being auto-populated? This can avoid some ambiguity with the options being passed in and how they're manipulated. Or if a null
or undefined
is passed as the constructor, it'll use the defaults, but an empty object {}
should be treated as user wants to supply their own configs and if any critical configs are missing, then we should throw an error from the constructor.
Examples
new Docker(); // uses the defaultOpts function
new Docker({}); // does not use defaultOpts function, will throw an error since neither socketPath nor host/port is defined
new Docker({ host: '10.0.0.123' }); // host is defined, defaultOpts should not be called, but will throw error for missing port parameter
This will result in a major revision since this is technical breaking changes as we're going to be modifying the default behavior. If we can come to a consensus here, I can start a PR with these changes.
I understand that defaultOpts
function does a few more things, we'll likely want to move those out of the function to set up the initial states.
Thanks for all the hard work! Let me know what you and other folks think is the best way forward.
Lines in question here for reference: https://github.com/apocas/docker-modem/blob/3e3bb249d8e247af4c9aafba25c015d7488688f6/lib/modem.js#L16-L69
Hello and thanks for terrific package :)
I followed the examples in the readme and did:
But it would still connect to the default unix socket. Finally I figured out that explicitly setting socketPath to null I could get it to respect the options. I.e. this works:
the solution lies under here, it should first check for http then go for socket option; in
lib/modem.js