prompt: 
  We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  plots: replace --show-json with --show-vega
  Requested by @dmpetrov for cml. `--show-vega` should require a target and return a filled vega template. `--show-json` is not needed, let's delete it.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  
  --- BEGIN FILE ---
  ```
  ### dvc/command/plots.py
  import argparse
  import logging
  import os
  
  from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
  from dvc.exceptions import DvcException
  from dvc.utils import format_link
  
  logger = logging.getLogger(__name__)
  
  PAGE_HTML = """<!DOCTYPE html>
  <html>
  <head>
      <title>DVC Plot</title>
      <script src="https://cdn.jsdelivr.net/npm/vega@5.10.0"></script>
      <script src="https://cdn.jsdelivr.net/npm/vega-lite@4.8.1"></script>
      <script src="https://cdn.jsdelivr.net/npm/vega-embed@6.5.1"></script>
  </head>
  <body>
      {divs}
  </body>
  </html>"""
  
  DIV_HTML = """<div id = "{id}"></div>
  <script type = "text/javascript">
      var spec = {vega_json};
      vegaEmbed('#{id}', spec);
  </script>"""
  
  
  class CmdPlots(CmdBase):
      def _func(self, *args, **kwargs):
          raise NotImplementedError
  
      def run(self):
          try:
              plots = self._func(
                  targets=self.args.targets,
                  template=self.args.template,
                  x_field=self.args.x,
                  y_field=self.args.y,
                  csv_header=not self.args.no_csv_header,
                  title=self.args.title,
                  x_title=self.args.xlab,
                  y_title=self.args.ylab,
              )
  
              if self.args.show_json:
                  import json
  
                  logger.info(json.dumps(plots))
                  return 0
  
              divs = [
                  DIV_HTML.format(id=f"plot{i}", vega_json=plot)
                  for i, plot in enumerate(plots.values())
              ]
              html = PAGE_HTML.format(divs="\n".join(divs))
              path = self.args.out or "plots.html"
  
              with open(path, "w") as fobj:
                  fobj.write(html)
  
              logger.info(
                  "file://{}".format(os.path.join(self.repo.root_dir, path))
              )
  
          except DvcException:
              logger.exception("")
              return 1
  
          return 0
  
  
  class CmdPlotsShow(CmdPlots):
      def _func(self, *args, **kwargs):
          return self.repo.plots.show(*args, **kwargs)
  
  
  class CmdPlotsDiff(CmdPlots):
      def _func(self, *args, **kwargs):
          return self.repo.plots.diff(*args, revs=self.args.revisions, **kwargs)
  
  
  def add_parser(subparsers, parent_parser):
      PLOTS_HELP = (
          "Generating plots for metrics stored in structured files "
          "(JSON, CSV, TSV)."
      )
  
      plots_parser = subparsers.add_parser(
          "plots",
          parents=[parent_parser],
          description=append_doc_link(PLOTS_HELP, "plots"),
          help=PLOTS_HELP,
          formatter_class=argparse.RawDescriptionHelpFormatter,
      )
      plots_subparsers = plots_parser.add_subparsers(
          dest="cmd",
          help="Use `dvc plots CMD --help` to display command-specific help.",
      )
  
      fix_subparsers(plots_subparsers)
  
      SHOW_HELP = "Generate a plots image file from a metrics file."
      plots_show_parser = plots_subparsers.add_parser(
          "show",
          parents=[parent_parser],
          description=append_doc_link(SHOW_HELP, "plots/show"),
          help=SHOW_HELP,
          formatter_class=argparse.RawDescriptionHelpFormatter,
      )
      plots_show_parser.add_argument(
          "-t",
          "--template",
          nargs="?",
          default=None,
          help=(
              "Special JSON or HTML schema file to inject with the data. "
              "See {}".format(
                  format_link("https://man.dvc.org/plots#plot-templates")
              )
          ),
      )
      plots_show_parser.add_argument(
          "-o", "--out", default=None, help="Destination path to save plots to.",
      )
      plots_show_parser.add_argument(
          "-x", default=None, help="Field name for x axis."
      )
      plots_show_parser.add_argument(
          "-y", default=None, help="Field name for y axis."
      )
      plots_show_parser.add_argument(
          "--no-csv-header",
          action="store_true",
          default=False,
          help="Required when CSV or TSV datafile does not have a header.",
      )
      plots_show_parser.add_argument(
          "--show-json",
          action="store_true",
          default=False,
          help="Show output in JSON format.",
      )
      plots_show_parser.add_argument("--title", default=None, help="Plot title.")
      plots_show_parser.add_argument(
          "--xlab", default=None, help="X axis title."
      )
      plots_show_parser.add_argument(
          "--ylab", default=None, help="Y axis title."
      )
      plots_show_parser.add_argument(
          "targets",
          nargs="*",
          help="Metrics files to visualize. Shows all plots by default.",
      )
      plots_show_parser.set_defaults(func=CmdPlotsShow)
  
      PLOTS_DIFF_HELP = (
          "Plot differences in metrics between commits in the DVC "
          "repository, or between the last commit and the workspace."
      )
      plots_diff_parser = plots_subparsers.add_parser(
          "diff",
          parents=[parent_parser],
          description=append_doc_link(PLOTS_DIFF_HELP, "plots/diff"),
          help=PLOTS_DIFF_HELP,
          formatter_class=argparse.RawDescriptionHelpFormatter,
      )
      plots_diff_parser.add_argument(
          "-t",
          "--template",
          nargs="?",
          default=None,
          help=(
              "Special JSON or HTML schema file to inject with the data. "
              "See {}".format(
                  format_link("https://man.dvc.org/plots#plot-templates")
              )
          ),
      )
      plots_diff_parser.add_argument(
          "--targets",
          nargs="*",
          help="Metrics file to visualize. Shows all plots by default.",
      )
      plots_diff_parser.add_argument(
          "-o", "--out", default=None, help="Destination path to save plots to.",
      )
      plots_diff_parser.add_argument(
          "-x", default=None, help="Field name for x axis."
      )
      plots_diff_parser.add_argument(
          "-y", default=None, help="Field name for y axis."
      )
      plots_diff_parser.add_argument(
          "--no-csv-header",
          action="store_true",
          default=False,
          help="Provided CSV ot TSV datafile does not have a header.",
      )
      plots_diff_parser.add_argument(
          "--show-json",
          action="store_true",
          default=False,
          help="Show output in JSON format.",
      )
      plots_diff_parser.add_argument("--title", default=None, help="Plot title.")
      plots_diff_parser.add_argument(
          "--xlab", default=None, help="X axis title."
      )
      plots_diff_parser.add_argument(
          "--ylab", default=None, help="Y axis title."
      )
      plots_diff_parser.add_argument(
          "revisions", nargs="*", default=None, help="Git commits to plot from",
      )
      plots_diff_parser.set_defaults(func=CmdPlotsDiff)
  
  ```
  --- END FILE ---
  
  Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.
  
  Every *SEARCH/REPLACE* edit must use this format:
  1. The file path
  2. The start of search block: <<<<<<< SEARCH
  3. A contiguous chunk of lines to search for in the existing source code
  4. The dividing line: =======
  5. The lines to replace into the source code
  6. The end of the replace block: >>>>>>> REPLACE
  
  Here is an example:
  
  ```python
  ### mathweb/flask/app.py
  <<<<<<< SEARCH
  from flask import Flask
  =======
  import math
  from flask import Flask
  >>>>>>> REPLACE
  ```
  
  Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
  Wrap the *SEARCH/REPLACE* edit in blocks ```python...```.
  
instance: {"FAIL_TO_PASS": ["tests/unit/command/test_plots.py::test_metrics_diff", "tests/unit/command/test_plots.py::test_plots_show_vega", "tests/unit/command/test_plots.py::test_metrics_show"], "PASS_TO_PASS": [], "base_commit": "63972c3d120d9f076f642a19382a247d5d5855a5", "created_at": "2020-05-28T01:36:47Z", "hints_text": "", "instance_id": "iterative__dvc-3891", "patch": "diff --git a/dvc/command/plots.py b/dvc/command/plots.py\n--- a/dvc/command/plots.py\n+++ b/dvc/command/plots.py\n@@ -33,6 +33,16 @@ def _func(self, *args, **kwargs):\n         raise NotImplementedError\n \n     def run(self):\n+        if self.args.show_vega:\n+            if not self.args.targets:\n+                logger.error(\"please specify a target for `--show-vega`\")\n+                return 1\n+            if len(self.args.targets) > 1:\n+                logger.error(\n+                    \"you can only specify one target for `--show-vega`\"\n+                )\n+                return 1\n+\n         try:\n             plots = self._func(\n                 targets=self.args.targets,\n@@ -45,10 +55,9 @@ def run(self):\n                 y_title=self.args.ylab,\n             )\n \n-            if self.args.show_json:\n-                import json\n-\n-                logger.info(json.dumps(plots))\n+            if self.args.show_vega:\n+                target = self.args.targets[0]\n+                logger.info(plots[target])\n                 return 0\n \n             divs = [\n@@ -138,10 +147,10 @@ def add_parser(subparsers, parent_parser):\n         help=\"Required when CSV or TSV datafile does not have a header.\",\n     )\n     plots_show_parser.add_argument(\n-        \"--show-json\",\n+        \"--show-vega\",\n         action=\"store_true\",\n         default=False,\n-        help=\"Show output in JSON format.\",\n+        help=\"Show output in VEGA format.\",\n     )\n     plots_show_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n     plots_show_parser.add_argument(\n@@ -201,10 +210,10 @@ def add_parser(subparsers, parent_parser):\n         help=\"Provided CSV ot TSV datafile does not have a header.\",\n     )\n     plots_diff_parser.add_argument(\n-        \"--show-json\",\n+        \"--show-vega\",\n         action=\"store_true\",\n         default=False,\n-        help=\"Show output in JSON format.\",\n+        help=\"Show output in VEGA format.\",\n     )\n     plots_diff_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n     plots_diff_parser.add_argument(\n", "problem_statement": "plots: replace --show-json with --show-vega\nRequested by @dmpetrov for cml. `--show-vega` should require a target and return a filled vega template. `--show-json` is not needed, let's delete it.\n", "repo": "iterative/dvc", "test_patch": "diff --git a/tests/unit/command/test_plots.py b/tests/unit/command/test_plots.py\n--- a/tests/unit/command/test_plots.py\n+++ b/tests/unit/command/test_plots.py\n@@ -13,7 +13,7 @@ def test_metrics_diff(dvc, mocker):\n             \"template\",\n             \"--targets\",\n             \"datafile\",\n-            \"--show-json\",\n+            \"--show-vega\",\n             \"-x\",\n             \"x_field\",\n             \"-y\",\n@@ -32,7 +32,9 @@ def test_metrics_diff(dvc, mocker):\n     assert cli_args.func == CmdPlotsDiff\n \n     cmd = cli_args.func(cli_args)\n-    m = mocker.patch(\"dvc.repo.plots.diff.diff\", return_value={})\n+    m = mocker.patch(\n+        \"dvc.repo.plots.diff.diff\", return_value={\"datafile\": \"filledtemplate\"}\n+    )\n \n     assert cmd.run() == 0\n \n@@ -59,7 +61,7 @@ def test_metrics_show(dvc, mocker):\n             \"result.extension\",\n             \"-t\",\n             \"template\",\n-            \"--show-json\",\n+            \"--show-vega\",\n             \"--no-csv-header\",\n             \"datafile\",\n         ]\n@@ -68,7 +70,9 @@ def test_metrics_show(dvc, mocker):\n \n     cmd = cli_args.func(cli_args)\n \n-    m = mocker.patch(\"dvc.repo.plots.show.show\", return_value={})\n+    m = mocker.patch(\n+        \"dvc.repo.plots.show.show\", return_value={\"datafile\": \"filledtemplate\"}\n+    )\n \n     assert cmd.run() == 0\n \n@@ -85,13 +89,21 @@ def test_metrics_show(dvc, mocker):\n     )\n \n \n-def test_plots_show_json(dvc, mocker, caplog):\n+def test_plots_show_vega(dvc, mocker, caplog):\n     cli_args = parse_args(\n-        [\"plots\", \"diff\", \"HEAD~10\", \"HEAD~1\", \"--show-json\"]\n+        [\n+            \"plots\",\n+            \"diff\",\n+            \"HEAD~10\",\n+            \"HEAD~1\",\n+            \"--show-vega\",\n+            \"--targets\",\n+            \"plots.csv\",\n+        ]\n     )\n     cmd = cli_args.func(cli_args)\n     mocker.patch(\n         \"dvc.repo.plots.diff.diff\", return_value={\"plots.csv\": \"plothtml\"}\n     )\n     assert cmd.run() == 0\n-    assert '{\"plots.csv\": \"plothtml\"}\\n' in caplog.text\n+    assert \"plothtml\" in caplog.text\n", "version": "1.0"}
parsed_commit_content: {"file_diffs":[{"old_file_content":"import argparse\nimport logging\nimport os\n\nfrom dvc.command.base import CmdBase, append_doc_link, fix_subparsers\nfrom dvc.exceptions import DvcException\nfrom dvc.utils import format_link\n\nlogger = logging.getLogger(__name__)\n\nPAGE_HTML = \"\"\"<!DOCTYPE html>\n<html>\n<head>\n    <title>DVC Plot</title>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega@5.10.0\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega-lite@4.8.1\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega-embed@6.5.1\"></script>\n</head>\n<body>\n    {divs}\n</body>\n</html>\"\"\"\n\nDIV_HTML = \"\"\"<div id = \"{id}\"></div>\n<script type = \"text/javascript\">\n    var spec = {vega_json};\n    vegaEmbed('#{id}', spec);\n</script>\"\"\"\n\n\nclass CmdPlots(CmdBase):\n    def _func(self, *args, **kwargs):\n        raise NotImplementedError\n\n    def run(self):\n        try:\n            plots = self._func(\n                targets=self.args.targets,\n                template=self.args.template,\n                x_field=self.args.x,\n                y_field=self.args.y,\n                csv_header=not self.args.no_csv_header,\n                title=self.args.title,\n                x_title=self.args.xlab,\n                y_title=self.args.ylab,\n            )\n\n            if self.args.show_json:\n                import json\n\n                logger.info(json.dumps(plots))\n                return 0\n\n            divs = [\n                DIV_HTML.format(id=f\"plot{i}\", vega_json=plot)\n                for i, plot in enumerate(plots.values())\n            ]\n            html = PAGE_HTML.format(divs=\"\\n\".join(divs))\n            path = self.args.out or \"plots.html\"\n\n            with open(path, \"w\") as fobj:\n                fobj.write(html)\n\n            logger.info(\n                \"file://{}\".format(os.path.join(self.repo.root_dir, path))\n            )\n\n        except DvcException:\n            logger.exception(\"\")\n            return 1\n\n        return 0\n\n\nclass CmdPlotsShow(CmdPlots):\n    def _func(self, *args, **kwargs):\n        return self.repo.plots.show(*args, **kwargs)\n\n\nclass CmdPlotsDiff(CmdPlots):\n    def _func(self, *args, **kwargs):\n        return self.repo.plots.diff(*args, revs=self.args.revisions, **kwargs)\n\n\ndef add_parser(subparsers, parent_parser):\n    PLOTS_HELP = (\n        \"Generating plots for metrics stored in structured files \"\n        \"(JSON, CSV, TSV).\"\n    )\n\n    plots_parser = subparsers.add_parser(\n        \"plots\",\n        parents=[parent_parser],\n        description=append_doc_link(PLOTS_HELP, \"plots\"),\n        help=PLOTS_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_subparsers = plots_parser.add_subparsers(\n        dest=\"cmd\",\n        help=\"Use `dvc plots CMD --help` to display command-specific help.\",\n    )\n\n    fix_subparsers(plots_subparsers)\n\n    SHOW_HELP = \"Generate a plots image file from a metrics file.\"\n    plots_show_parser = plots_subparsers.add_parser(\n        \"show\",\n        parents=[parent_parser],\n        description=append_doc_link(SHOW_HELP, \"plots/show\"),\n        help=SHOW_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_show_parser.add_argument(\n        \"-t\",\n        \"--template\",\n        nargs=\"?\",\n        default=None,\n        help=(\n            \"Special JSON or HTML schema file to inject with the data. \"\n            \"See {}\".format(\n                format_link(\"https://man.dvc.org/plots#plot-templates\")\n            )\n        ),\n    )\n    plots_show_parser.add_argument(\n        \"-o\", \"--out\", default=None, help=\"Destination path to save plots to.\",\n    )\n    plots_show_parser.add_argument(\n        \"-x\", default=None, help=\"Field name for x axis.\"\n    )\n    plots_show_parser.add_argument(\n        \"-y\", default=None, help=\"Field name for y axis.\"\n    )\n    plots_show_parser.add_argument(\n        \"--no-csv-header\",\n        action=\"store_true\",\n        default=False,\n        help=\"Required when CSV or TSV datafile does not have a header.\",\n    )\n    plots_show_parser.add_argument(\n        \"--show-json\",\n        action=\"store_true\",\n        default=False,\n        help=\"Show output in JSON format.\",\n    )\n    plots_show_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n    plots_show_parser.add_argument(\n        \"--xlab\", default=None, help=\"X axis title.\"\n    )\n    plots_show_parser.add_argument(\n        \"--ylab\", default=None, help=\"Y axis title.\"\n    )\n    plots_show_parser.add_argument(\n        \"targets\",\n        nargs=\"*\",\n        help=\"Metrics files to visualize. Shows all plots by default.\",\n    )\n    plots_show_parser.set_defaults(func=CmdPlotsShow)\n\n    PLOTS_DIFF_HELP = (\n        \"Plot differences in metrics between commits in the DVC \"\n        \"repository, or between the last commit and the workspace.\"\n    )\n    plots_diff_parser = plots_subparsers.add_parser(\n        \"diff\",\n        parents=[parent_parser],\n        description=append_doc_link(PLOTS_DIFF_HELP, \"plots/diff\"),\n        help=PLOTS_DIFF_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_diff_parser.add_argument(\n        \"-t\",\n        \"--template\",\n        nargs=\"?\",\n        default=None,\n        help=(\n            \"Special JSON or HTML schema file to inject with the data. \"\n            \"See {}\".format(\n                format_link(\"https://man.dvc.org/plots#plot-templates\")\n            )\n        ),\n    )\n    plots_diff_parser.add_argument(\n        \"--targets\",\n        nargs=\"*\",\n        help=\"Metrics file to visualize. Shows all plots by default.\",\n    )\n    plots_diff_parser.add_argument(\n        \"-o\", \"--out\", default=None, help=\"Destination path to save plots to.\",\n    )\n    plots_diff_parser.add_argument(\n        \"-x\", default=None, help=\"Field name for x axis.\"\n    )\n    plots_diff_parser.add_argument(\n        \"-y\", default=None, help=\"Field name for y axis.\"\n    )\n    plots_diff_parser.add_argument(\n        \"--no-csv-header\",\n        action=\"store_true\",\n        default=False,\n        help=\"Provided CSV ot TSV datafile does not have a header.\",\n    )\n    plots_diff_parser.add_argument(\n        \"--show-json\",\n        action=\"store_true\",\n        default=False,\n        help=\"Show output in JSON format.\",\n    )\n    plots_diff_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n    plots_diff_parser.add_argument(\n        \"--xlab\", default=None, help=\"X axis title.\"\n    )\n    plots_diff_parser.add_argument(\n        \"--ylab\", default=None, help=\"Y axis title.\"\n    )\n    plots_diff_parser.add_argument(\n        \"revisions\", nargs=\"*\", default=None, help=\"Git commits to plot from\",\n    )\n    plots_diff_parser.set_defaults(func=CmdPlotsDiff)\n","new_file_content":"import argparse\nimport logging\nimport os\n\nfrom dvc.command.base import CmdBase, append_doc_link, fix_subparsers\nfrom dvc.exceptions import DvcException\nfrom dvc.utils import format_link\n\nlogger = logging.getLogger(__name__)\n\nPAGE_HTML = \"\"\"<!DOCTYPE html>\n<html>\n<head>\n    <title>DVC Plot</title>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega@5.10.0\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega-lite@4.8.1\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega-embed@6.5.1\"></script>\n</head>\n<body>\n    {divs}\n</body>\n</html>\"\"\"\n\nDIV_HTML = \"\"\"<div id = \"{id}\"></div>\n<script type = \"text/javascript\">\n    var spec = {vega_json};\n    vegaEmbed('#{id}', spec);\n</script>\"\"\"\n\n\nclass CmdPlots(CmdBase):\n    def _func(self, *args, **kwargs):\n        raise NotImplementedError\n\n    def run(self):\n        if self.args.show_vega:\n            if not self.args.targets:\n                logger.error(\"please specify a target for `--show-vega`\")\n                return 1\n            if len(self.args.targets) > 1:\n                logger.error(\n                    \"you can only specify one target for `--show-vega`\"\n                )\n                return 1\n\n        try:\n            plots = self._func(\n                targets=self.args.targets,\n                template=self.args.template,\n                x_field=self.args.x,\n                y_field=self.args.y,\n                csv_header=not self.args.no_csv_header,\n                title=self.args.title,\n                x_title=self.args.xlab,\n                y_title=self.args.ylab,\n            )\n\n            if self.args.show_vega:\n                target = self.args.targets[0]\n                logger.info(plots[target])\n                return 0\n\n            divs = [\n                DIV_HTML.format(id=f\"plot{i}\", vega_json=plot)\n                for i, plot in enumerate(plots.values())\n            ]\n            html = PAGE_HTML.format(divs=\"\\n\".join(divs))\n            path = self.args.out or \"plots.html\"\n\n            with open(path, \"w\") as fobj:\n                fobj.write(html)\n\n            logger.info(\n                \"file://{}\".format(os.path.join(self.repo.root_dir, path))\n            )\n\n        except DvcException:\n            logger.exception(\"\")\n            return 1\n\n        return 0\n\n\nclass CmdPlotsShow(CmdPlots):\n    def _func(self, *args, **kwargs):\n        return self.repo.plots.show(*args, **kwargs)\n\n\nclass CmdPlotsDiff(CmdPlots):\n    def _func(self, *args, **kwargs):\n        return self.repo.plots.diff(*args, revs=self.args.revisions, **kwargs)\n\n\ndef add_parser(subparsers, parent_parser):\n    PLOTS_HELP = (\n        \"Generating plots for metrics stored in structured files \"\n        \"(JSON, CSV, TSV).\"\n    )\n\n    plots_parser = subparsers.add_parser(\n        \"plots\",\n        parents=[parent_parser],\n        description=append_doc_link(PLOTS_HELP, \"plots\"),\n        help=PLOTS_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_subparsers = plots_parser.add_subparsers(\n        dest=\"cmd\",\n        help=\"Use `dvc plots CMD --help` to display command-specific help.\",\n    )\n\n    fix_subparsers(plots_subparsers)\n\n    SHOW_HELP = \"Generate a plots image file from a metrics file.\"\n    plots_show_parser = plots_subparsers.add_parser(\n        \"show\",\n        parents=[parent_parser],\n        description=append_doc_link(SHOW_HELP, \"plots/show\"),\n        help=SHOW_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_show_parser.add_argument(\n        \"-t\",\n        \"--template\",\n        nargs=\"?\",\n        default=None,\n        help=(\n            \"Special JSON or HTML schema file to inject with the data. \"\n            \"See {}\".format(\n                format_link(\"https://man.dvc.org/plots#plot-templates\")\n            )\n        ),\n    )\n    plots_show_parser.add_argument(\n        \"-o\", \"--out\", default=None, help=\"Destination path to save plots to.\",\n    )\n    plots_show_parser.add_argument(\n        \"-x\", default=None, help=\"Field name for x axis.\"\n    )\n    plots_show_parser.add_argument(\n        \"-y\", default=None, help=\"Field name for y axis.\"\n    )\n    plots_show_parser.add_argument(\n        \"--no-csv-header\",\n        action=\"store_true\",\n        default=False,\n        help=\"Required when CSV or TSV datafile does not have a header.\",\n    )\n    plots_show_parser.add_argument(\n        \"--show-vega\",\n        action=\"store_true\",\n        default=False,\n        help=\"Show output in VEGA format.\",\n    )\n    plots_show_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n    plots_show_parser.add_argument(\n        \"--xlab\", default=None, help=\"X axis title.\"\n    )\n    plots_show_parser.add_argument(\n        \"--ylab\", default=None, help=\"Y axis title.\"\n    )\n    plots_show_parser.add_argument(\n        \"targets\",\n        nargs=\"*\",\n        help=\"Metrics files to visualize. Shows all plots by default.\",\n    )\n    plots_show_parser.set_defaults(func=CmdPlotsShow)\n\n    PLOTS_DIFF_HELP = (\n        \"Plot differences in metrics between commits in the DVC \"\n        \"repository, or between the last commit and the workspace.\"\n    )\n    plots_diff_parser = plots_subparsers.add_parser(\n        \"diff\",\n        parents=[parent_parser],\n        description=append_doc_link(PLOTS_DIFF_HELP, \"plots/diff\"),\n        help=PLOTS_DIFF_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_diff_parser.add_argument(\n        \"-t\",\n        \"--template\",\n        nargs=\"?\",\n        default=None,\n        help=(\n            \"Special JSON or HTML schema file to inject with the data. \"\n            \"See {}\".format(\n                format_link(\"https://man.dvc.org/plots#plot-templates\")\n            )\n        ),\n    )\n    plots_diff_parser.add_argument(\n        \"--targets\",\n        nargs=\"*\",\n        help=\"Metrics file to visualize. Shows all plots by default.\",\n    )\n    plots_diff_parser.add_argument(\n        \"-o\", \"--out\", default=None, help=\"Destination path to save plots to.\",\n    )\n    plots_diff_parser.add_argument(\n        \"-x\", default=None, help=\"Field name for x axis.\"\n    )\n    plots_diff_parser.add_argument(\n        \"-y\", default=None, help=\"Field name for y axis.\"\n    )\n    plots_diff_parser.add_argument(\n        \"--no-csv-header\",\n        action=\"store_true\",\n        default=False,\n        help=\"Provided CSV ot TSV datafile does not have a header.\",\n    )\n    plots_diff_parser.add_argument(\n        \"--show-vega\",\n        action=\"store_true\",\n        default=False,\n        help=\"Show output in VEGA format.\",\n    )\n    plots_diff_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n    plots_diff_parser.add_argument(\n        \"--xlab\", default=None, help=\"X axis title.\"\n    )\n    plots_diff_parser.add_argument(\n        \"--ylab\", default=None, help=\"Y axis title.\"\n    )\n    plots_diff_parser.add_argument(\n        \"revisions\", nargs=\"*\", default=None, help=\"Git commits to plot from\",\n    )\n    plots_diff_parser.set_defaults(func=CmdPlotsDiff)\n","header":{"file":{"path":"dvc/command/plots.py"},"misc_line":null},"index_line":null,"is_binary_file":false,"binary_line":null,"minus_file":{"path":"a/dvc/command/plots.py"},"plus_file":{"path":"b/dvc/command/plots.py"},"hunks":[{"descriptor":{"old_range":{"start":33,"length":6},"new_range":{"start":33,"length":16},"section":"def _func(self, *args, **kwargs):"},"line_group":{"all_lines":[{"content":"        raise NotImplementedError","type":"context"},{"content":"","type":"context"},{"content":"    def run(self):","type":"context"},{"content":"        if self.args.show_vega:","type":"added"},{"content":"            if not self.args.targets:","type":"added"},{"content":"                logger.error(\"please specify a target for `--show-vega`\")","type":"added"},{"content":"                return 1","type":"added"},{"content":"            if len(self.args.targets) > 1:","type":"added"},{"content":"                logger.error(","type":"added"},{"content":"                    \"you can only specify one target for `--show-vega`\"","type":"added"},{"content":"                )","type":"added"},{"content":"                return 1","type":"added"},{"content":"","type":"added"},{"content":"        try:","type":"context"},{"content":"            plots = self._func(","type":"context"},{"content":"                targets=self.args.targets,","type":"context"}]},"modified_entities":[],"added_entities":[],"deleted_entities":[]},{"descriptor":{"old_range":{"start":45,"length":10},"new_range":{"start":55,"length":9},"section":"def run(self):"},"line_group":{"all_lines":[{"content":"                y_title=self.args.ylab,","type":"context"},{"content":"            )","type":"context"},{"content":"","type":"context"},{"content":"            if self.args.show_json:","type":"deleted"},{"content":"                import json","type":"deleted"},{"content":"","type":"deleted"},{"content":"                logger.info(json.dumps(plots))","type":"deleted"},{"content":"            if self.args.show_vega:","type":"added"},{"content":"                target = self.args.targets[0]","type":"added"},{"content":"                logger.info(plots[target])","type":"added"},{"content":"                return 0","type":"context"},{"content":"","type":"context"},{"content":"            divs = [","type":"context"}]},"modified_entities":[],"added_entities":[],"deleted_entities":[]},{"descriptor":{"old_range":{"start":138,"length":10},"new_range":{"start":147,"length":10},"section":"def add_parser(subparsers, parent_parser):"},"line_group":{"all_lines":[{"content":"        help=\"Required when CSV or TSV datafile does not have a header.\",","type":"context"},{"content":"    )","type":"context"},{"content":"    plots_show_parser.add_argument(","type":"context"},{"content":"        \"--show-json\",","type":"deleted"},{"content":"        \"--show-vega\",","type":"added"},{"content":"        action=\"store_true\",","type":"context"},{"content":"        default=False,","type":"context"},{"content":"        help=\"Show output in JSON format.\",","type":"deleted"},{"content":"        help=\"Show output in VEGA format.\",","type":"added"},{"content":"    )","type":"context"},{"content":"    plots_show_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")","type":"context"},{"content":"    plots_show_parser.add_argument(","type":"context"}]},"modified_entities":[],"added_entities":[],"deleted_entities":[]},{"descriptor":{"old_range":{"start":201,"length":10},"new_range":{"start":210,"length":10},"section":"def add_parser(subparsers, parent_parser):"},"line_group":{"all_lines":[{"content":"        help=\"Provided CSV ot TSV datafile does not have a header.\",","type":"context"},{"content":"    )","type":"context"},{"content":"    plots_diff_parser.add_argument(","type":"context"},{"content":"        \"--show-json\",","type":"deleted"},{"content":"        \"--show-vega\",","type":"added"},{"content":"        action=\"store_true\",","type":"context"},{"content":"        default=False,","type":"context"},{"content":"        help=\"Show output in JSON format.\",","type":"deleted"},{"content":"        help=\"Show output in VEGA format.\",","type":"added"},{"content":"    )","type":"context"},{"content":"    plots_diff_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")","type":"context"},{"content":"    plots_diff_parser.add_argument(","type":"context"},{"content":"","type":"context"}]},"modified_entities":[],"added_entities":[],"deleted_entities":[]}]}],"old_commit_hash":"63972c3d120d9f076f642a19382a247d5d5855a5","new_commit_hash":"4c519dd89f45b0d535adac14ec742d281f94ca4c","commit_message":"plots: replace --show-json with --show-vega","commit_date":"2020-05-28T04:34:43+03:00","metadata":{}}
problem_statement: plots: replace --show-json with --show-vega
  Requested by @dmpetrov for cml. `--show-vega` should require a target and return a filled vega template. `--show-json` is not needed, let's delete it.
  
patch: diff --git a/dvc/command/plots.py b/dvc/command/plots.py
  --- a/dvc/command/plots.py
  +++ b/dvc/command/plots.py
  @@ -33,6 +33,16 @@ def _func(self, *args, **kwargs):
           raise NotImplementedError
   
       def run(self):
  +        if self.args.show_vega:
  +            if not self.args.targets:
  +                logger.error("please specify a target for `--show-vega`")
  +                return 1
  +            if len(self.args.targets) > 1:
  +                logger.error(
  +                    "you can only specify one target for `--show-vega`"
  +                )
  +                return 1
  +
           try:
               plots = self._func(
                   targets=self.args.targets,
  @@ -45,10 +55,9 @@ def run(self):
                   y_title=self.args.ylab,
               )
   
  -            if self.args.show_json:
  -                import json
  -
  -                logger.info(json.dumps(plots))
  +            if self.args.show_vega:
  +                target = self.args.targets[0]
  +                logger.info(plots[target])
                   return 0
   
               divs = [
  @@ -138,10 +147,10 @@ def add_parser(subparsers, parent_parser):
           help="Required when CSV or TSV datafile does not have a header.",
       )
       plots_show_parser.add_argument(
  -        "--show-json",
  +        "--show-vega",
           action="store_true",
           default=False,
  -        help="Show output in JSON format.",
  +        help="Show output in VEGA format.",
       )
       plots_show_parser.add_argument("--title", default=None, help="Plot title.")
       plots_show_parser.add_argument(
  @@ -201,10 +210,10 @@ def add_parser(subparsers, parent_parser):
           help="Provided CSV ot TSV datafile does not have a header.",
       )
       plots_diff_parser.add_argument(
  -        "--show-json",
  +        "--show-vega",
           action="store_true",
           default=False,
  -        help="Show output in JSON format.",
  +        help="Show output in VEGA format.",
       )
       plots_diff_parser.add_argument("--title", default=None, help="Plot title.")
       plots_diff_parser.add_argument(
   
  
file_context: {"dvc/command/plots.py": "import argparse\nimport logging\nimport os\n\nfrom dvc.command.base import CmdBase, append_doc_link, fix_subparsers\nfrom dvc.exceptions import DvcException\nfrom dvc.utils import format_link\n\nlogger = logging.getLogger(__name__)\n\nPAGE_HTML = \"\"\"<!DOCTYPE html>\n<html>\n<head>\n    <title>DVC Plot</title>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega@5.10.0\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega-lite@4.8.1\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega-embed@6.5.1\"></script>\n</head>\n<body>\n    {divs}\n</body>\n</html>\"\"\"\n\nDIV_HTML = \"\"\"<div id = \"{id}\"></div>\n<script type = \"text/javascript\">\n    var spec = {vega_json};\n    vegaEmbed('#{id}', spec);\n</script>\"\"\"\n\n\nclass CmdPlots(CmdBase):\n    def _func(self, *args, **kwargs):\n        raise NotImplementedError\n\n    def run(self):\n        try:\n            plots = self._func(\n                targets=self.args.targets,\n                template=self.args.template,\n                x_field=self.args.x,\n                y_field=self.args.y,\n                csv_header=not self.args.no_csv_header,\n                title=self.args.title,\n                x_title=self.args.xlab,\n                y_title=self.args.ylab,\n            )\n\n            if self.args.show_json:\n                import json\n\n                logger.info(json.dumps(plots))\n                return 0\n\n            divs = [\n                DIV_HTML.format(id=f\"plot{i}\", vega_json=plot)\n                for i, plot in enumerate(plots.values())\n            ]\n            html = PAGE_HTML.format(divs=\"\\n\".join(divs))\n            path = self.args.out or \"plots.html\"\n\n            with open(path, \"w\") as fobj:\n                fobj.write(html)\n\n            logger.info(\n                \"file://{}\".format(os.path.join(self.repo.root_dir, path))\n            )\n\n        except DvcException:\n            logger.exception(\"\")\n            return 1\n\n        return 0\n\n\nclass CmdPlotsShow(CmdPlots):\n    def _func(self, *args, **kwargs):\n        return self.repo.plots.show(*args, **kwargs)\n\n\nclass CmdPlotsDiff(CmdPlots):\n    def _func(self, *args, **kwargs):\n        return self.repo.plots.diff(*args, revs=self.args.revisions, **kwargs)\n\n\ndef add_parser(subparsers, parent_parser):\n    PLOTS_HELP = (\n        \"Generating plots for metrics stored in structured files \"\n        \"(JSON, CSV, TSV).\"\n    )\n\n    plots_parser = subparsers.add_parser(\n        \"plots\",\n        parents=[parent_parser],\n        description=append_doc_link(PLOTS_HELP, \"plots\"),\n        help=PLOTS_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_subparsers = plots_parser.add_subparsers(\n        dest=\"cmd\",\n        help=\"Use `dvc plots CMD --help` to display command-specific help.\",\n    )\n\n    fix_subparsers(plots_subparsers)\n\n    SHOW_HELP = \"Generate a plots image file from a metrics file.\"\n    plots_show_parser = plots_subparsers.add_parser(\n        \"show\",\n        parents=[parent_parser],\n        description=append_doc_link(SHOW_HELP, \"plots/show\"),\n        help=SHOW_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_show_parser.add_argument(\n        \"-t\",\n        \"--template\",\n        nargs=\"?\",\n        default=None,\n        help=(\n            \"Special JSON or HTML schema file to inject with the data. \"\n            \"See {}\".format(\n                format_link(\"https://man.dvc.org/plots#plot-templates\")\n            )\n        ),\n    )\n    plots_show_parser.add_argument(\n        \"-o\", \"--out\", default=None, help=\"Destination path to save plots to.\",\n    )\n    plots_show_parser.add_argument(\n        \"-x\", default=None, help=\"Field name for x axis.\"\n    )\n    plots_show_parser.add_argument(\n        \"-y\", default=None, help=\"Field name for y axis.\"\n    )\n    plots_show_parser.add_argument(\n        \"--no-csv-header\",\n        action=\"store_true\",\n        default=False,\n        help=\"Required when CSV or TSV datafile does not have a header.\",\n    )\n    plots_show_parser.add_argument(\n        \"--show-json\",\n        action=\"store_true\",\n        default=False,\n        help=\"Show output in JSON format.\",\n    )\n    plots_show_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n    plots_show_parser.add_argument(\n        \"--xlab\", default=None, help=\"X axis title.\"\n    )\n    plots_show_parser.add_argument(\n        \"--ylab\", default=None, help=\"Y axis title.\"\n    )\n    plots_show_parser.add_argument(\n        \"targets\",\n        nargs=\"*\",\n        help=\"Metrics files to visualize. Shows all plots by default.\",\n    )\n    plots_show_parser.set_defaults(func=CmdPlotsShow)\n\n    PLOTS_DIFF_HELP = (\n        \"Plot differences in metrics between commits in the DVC \"\n        \"repository, or between the last commit and the workspace.\"\n    )\n    plots_diff_parser = plots_subparsers.add_parser(\n        \"diff\",\n        parents=[parent_parser],\n        description=append_doc_link(PLOTS_DIFF_HELP, \"plots/diff\"),\n        help=PLOTS_DIFF_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_diff_parser.add_argument(\n        \"-t\",\n        \"--template\",\n        nargs=\"?\",\n        default=None,\n        help=(\n            \"Special JSON or HTML schema file to inject with the data. \"\n            \"See {}\".format(\n                format_link(\"https://man.dvc.org/plots#plot-templates\")\n            )\n        ),\n    )\n    plots_diff_parser.add_argument(\n        \"--targets\",\n        nargs=\"*\",\n        help=\"Metrics file to visualize. Shows all plots by default.\",\n    )\n    plots_diff_parser.add_argument(\n        \"-o\", \"--out\", default=None, help=\"Destination path to save plots to.\",\n    )\n    plots_diff_parser.add_argument(\n        \"-x\", default=None, help=\"Field name for x axis.\"\n    )\n    plots_diff_parser.add_argument(\n        \"-y\", default=None, help=\"Field name for y axis.\"\n    )\n    plots_diff_parser.add_argument(\n        \"--no-csv-header\",\n        action=\"store_true\",\n        default=False,\n        help=\"Provided CSV ot TSV datafile does not have a header.\",\n    )\n    plots_diff_parser.add_argument(\n        \"--show-json\",\n        action=\"store_true\",\n        default=False,\n        help=\"Show output in JSON format.\",\n    )\n    plots_diff_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n    plots_diff_parser.add_argument(\n        \"--xlab\", default=None, help=\"X axis title.\"\n    )\n    plots_diff_parser.add_argument(\n        \"--ylab\", default=None, help=\"Y axis title.\"\n    )\n    plots_diff_parser.add_argument(\n        \"revisions\", nargs=\"*\", default=None, help=\"Git commits to plot from\",\n    )\n    plots_diff_parser.set_defaults(func=CmdPlotsDiff)\n"}
filelevel_patches: {"dvc/command/plots.py": "@@ -33,6 +33,16 @@ def _func(self, *args, **kwargs):\n         raise NotImplementedError\n \n     def run(self):\n+        if self.args.show_vega:\n+            if not self.args.targets:\n+                logger.error(\"please specify a target for `--show-vega`\")\n+                return 1\n+            if len(self.args.targets) > 1:\n+                logger.error(\n+                    \"you can only specify one target for `--show-vega`\"\n+                )\n+                return 1\n+\n         try:\n             plots = self._func(\n                 targets=self.args.targets,\n@@ -45,10 +55,9 @@ def run(self):\n                 y_title=self.args.ylab,\n             )\n \n-            if self.args.show_json:\n-                import json\n-\n-                logger.info(json.dumps(plots))\n+            if self.args.show_vega:\n+                target = self.args.targets[0]\n+                logger.info(plots[target])\n                 return 0\n \n             divs = [\n@@ -138,10 +147,10 @@ def add_parser(subparsers, parent_parser):\n         help=\"Required when CSV or TSV datafile does not have a header.\",\n     )\n     plots_show_parser.add_argument(\n-        \"--show-json\",\n+        \"--show-vega\",\n         action=\"store_true\",\n         default=False,\n-        help=\"Show output in JSON format.\",\n+        help=\"Show output in VEGA format.\",\n     )\n     plots_show_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n     plots_show_parser.add_argument(\n@@ -201,10 +210,10 @@ def add_parser(subparsers, parent_parser):\n         help=\"Provided CSV ot TSV datafile does not have a header.\",\n     )\n     plots_diff_parser.add_argument(\n-        \"--show-json\",\n+        \"--show-vega\",\n         action=\"store_true\",\n         default=False,\n-        help=\"Show output in JSON format.\",\n+        help=\"Show output in VEGA format.\",\n     )\n     plots_diff_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n     plots_diff_parser.add_argument("}
messages.content: 
  We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  plots: replace --show-json with --show-vega
  Requested by @dmpetrov for cml. `--show-vega` should require a target and return a filled vega template. `--show-json` is not needed, let's delete it.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  
  --- BEGIN FILE ---
  ```
  ### dvc/command/plots.py
  import argparse
  import logging
  import os
  
  from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
  from dvc.exceptions import DvcException
  from dvc.utils import format_link
  
  logger = logging.getLogger(__name__)
  
  PAGE_HTML = """<!DOCTYPE html>
  <html>
  <head>
      <title>DVC Plot</title>
      <script src="https://cdn.jsdelivr.net/npm/vega@5.10.0"></script>
      <script src="https://cdn.jsdelivr.net/npm/vega-lite@4.8.1"></script>
      <script src="https://cdn.jsdelivr.net/npm/vega-embed@6.5.1"></script>
  </head>
  <body>
      {divs}
  </body>
  </html>"""
  
  DIV_HTML = """<div id = "{id}"></div>
  <script type = "text/javascript">
      var spec = {vega_json};
      vegaEmbed('#{id}', spec);
  </script>"""
  
  
  class CmdPlots(CmdBase):
      def _func(self, *args, **kwargs):
          raise NotImplementedError
  
      def run(self):
          try:
              plots = self._func(
                  targets=self.args.targets,
                  template=self.args.template,
                  x_field=self.args.x,
                  y_field=self.args.y,
                  csv_header=not self.args.no_csv_header,
                  title=self.args.title,
                  x_title=self.args.xlab,
                  y_title=self.args.ylab,
              )
  
              if self.args.show_json:
                  import json
  
                  logger.info(json.dumps(plots))
                  return 0
  
              divs = [
                  DIV_HTML.format(id=f"plot{i}", vega_json=plot)
                  for i, plot in enumerate(plots.values())
              ]
              html = PAGE_HTML.format(divs="\n".join(divs))
              path = self.args.out or "plots.html"
  
              with open(path, "w") as fobj:
                  fobj.write(html)
  
              logger.info(
                  "file://{}".format(os.path.join(self.repo.root_dir, path))
              )
  
          except DvcException:
              logger.exception("")
              return 1
  
          return 0
  
  
  class CmdPlotsShow(CmdPlots):
      def _func(self, *args, **kwargs):
          return self.repo.plots.show(*args, **kwargs)
  
  
  class CmdPlotsDiff(CmdPlots):
      def _func(self, *args, **kwargs):
          return self.repo.plots.diff(*args, revs=self.args.revisions, **kwargs)
  
  
  def add_parser(subparsers, parent_parser):
      PLOTS_HELP = (
          "Generating plots for metrics stored in structured files "
          "(JSON, CSV, TSV)."
      )
  
      plots_parser = subparsers.add_parser(
          "plots",
          parents=[parent_parser],
          description=append_doc_link(PLOTS_HELP, "plots"),
          help=PLOTS_HELP,
          formatter_class=argparse.RawDescriptionHelpFormatter,
      )
      plots_subparsers = plots_parser.add_subparsers(
          dest="cmd",
          help="Use `dvc plots CMD --help` to display command-specific help.",
      )
  
      fix_subparsers(plots_subparsers)
  
      SHOW_HELP = "Generate a plots image file from a metrics file."
      plots_show_parser = plots_subparsers.add_parser(
          "show",
          parents=[parent_parser],
          description=append_doc_link(SHOW_HELP, "plots/show"),
          help=SHOW_HELP,
          formatter_class=argparse.RawDescriptionHelpFormatter,
      )
      plots_show_parser.add_argument(
          "-t",
          "--template",
          nargs="?",
          default=None,
          help=(
              "Special JSON or HTML schema file to inject with the data. "
              "See {}".format(
                  format_link("https://man.dvc.org/plots#plot-templates")
              )
          ),
      )
      plots_show_parser.add_argument(
          "-o", "--out", default=None, help="Destination path to save plots to.",
      )
      plots_show_parser.add_argument(
          "-x", default=None, help="Field name for x axis."
      )
      plots_show_parser.add_argument(
          "-y", default=None, help="Field name for y axis."
      )
      plots_show_parser.add_argument(
          "--no-csv-header",
          action="store_true",
          default=False,
          help="Required when CSV or TSV datafile does not have a header.",
      )
      plots_show_parser.add_argument(
          "--show-json",
          action="store_true",
          default=False,
          help="Show output in JSON format.",
      )
      plots_show_parser.add_argument("--title", default=None, help="Plot title.")
      plots_show_parser.add_argument(
          "--xlab", default=None, help="X axis title."
      )
      plots_show_parser.add_argument(
          "--ylab", default=None, help="Y axis title."
      )
      plots_show_parser.add_argument(
          "targets",
          nargs="*",
          help="Metrics files to visualize. Shows all plots by default.",
      )
      plots_show_parser.set_defaults(func=CmdPlotsShow)
  
      PLOTS_DIFF_HELP = (
          "Plot differences in metrics between commits in the DVC "
          "repository, or between the last commit and the workspace."
      )
      plots_diff_parser = plots_subparsers.add_parser(
          "diff",
          parents=[parent_parser],
          description=append_doc_link(PLOTS_DIFF_HELP, "plots/diff"),
          help=PLOTS_DIFF_HELP,
          formatter_class=argparse.RawDescriptionHelpFormatter,
      )
      plots_diff_parser.add_argument(
          "-t",
          "--template",
          nargs="?",
          default=None,
          help=(
              "Special JSON or HTML schema file to inject with the data. "
              "See {}".format(
                  format_link("https://man.dvc.org/plots#plot-templates")
              )
          ),
      )
      plots_diff_parser.add_argument(
          "--targets",
          nargs="*",
          help="Metrics file to visualize. Shows all plots by default.",
      )
      plots_diff_parser.add_argument(
          "-o", "--out", default=None, help="Destination path to save plots to.",
      )
      plots_diff_parser.add_argument(
          "-x", default=None, help="Field name for x axis."
      )
      plots_diff_parser.add_argument(
          "-y", default=None, help="Field name for y axis."
      )
      plots_diff_parser.add_argument(
          "--no-csv-header",
          action="store_true",
          default=False,
          help="Provided CSV ot TSV datafile does not have a header.",
      )
      plots_diff_parser.add_argument(
          "--show-json",
          action="store_true",
          default=False,
          help="Show output in JSON format.",
      )
      plots_diff_parser.add_argument("--title", default=None, help="Plot title.")
      plots_diff_parser.add_argument(
          "--xlab", default=None, help="X axis title."
      )
      plots_diff_parser.add_argument(
          "--ylab", default=None, help="Y axis title."
      )
      plots_diff_parser.add_argument(
          "revisions", nargs="*", default=None, help="Git commits to plot from",
      )
      plots_diff_parser.set_defaults(func=CmdPlotsDiff)
  
  ```
  --- END FILE ---
  
  Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.
  
  Every *SEARCH/REPLACE* edit must use this format:
  1. The file path
  2. The start of search block: <<<<<<< SEARCH
  3. A contiguous chunk of lines to search for in the existing source code
  4. The dividing line: =======
  5. The lines to replace into the source code
  6. The end of the replace block: >>>>>>> REPLACE
  
  Here is an example:
  
  ```python
  ### mathweb/flask/app.py
  <<<<<<< SEARCH
  from flask import Flask
  =======
  import math
  from flask import Flask
  >>>>>>> REPLACE
  ```
  
  Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
  Wrap the *SEARCH/REPLACE* edit in blocks ```python...```.
  
messages.role: user
verification_info: {"file_context": {"dvc/command/plots.py": "import argparse\nimport logging\nimport os\n\nfrom dvc.command.base import CmdBase, append_doc_link, fix_subparsers\nfrom dvc.exceptions import DvcException\nfrom dvc.utils import format_link\n\nlogger = logging.getLogger(__name__)\n\nPAGE_HTML = \"\"\"<!DOCTYPE html>\n<html>\n<head>\n    <title>DVC Plot</title>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega@5.10.0\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega-lite@4.8.1\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/vega-embed@6.5.1\"></script>\n</head>\n<body>\n    {divs}\n</body>\n</html>\"\"\"\n\nDIV_HTML = \"\"\"<div id = \"{id}\"></div>\n<script type = \"text/javascript\">\n    var spec = {vega_json};\n    vegaEmbed('#{id}', spec);\n</script>\"\"\"\n\n\nclass CmdPlots(CmdBase):\n    def _func(self, *args, **kwargs):\n        raise NotImplementedError\n\n    def run(self):\n        try:\n            plots = self._func(\n                targets=self.args.targets,\n                template=self.args.template,\n                x_field=self.args.x,\n                y_field=self.args.y,\n                csv_header=not self.args.no_csv_header,\n                title=self.args.title,\n                x_title=self.args.xlab,\n                y_title=self.args.ylab,\n            )\n\n            if self.args.show_json:\n                import json\n\n                logger.info(json.dumps(plots))\n                return 0\n\n            divs = [\n                DIV_HTML.format(id=f\"plot{i}\", vega_json=plot)\n                for i, plot in enumerate(plots.values())\n            ]\n            html = PAGE_HTML.format(divs=\"\\n\".join(divs))\n            path = self.args.out or \"plots.html\"\n\n            with open(path, \"w\") as fobj:\n                fobj.write(html)\n\n            logger.info(\n                \"file://{}\".format(os.path.join(self.repo.root_dir, path))\n            )\n\n        except DvcException:\n            logger.exception(\"\")\n            return 1\n\n        return 0\n\n\nclass CmdPlotsShow(CmdPlots):\n    def _func(self, *args, **kwargs):\n        return self.repo.plots.show(*args, **kwargs)\n\n\nclass CmdPlotsDiff(CmdPlots):\n    def _func(self, *args, **kwargs):\n        return self.repo.plots.diff(*args, revs=self.args.revisions, **kwargs)\n\n\ndef add_parser(subparsers, parent_parser):\n    PLOTS_HELP = (\n        \"Generating plots for metrics stored in structured files \"\n        \"(JSON, CSV, TSV).\"\n    )\n\n    plots_parser = subparsers.add_parser(\n        \"plots\",\n        parents=[parent_parser],\n        description=append_doc_link(PLOTS_HELP, \"plots\"),\n        help=PLOTS_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_subparsers = plots_parser.add_subparsers(\n        dest=\"cmd\",\n        help=\"Use `dvc plots CMD --help` to display command-specific help.\",\n    )\n\n    fix_subparsers(plots_subparsers)\n\n    SHOW_HELP = \"Generate a plots image file from a metrics file.\"\n    plots_show_parser = plots_subparsers.add_parser(\n        \"show\",\n        parents=[parent_parser],\n        description=append_doc_link(SHOW_HELP, \"plots/show\"),\n        help=SHOW_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_show_parser.add_argument(\n        \"-t\",\n        \"--template\",\n        nargs=\"?\",\n        default=None,\n        help=(\n            \"Special JSON or HTML schema file to inject with the data. \"\n            \"See {}\".format(\n                format_link(\"https://man.dvc.org/plots#plot-templates\")\n            )\n        ),\n    )\n    plots_show_parser.add_argument(\n        \"-o\", \"--out\", default=None, help=\"Destination path to save plots to.\",\n    )\n    plots_show_parser.add_argument(\n        \"-x\", default=None, help=\"Field name for x axis.\"\n    )\n    plots_show_parser.add_argument(\n        \"-y\", default=None, help=\"Field name for y axis.\"\n    )\n    plots_show_parser.add_argument(\n        \"--no-csv-header\",\n        action=\"store_true\",\n        default=False,\n        help=\"Required when CSV or TSV datafile does not have a header.\",\n    )\n    plots_show_parser.add_argument(\n        \"--show-json\",\n        action=\"store_true\",\n        default=False,\n        help=\"Show output in JSON format.\",\n    )\n    plots_show_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n    plots_show_parser.add_argument(\n        \"--xlab\", default=None, help=\"X axis title.\"\n    )\n    plots_show_parser.add_argument(\n        \"--ylab\", default=None, help=\"Y axis title.\"\n    )\n    plots_show_parser.add_argument(\n        \"targets\",\n        nargs=\"*\",\n        help=\"Metrics files to visualize. Shows all plots by default.\",\n    )\n    plots_show_parser.set_defaults(func=CmdPlotsShow)\n\n    PLOTS_DIFF_HELP = (\n        \"Plot differences in metrics between commits in the DVC \"\n        \"repository, or between the last commit and the workspace.\"\n    )\n    plots_diff_parser = plots_subparsers.add_parser(\n        \"diff\",\n        parents=[parent_parser],\n        description=append_doc_link(PLOTS_DIFF_HELP, \"plots/diff\"),\n        help=PLOTS_DIFF_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    plots_diff_parser.add_argument(\n        \"-t\",\n        \"--template\",\n        nargs=\"?\",\n        default=None,\n        help=(\n            \"Special JSON or HTML schema file to inject with the data. \"\n            \"See {}\".format(\n                format_link(\"https://man.dvc.org/plots#plot-templates\")\n            )\n        ),\n    )\n    plots_diff_parser.add_argument(\n        \"--targets\",\n        nargs=\"*\",\n        help=\"Metrics file to visualize. Shows all plots by default.\",\n    )\n    plots_diff_parser.add_argument(\n        \"-o\", \"--out\", default=None, help=\"Destination path to save plots to.\",\n    )\n    plots_diff_parser.add_argument(\n        \"-x\", default=None, help=\"Field name for x axis.\"\n    )\n    plots_diff_parser.add_argument(\n        \"-y\", default=None, help=\"Field name for y axis.\"\n    )\n    plots_diff_parser.add_argument(\n        \"--no-csv-header\",\n        action=\"store_true\",\n        default=False,\n        help=\"Provided CSV ot TSV datafile does not have a header.\",\n    )\n    plots_diff_parser.add_argument(\n        \"--show-json\",\n        action=\"store_true\",\n        default=False,\n        help=\"Show output in JSON format.\",\n    )\n    plots_diff_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n    plots_diff_parser.add_argument(\n        \"--xlab\", default=None, help=\"X axis title.\"\n    )\n    plots_diff_parser.add_argument(\n        \"--ylab\", default=None, help=\"Y axis title.\"\n    )\n    plots_diff_parser.add_argument(\n        \"revisions\", nargs=\"*\", default=None, help=\"Git commits to plot from\",\n    )\n    plots_diff_parser.set_defaults(func=CmdPlotsDiff)\n"}, "filelevel_patches": {"dvc/command/plots.py": "@@ -33,6 +33,16 @@ def _func(self, *args, **kwargs):\n         raise NotImplementedError\n \n     def run(self):\n+        if self.args.show_vega:\n+            if not self.args.targets:\n+                logger.error(\"please specify a target for `--show-vega`\")\n+                return 1\n+            if len(self.args.targets) > 1:\n+                logger.error(\n+                    \"you can only specify one target for `--show-vega`\"\n+                )\n+                return 1\n+\n         try:\n             plots = self._func(\n                 targets=self.args.targets,\n@@ -45,10 +55,9 @@ def run(self):\n                 y_title=self.args.ylab,\n             )\n \n-            if self.args.show_json:\n-                import json\n-\n-                logger.info(json.dumps(plots))\n+            if self.args.show_vega:\n+                target = self.args.targets[0]\n+                logger.info(plots[target])\n                 return 0\n \n             divs = [\n@@ -138,10 +147,10 @@ def add_parser(subparsers, parent_parser):\n         help=\"Required when CSV or TSV datafile does not have a header.\",\n     )\n     plots_show_parser.add_argument(\n-        \"--show-json\",\n+        \"--show-vega\",\n         action=\"store_true\",\n         default=False,\n-        help=\"Show output in JSON format.\",\n+        help=\"Show output in VEGA format.\",\n     )\n     plots_show_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n     plots_show_parser.add_argument(\n@@ -201,10 +210,10 @@ def add_parser(subparsers, parent_parser):\n         help=\"Provided CSV ot TSV datafile does not have a header.\",\n     )\n     plots_diff_parser.add_argument(\n-        \"--show-json\",\n+        \"--show-vega\",\n         action=\"store_true\",\n         default=False,\n-        help=\"Show output in JSON format.\",\n+        help=\"Show output in VEGA format.\",\n     )\n     plots_diff_parser.add_argument(\"--title\", default=None, help=\"Plot title.\")\n     plots_diff_parser.add_argument("}}