Repository: gabrieldemarmiesse/python-on-whales (language: python)

Issue:
context.use does not return a context object
`docker.context.create` returns a `context` object which can be later used in a `DockerClient`
```
context = docker.context.create(
                    context, 
                    docker=DockerContextConfig(host=base_url)
                ) 

print(type(context))
<class 'python_on_whales.components.context.cli_wrapper.Context'>
```
However if the context already exists a `DockerException` is thrown:
```
context = docker.context.create(
                    context, 
                    docker=DockerContextConfig(host=base_url)
                ) 

python_on_whales.exceptions.DockerException: The docker command executed was `/.cache/python-on-whales/docker-cli/20.10.5/docker context create --docker host=ssh://root@192.168.64.11,skip-tls-verify=False 192.168.64.11`.
It returned with code 1
The content of stdout is ''
The content of stderr is 'context "192.168.64.11" already exists
```
Calling `docker.context.use("192.168.64.11")` only switches to the context but does not return a context object making it very difficult to create a `DockerClient` with a context.


Discussion / hints:
I think a workaround would be to use `docker.context.inspect()` to get the Context object, which is itself a context manager. But indeed it would be nice if the context could be returned with `docker.context.use()`. I'm open to a pull request to return the object.

Fix patch:
diff --git a/python_on_whales/components/context/cli_wrapper.py b/python_on_whales/components/context/cli_wrapper.py
index 625510cf..9f2af125 100644
--- a/python_on_whales/components/context/cli_wrapper.py
+++ b/python_on_whales/components/context/cli_wrapper.py
@@ -231,3 +231,4 @@ def use(self, context: ValidContext):
         """
         full_cmd = self.docker_cmd + ["context", "use", context]
         run(full_cmd)
+        return self.inspect(context)


Test patch:
diff --git a/tests/python_on_whales/components/test_context.py b/tests/python_on_whales/components/test_context.py
index e85fcf49..0160885d 100644
--- a/tests/python_on_whales/components/test_context.py
+++ b/tests/python_on_whales/components/test_context.py
@@ -48,6 +48,10 @@ def test_use_context():
     docker.context.use("default")
 
 
+def test_use_context_returns():
+    assert docker.context.use("default") == docker.context.inspect("default")
+
+
 def test_remove_empty_context_list():
     all_contexts = set(docker.context.list())
     docker.context.remove([])