Automatic client API version downgrading

Since the client knows the version of the server is mismatched:

Error response from daemon: client and server don't have same version (client : 1.24, server: 1.18)

and it is possible to downgrade the client by exporting DOCKER_API_VERSION it would be very helpful if the downgrade could happen automatically, perhaps with a warning logged.

Since the version endpoint of the API is versioned it is not possible to interrogate the server and downgrade programatically:

version=$(docker version --format '{{.Server.Version}}' | tr -d "\-[a-z]")
export DOCKER_API_VERSION=${version}

due to the chicken-and-egg problem of having a mismatched client to begin with.