diff --git a/shub/login.py b/shub/login.py index af5f8aac..4699e078 100644 --- a/shub/login.py +++ b/shub/login.py @@ -10,7 +10,8 @@ @click.pass_context def cli(context): if auth.get_key_netrc(): - context.fail('Already logged in. To logout use: shub logout') + log("You're already logged in. To change credentials, use 'shub logout' first.") + return 0 cfg_key = _find_cfg_key() key = _prompt_for_key(suggestion=cfg_key) diff --git a/tests/test_login.py b/tests/test_login.py index 48ba3b9b..00c195ea 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -65,3 +65,17 @@ def test_login_can_handle_invalid_scrapy_cfg(self): # then self.assertEqual(0, result.exit_code, result.exception) + + def test_login_attempt_after_login_doesnt_lead_to_an_error(self): + with self.runner.isolated_filesystem() as fs: + login.auth.NETRC_FILE = os.path.join(fs, '.netrc') + + # given + self.runner.invoke(login.cli, input=self.VALID_KEY) + + # when + result = self.runner.invoke(login.cli, input=self.VALID_KEY) + + # then + self.assertEqual(0, result.exit_code) + self.assertTrue('already logged in' in result.output)