Repository: conan-io/conan

Issue:
conan user -r=remote shows all the user, not the one for the given remote
To help us debug your issue please explain:

- [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.

Conan 1.0
Steps: Define several remotes, type ``conan user -r=asdasdas`` (whatever remote name). The remote name is not checked at all.




Discussion:

Resolving patch:
diff --git a/conans/client/manager.py b/conans/client/manager.py
--- a/conans/client/manager.py
+++ b/conans/client/manager.py
@@ -533,7 +533,9 @@ def user(self, remote=None, name=None, password=None):
             if not remote:
                 remote = remote_proxy.registry.default_remote.name
             name, password = self._user_io.request_login(remote_name=remote, username=name)
-        return remote_proxy.authenticate(name, password)
+
+        all_remotes = True if remote is None else False
+        return remote_proxy.authenticate(name, password, all_remotes=all_remotes)
 
     def get_path(self, reference, package_id=None, path=None, remote=None):
         remote_proxy = ConanProxy(self._client_cache, self._user_io, self._remote_manager, remote)
diff --git a/conans/client/proxy.py b/conans/client/proxy.py
--- a/conans/client/proxy.py
+++ b/conans/client/proxy.py
@@ -395,13 +395,22 @@ def _retrieve_remote_package(self, package_ref, package_folder, output, remote=N
             output.warn('Binary for %s not in remote: %s' % (package_id, str(e)))
             return False
 
-    def authenticate(self, name, password):
-        if not name:  # List all users, from all remotes
-            remotes = self._registry.remotes
-            if not remotes:
-                self._out.error("No remotes defined")
-            for remote in remotes:
-                self._remote_manager.authenticate(remote, None, None)
-            return
-        remote, _ = self._get_remote()
-        return self._remote_manager.authenticate(remote, name, password)
+    def authenticate(self, name, password, all_remotes=False):
+        """
+        Manage user auth against remote.
+        Also displays a list of authenticated users against remote(s) if user name is evaluated to False.
+
+        :param name: user name string
+        :param password: password string
+        :param all_remotes: True/False to use all available remotes to display a list of authenticated users if
+                            user name is evaluated to False.
+        """
+        current_remote, _ = self._get_remote()
+
+        if name:
+            return self._remote_manager.authenticate(current_remote, name, password)
+
+        # List all users from required remotes
+        remotes = self._registry.remotes if all_remotes else [current_remote]
+        for remote in remotes:
+            self._remote_manager.authenticate(remote, None, None)


Test patch:
diff --git a/conans/test/command/user_test.py b/conans/test/command/user_test.py
--- a/conans/test/command/user_test.py
+++ b/conans/test/command/user_test.py
@@ -4,13 +4,44 @@
 
 class UserTest(unittest.TestCase):
 
-    def test_command_user(self):
-        """ Test that the user can be shown and changed, and it is reflected in the
-        user cache localdb
+    def test_command_user_no_remotes(self):
+        """ Test that proper error is reported when no remotes are defined and conan user is executed
         """
         client = TestClient()
-        client.run('user')
-        self.assertIn("ERROR: No remotes defined", client.user_io.out)
+        with self.assertRaises(Exception):
+            client.run("user")
+        self.assertIn("ERROR: No default remote defined", client.user_io.out)
+
+        with self.assertRaises(Exception):
+            client.run("user -r wrong_remote")
+        self.assertIn("ERROR: No remote 'wrong_remote' defined", client.user_io.out)
+
+    def test_command_user_list(self):
+        """ Test list of user is reported for all remotes or queried remote
+        """
+        servers = {
+            "default": TestServer(),
+            "test_remote_1": TestServer(),
+        }
+        client = TestClient(servers=servers)
+
+        # Test with wrong remote right error is reported
+        with self.assertRaises(Exception):
+            client.run("user -r Test_Wrong_Remote")
+        self.assertIn("ERROR: No remote 'Test_Wrong_Remote' defined", client.user_io.out)
+
+        # Test user list for requested remote reported
+        client.run("user -r test_remote_1")
+        self.assertIn("Current 'test_remote_1' user: None (anonymous)", client.user_io.out)
+        self.assertNotIn("Current 'default' user: None (anonymous)", client.user_io.out)
+
+        # Test user list for all remotes is reported
+        client.run("user")
+        self.assertIn(
+            ("Current 'default' user: None (anonymous)\n"
+             "Current 'test_remote_1' user: None (anonymous)"),
+            client.user_io.out
+        )
 
     def test_with_remote_no_connect(self):
         test_server = TestServer()