Repository: Benexl/FastAnime

Issue:
[bug] only output the completions
Currently when you run the completions subcommand it will output the completions and some logs:
```sh
$ fastanime completions
Checking for updates...
So you can enjoy the latest features and bug fixes
You can disable this by setting check_for_updates to False in the config

<actual completions>
```

This however is problematic when you want to load the completions with an eval:
```sh
eval "$(fastanime completions)"
```

A workaround for this is to cut the first 3 lines of the output:
```sh
eval "$(fastanime completions | tail -n +4)"
```

Discussion:
@Benexl: hmm, forgot it would affect that, maybe the info for checking for update should be printed to stderr instead of stdout. Would you like to tackle this one? @she11sh0cked: I could certainly try this evening :) But wouldn't it be better to just skip the check for the completions subcommand?@Benexl: If you can implement it that way fine by me.

Solution patch:
diff --git a/fastanime/cli/__init__.py b/fastanime/cli/__init__.py
index 21c9159..be4c294 100644
--- a/fastanime/cli/__init__.py
+++ b/fastanime/cli/__init__.py
@@ -226,7 +226,7 @@ def run_cli(
     from .config import Config
 
     ctx.obj = Config()
-    if ctx.obj.check_for_updates:
+    if ctx.obj.check_for_updates and ctx.invoked_subcommand != "completions":
         from .app_updater import check_for_updates
 
         print("Checking for updates...")


Test patch:
diff --git a/tests/test_all_commands.py b/tests/test_all_commands.py
index b508761..0a129b7 100644
--- a/tests/test_all_commands.py
+++ b/tests/test_all_commands.py
@@ -1,5 +1,6 @@
 import pytest
 from click.testing import CliRunner
+from unittest.mock import patch
 
 from fastanime.cli import run_cli
 
@@ -147,3 +148,10 @@ def test_anilist_upcoming_help(runner: CliRunner):
 def test_anilist_watching_help(runner: CliRunner):
     result = runner.invoke(run_cli, ["anilist", "watching", "--help"])
     assert result.exit_code == 0
+
+
+def test_check_for_updates_not_called_on_completions(runner):
+    with patch('fastanime.cli.app_updater.check_for_updates') as mock_check_for_updates:
+        result = runner.invoke(run_cli, ["completions"])
+        assert result.exit_code == 0
+        mock_check_for_updates.assert_not_called()