Repository: joke2k/faker

Issue:
Lots of output at terminal
If I just enter `faker` at the terminal and hit enter, is it supposed to produce nearly 50mb of output? The text flew by so fast, I piped it into a text file, and it was something like 46mb of text. I'm fairly confident this isn't intended, but I obviously can't say for sure, since I'm not the one who wrote it. If this isn't intended, I can provide more details. 


Discussion:
It is sort of intended but not exactly. I am a relatively new contributor, so this is just my take. I think the original intent was to produce some docs and sample code based on the available provider methods. This part of the codebase is somewhat ancient, back when there are probably very few provider methods, but as more provider methods were added, the amount of text just increased, more so with the addition of methods that can generate random binary files.

There has been a discussion in #1078 about overhauling the cli utility, but I have not had the time to focus on this one. Perhaps you would like to try?
I'm sorta fairly knowledgeable with argparse, if you'd like me to see what I can do. But in the meantime, I think just displaying the normal argparse error would be the best solution for now, and then maybe relocating this text to a "example" subcommand, which could possibly write it to a file? At least until it gets explored more in depth. Or I can just report back with a more elaborate proposal?

I'll still explore it, see what it looks like.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
I think a simple message like this would be sufficient:

```
$ faker
usage: faker [-h] [--version] [-v] [-o output] [-l LOCALE] [-r REPEAT] [-s SEP] [--seed SEED] [-i [INCLUDE ...]] [fake] [fake argument ...]
Try 'faker --help' for more information.
```

i.e. the same output you get when running e.g. `grep` without arguments.

Resolving patch:
diff --git a/faker/cli.py b/faker/cli.py
--- a/faker/cli.py
+++ b/faker/cli.py
@@ -1,8 +1,10 @@
 import argparse
+import itertools
 import logging
 import os
 import random
 import sys
+import textwrap
 
 from io import TextIOWrapper
 from pathlib import Path
@@ -34,11 +36,18 @@ def print_provider(
     print(f"### {doc.get_provider_name(provider)}", file=output)
     print(file=output)
 
+    margin = max(30, doc.max_name_len + 2)
     for signature, example in formatters.items():
         if signature in excludes:
             continue
+        signature_lines = textwrap.wrap(signature, width=margin, subsequent_indent="  ")
         try:
-            lines = str(example).expandtabs().splitlines()
+            lines = textwrap.wrap(
+                str(example).expandtabs(),
+                width=150 - margin,
+                initial_indent="# ",
+                subsequent_indent="  ",
+            )
         except UnicodeDecodeError:
             # The example is actually made of bytes.
             # We could coerce to bytes, but that would fail anyway when we wiil
@@ -46,16 +55,8 @@ def print_provider(
             lines = ["<bytes>"]
         except UnicodeEncodeError:
             raise Exception(f"error on {signature!r} with value {example!r}")
-        margin = max(30, doc.max_name_len + 1)
-        remains = 150 - margin
-        separator = "#"
-        for line in lines:
-            for i in range(0, (len(line) // remains) + 1):
-                print(
-                    f"\t{signature:<{margin}}{separator} {line[i * remains:(i + 1) * remains]}",
-                    file=output,
-                )
-                signature = separator = " "
+        for left, right in itertools.zip_longest(signature_lines, lines, fillvalue=""):
+            print(f"\t{left:<{margin}}  {right}", file=output)
 
 
 def print_doc(
@@ -112,23 +113,6 @@ def print_doc(
         for provider, fakers in formatters:
             print_provider(doc, provider, fakers, output=output)
 
-        for language in AVAILABLE_LOCALES:
-            if language == lang:
-                continue
-            print(file=output)
-            print(f"## LANGUAGE {language}", file=output)
-            fake = Faker(locale=language)
-            fake.seed_instance(seed)
-            d = documentor.Documentor(fake)
-
-            for p, fs in d.get_formatters(
-                with_args=True,
-                with_defaults=True,
-                locale=language,
-                excludes=base_provider_formatters + unsupported,
-            ):
-                print_provider(d, p, fs, output=output)
-
 
 class Command:
     def __init__(self, argv: Optional[str] = None) -> None:
diff --git a/faker/documentor.py b/faker/documentor.py
--- a/faker/documentor.py
+++ b/faker/documentor.py
@@ -119,7 +119,7 @@ def get_provider_formatters(
                 continue
             formatters[signature] = example
 
-            self.max_name_len = max(self.max_name_len, len(signature))
+            self.max_name_len = max(self.max_name_len, *(len(part) for part in signature.split()))
             self.already_generated.append(name)
 
         return formatters


Test patch: