Repository: Morpheus636/zeal-cli (language: python)

Issue:
Function to return a list of installed docsets



Discussion / hints:

Fix patch:
diff --git a/src/zeal/__init__.py b/src/zeal/__init__.py
index 7fe9f6f..b292ad7 100644
--- a/src/zeal/__init__.py
+++ b/src/zeal/__init__.py
@@ -1,1 +1,1 @@
-from . import download_docset, exceptions
+from . import download_docset, exceptions, list_docsets
diff --git a/src/zeal/list_docsets.py b/src/zeal/list_docsets.py
new file mode 100644
index 0000000..81e0049
--- /dev/null
+++ b/src/zeal/list_docsets.py
@@ -0,0 +1,17 @@
+import os
+
+from . import filesystem
+
+
+def get_list(docset_dir: str = filesystem.docset_dir) -> list:
+    """List the docsets in the docset_dir.
+
+    :param docset_dir: String, path to the Zeal docset directory. DefaultL filesystem.docset_dir
+    :return: List of docsets (by name, not by path)
+    """
+    files_list = os.listdir(docset_dir)
+    installed_docsets = []
+    for file in files_list:
+        if file.endswith(".docset"):
+            installed_docsets.append(file.rstrip(".docset"))
+    return installed_docsets


Test patch:
diff --git a/tests/unit/test_list_docsets.py b/tests/unit/test_list_docsets.py
new file mode 100644
index 0000000..9cb4dfa
--- /dev/null
+++ b/tests/unit/test_list_docsets.py
@@ -0,0 +1,20 @@
+import os
+import sys
+import tempfile
+
+
+sys.path.append(os.path.relpath(__file__) + "/../src")
+import src.zeal  # NOQA: E402
+
+
+def test_list_docsets():
+    with tempfile.TemporaryDirectory() as docset_dir:
+        os.mkdir(os.path.join(docset_dir, "docset1.docset"))
+        os.mkdir(os.path.join(docset_dir, "docset2.docset"))
+        os.mkdir(os.path.join(docset_dir, "docset3.docset"))
+        os.mkdir(os.path.join(docset_dir, "not_a_docset"))
+        docset_list = src.zeal.list_docsets.get_list(docset_dir=docset_dir)
+        assert "docset1" in docset_list
+        assert "docset2" in docset_list
+        assert "docset3" in docset_list
+        assert "not_a_docset" not in docset_list