Repository: iterative/dvc

Issue:
Implement the --show-md flag for dvc metrics show
Currently I can do `dvc metrics diff --show-md` to get a markdown formatted table of metric diffs, but this isn't implemented for `dvc metrics show`. It would be great if it was!


Discussion:
Should be trivial after https://github.com/iterative/dvc/pull/4706 

Resolving patch:
diff --git a/dvc/command/metrics.py b/dvc/command/metrics.py
--- a/dvc/command/metrics.py
+++ b/dvc/command/metrics.py
@@ -13,6 +13,7 @@
 
 def _show_metrics(
     metrics,
+    markdown=False,
     all_branches=False,
     all_tags=False,
     all_commits=False,
@@ -65,7 +66,7 @@ def _round(val):
 
     if missing:
         raise BadMetricError(missing)
-    return table(header, rows, markdown=False)
+    return table(header, rows, markdown)
 
 
 class CmdMetricsBase(CmdBase):
@@ -90,6 +91,7 @@ def run(self):
             else:
                 table = _show_metrics(
                     metrics,
+                    self.args.show_md,
                     self.args.all_branches,
                     self.args.all_tags,
                     self.args.all_commits,
@@ -228,6 +230,12 @@ def add_parser(subparsers, parent_parser):
         default=False,
         help="Show output in JSON format.",
     )
+    metrics_show_parser.add_argument(
+        "--show-md",
+        action="store_true",
+        default=False,
+        help="Show tabulated output in the Markdown format (GFM).",
+    )
     metrics_show_parser.add_argument(
         "-R",
         "--recursive",


Test patch:
diff --git a/tests/unit/command/test_metrics.py b/tests/unit/command/test_metrics.py
--- a/tests/unit/command/test_metrics.py
+++ b/tests/unit/command/test_metrics.py
@@ -19,6 +19,7 @@ def test_metrics_diff(dvc, mocker):
             "-R",
             "--all",
             "--show-json",
+            "--show-md",
             "--targets",
             "target1",
             "target2",
@@ -330,3 +331,42 @@ def test_metrics_show_precision():
         Revision    Path          a          b.ad       b.bc
         branch_1    metrics.json  1.0987654  1.5342673  2.9877255"""
     )
+
+
+def test_metrics_show_default():
+    assert _show_metrics(
+        {
+            "metrics.yaml": {
+                "x.b": {"old": 5, "new": 6},
+                "a.d.e": {"old": 3, "new": 4, "diff": 1},
+                "a.b.c": {"old": 1, "new": 2, "diff": 1},
+            }
+        },
+    ) == textwrap.dedent(
+        """\
+        Path    diff    new    old
+        x.b     —       6      5
+        a.d.e   1       4      3
+        a.b.c   1       2      1"""
+    )
+
+
+def test_metrics_show_md():
+    assert _show_metrics(
+        {
+            "metrics.yaml": {
+                "x.b": {"old": 5, "new": 6},
+                "a.d.e": {"old": 3, "new": 4, "diff": 1},
+                "a.b.c": {"old": 1, "new": 2, "diff": 1},
+            }
+        },
+        markdown=True,
+    ) == textwrap.dedent(
+        """\
+        | Path   | diff   | new   | old   |
+        |--------|--------|-------|-------|
+        | x.b    | —      | 6     | 5     |
+        | a.d.e  | 1      | 4     | 3     |
+        | a.b.c  | 1      | 2     | 1     |
+        """
+    )