Repository: joke2k/faker

Issue:
faker command line fails with "faker.exceptions.UnsupportedFeature: `image` requires the `Pillow` python library."
* Faker version: 8.8.2
* OS: Ubuntu

It looks like the image faker added in #1254 / 8.5.0 broke the faker command line?

is the fix to catch `UnsupportedFeature` in cli.py, and maybe print a warning?

### Steps to reproduce

1. Install faker in a virtualenv
1. run in the terminal `faker`

### Expected behavior

cli should output fake data

### Actual behavior

Fails with exception:

faker.exceptions.UnsupportedFeature: `image` requires the `Pillow` python library.



Comments:

Patch:
diff --git a/faker/cli.py b/faker/cli.py
index 786060a3..cef26c7e 100644
--- a/faker/cli.py
+++ b/faker/cli.py
@@ -7,7 +7,7 @@ import sys
 from pathlib import Path
 from typing import Any, Dict, List, Optional, TextIO
 
-from faker import VERSION, Faker, documentor
+from faker import VERSION, Faker, documentor, exceptions
 from faker.config import AVAILABLE_LOCALES, DEFAULT_LOCALE, META_PROVIDERS_MODULES
 
 __author__ = 'joke2k'
@@ -86,8 +86,15 @@ def print_doc(provider_or_field=None,
 
     else:
         doc = documentor.Documentor(fake)
+        unsupported = []
 
-        formatters = doc.get_formatters(with_args=True, with_defaults=True)
+        while True:
+            try:
+                formatters = doc.get_formatters(with_args=True, with_defaults=True, excludes=unsupported)
+            except exceptions.UnsupportedFeature as e:
+                unsupported.append(e.name)
+            else:
+                break
 
         for provider, fakers in formatters:
 
@@ -104,7 +111,7 @@ def print_doc(provider_or_field=None,
 
             for p, fs in d.get_formatters(with_args=True, with_defaults=True,
                                           locale=language,
-                                          excludes=base_provider_formatters):
+                                          excludes=base_provider_formatters + unsupported):
                 print_provider(d, p, fs, output=output)
 
 
diff --git a/faker/exceptions.py b/faker/exceptions.py
index 0feb4dd1..21bc606d 100644
--- a/faker/exceptions.py
+++ b/faker/exceptions.py
@@ -10,3 +10,6 @@ class UniquenessException(BaseFakerException):
 
 class UnsupportedFeature(BaseFakerException):
     """The requested feature is not available on this system."""
+    def __init__(self, msg, name):
+        self.name = name
+        super().__init__(msg)
diff --git a/faker/providers/misc/__init__.py b/faker/providers/misc/__init__.py
index 5cf7822f..d6572080 100644
--- a/faker/providers/misc/__init__.py
+++ b/faker/providers/misc/__init__.py
@@ -305,7 +305,7 @@ class Provider(BaseProvider):
             import PIL.Image
             import PIL.ImageDraw
         except ImportError:
-            raise UnsupportedFeature("`image` requires the `Pillow` python library.")
+            raise UnsupportedFeature("`image` requires the `Pillow` python library.", "image")
 
         (width, height) = size
         image = PIL.Image.new('RGB', size, self.generator.color(hue=hue, luminosity=luminosity))


Test patch:
diff --git a/tests/providers/test_misc.py b/tests/providers/test_misc.py
index 41de338d..35413597 100644
--- a/tests/providers/test_misc.py
+++ b/tests/providers/test_misc.py
@@ -326,9 +326,11 @@ class TestMiscProvider:
 
     def test_image_no_pillow(self, faker):
         with patch.dict("sys.modules", {"PIL": None}):
-            with pytest.raises(exceptions.UnsupportedFeature):
+            with pytest.raises(exceptions.UnsupportedFeature) as excinfo:
                 faker.image()
 
+            assert excinfo.value.name == "image"
+
     def test_dsv_with_invalid_values(self, faker):
         with pytest.raises(ValueError):
             faker.dsv(num_rows='1')