Repository: abey79/vpype

Issue:
Bug: Adding a pipeline command after `show` results in a stack trace error
How to reproduce:

```
$ vpype read LabradorLowPoly.svg show stat
========= Stats ========= 
Traceback (most recent call last):
  File "/home/dominik/.local/bin/vpype", line 8, in <module>
    sys.exit(cli())
  File "/home/dominik/.local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/dominik/.local/lib/python3.8/site-packages/vpype_cli/cli.py", line 74, in main
    return super().main(args=preprocess_argument_list(args), **extra)
  File "/home/dominik/.local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/dominik/.local/lib/python3.8/site-packages/click/core.py", line 1290, in invoke
    return _process_result(rv)
  File "/home/dominik/.local/lib/python3.8/site-packages/click/core.py", line 1224, in _process_result
    value = ctx.invoke(self.result_callback, value, **ctx.params)
  File "/home/dominik/.local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/dominik/.local/lib/python3.8/site-packages/vpype_cli/cli.py", line 128, in process_pipeline
    execute_processors(processors)
  File "/home/dominik/.local/lib/python3.8/site-packages/vpype_cli/cli.py", line 212, in execute_processors
    state = proc(state)
  File "/home/dominik/.local/lib/python3.8/site-packages/vpype/decorators.py", line 150, in global_processor
    state.document = f(state.document, *args, **kwargs)
  File "/home/dominik/.local/lib/python3.8/site-packages/vpype_cli/debug.py", line 135, in stat
    print(f"Current page size: {document.page_size}")
AttributeError: 'NoneType' object has no attribute 'page_size'
```

Also true with the classic show:
```
$ vpype read LabradorLowPoly.svg show --classic stat
========= Stats ========= 
Traceback (most recent call last):
  File "/home/dominik/.local/bin/vpype", line 8, in <module>
    sys.exit(cli())
  File "/home/dominik/.local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/dominik/.local/lib/python3.8/site-packages/vpype_cli/cli.py", line 74, in main
    return super().main(args=preprocess_argument_list(args), **extra)
  File "/home/dominik/.local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/dominik/.local/lib/python3.8/site-packages/click/core.py", line 1290, in invoke
    return _process_result(rv)
  File "/home/dominik/.local/lib/python3.8/site-packages/click/core.py", line 1224, in _process_result
    value = ctx.invoke(self.result_callback, value, **ctx.params)
  File "/home/dominik/.local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/dominik/.local/lib/python3.8/site-packages/vpype_cli/cli.py", line 128, in process_pipeline
    execute_processors(processors)
  File "/home/dominik/.local/lib/python3.8/site-packages/vpype_cli/cli.py", line 212, in execute_processors
    state = proc(state)
  File "/home/dominik/.local/lib/python3.8/site-packages/vpype/decorators.py", line 150, in global_processor
    state.document = f(state.document, *args, **kwargs)
  File "/home/dominik/.local/lib/python3.8/site-packages/vpype_cli/debug.py", line 135, in stat
    print(f"Current page size: {document.page_size}")
AttributeError: 'NoneType' object has no attribute 'page_size'
```

Version:
```
$ vpype --version
vpype 1.3.0a0
```


Discussion:

Resolving patch:
diff --git a/vpype_cli/show.py b/vpype_cli/show.py
--- a/vpype_cli/show.py
+++ b/vpype_cli/show.py
@@ -104,6 +104,8 @@ def show(
             document, view_mode=view_mode, show_pen_up=show_pen_up, show_points=show_points
         )
 
+    return document
+
 
 def _test_mgl() -> bool:
     """Tests availability of ModernGL."""
@@ -249,5 +251,3 @@ def on_pick(event):
     if show_grid:
         plt.grid("on")
     plt.show()
-
-    return document


Test patch:
diff --git a/tests/test_show.py b/tests/test_show.py
--- a/tests/test_show.py
+++ b/tests/test_show.py
@@ -1,6 +1,7 @@
 import matplotlib.pyplot as plt
 import pytest
 
+import vpype as vp
 import vpype_viewer
 from vpype_cli import cli
 
@@ -67,3 +68,19 @@ def new_show(*args, **kwargs):
 
     assert res.exit_code == 0
     assert_image_similarity(image)
+
+
+def test_show_must_return_document(runner, monkeypatch):
+    @cli.command()
+    @vp.global_processor
+    def assertdoc(document):
+        assert document is not None
+        assert type(document) is vp.Document
+
+    def new_show(*args, **kwargs):
+        pass
+
+    monkeypatch.setattr(vpype_viewer, "show", new_show)
+
+    result = runner.invoke(cli, "line 0 0 10 10 show assertdoc")
+    assert result.exit_code == 0