Repository: conan-io/conan

Issue:
Proper error message using conan remote disable/enable if remote doesn't exist
Using Conan 1.19 you will be able to enable or disable remotes with `conan remote enable/disable remote_name`. If the remote does not exist there is no error message. There should be one error message in this case.

To help us debug your issue please explain:

- [X] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [X] I've specified the Conan version, operating system version and any tool that can be relevant.
- [X] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.




Discussion:
Should there also be an error on enabling remotes that are already enabled?


Resolving patch:
diff --git a/conans/client/cache/remote_registry.py b/conans/client/cache/remote_registry.py
--- a/conans/client/cache/remote_registry.py
+++ b/conans/client/cache/remote_registry.py
@@ -185,12 +185,16 @@ def set_disabled_state(self, remote_name, state):
         filtered_remotes = []
         for remote in self._remotes.values():
             if fnmatch.fnmatch(remote.name, remote_name):
-                if remote.disabled != state:
-                    filtered_remotes.append(remote.name)
-        for r in filtered_remotes:
-            remote = self._remotes[r]
-            self._remotes[r] = Remote(remote.name, remote.url,
-                                      remote.verify_ssl, state)
+                filtered_remotes.append(remote)
+
+        if not filtered_remotes and not "*" in remote_name:
+            raise NoRemoteAvailable("Remote '%s' not found in remotes" % (remote_name))
+
+        for remote in filtered_remotes:
+            if remote.disabled == state:
+                continue
+            self._remotes[remote.name] = Remote(remote.name, remote.url,
+                                                remote.verify_ssl, state)
 
     def get_remote(self, remote_name):
         # Returns the remote defined by the name, or the default if is None


Test patch:
diff --git a/conans/test/functional/command/remote_test.py b/conans/test/functional/command/remote_test.py
--- a/conans/test/functional/command/remote_test.py
+++ b/conans/test/functional/command/remote_test.py
@@ -338,6 +338,32 @@ def remote_disable_test(self):
         for remote in data["remotes"]:
             self.assertNotIn("disabled", remote)
 
+    def invalid_remote_disable_test(self):
+        client = TestClient()
+
+        client.run("remote disable invalid_remote", assert_error=True)
+        self.assertIn("ERROR: Remote 'invalid_remote' not found in remotes",
+                      client.out)
+
+        client.run("remote enable invalid_remote", assert_error=True)
+        self.assertIn("ERROR: Remote 'invalid_remote' not found in remotes",
+                      client.out)
+
+        client.run("remote disable invalid_wildcard_*")
+
+    def remote_disable_already_set_test(self):
+        """
+        Check that we don't raise an error if the remote is already in the required state
+        """
+        client = TestClient()
+
+        client.run("remote add my-remote0 http://someurl0")
+        client.run("remote enable my-remote0")
+        client.run("remote enable my-remote0")
+
+        client.run("remote disable my-remote0")
+        client.run("remote disable my-remote0")
+
     def verify_ssl_error_test(self):
         client = TestClient()
         client.run("remote add my-remote http://someurl some_invalid_option=foo", assert_error=True)