diff: add JSON output

This commit is contained in:
Mr. Outis
2020-01-26 13:25:38 -06:00
parent b251682aec
commit a4ade13c0a
2 changed files with 34 additions and 11 deletions
+15 -1
View File
@@ -1,4 +1,5 @@
import argparse
import json
import logging
from dvc.command.base import CmdBase, append_doc_link
@@ -11,9 +12,16 @@ logger = logging.getLogger(__name__)
class CmdDiff(CmdBase):
def run(self):
try:
self.repo.diff(
diff = self.repo.diff(
self.args.a_ref, self.args.b_ref, target=self.args.target
)
if not any(diff.values()):
return 0
if self.args.json:
print(json.dumps(diff))
return 0
except DvcException:
logger.exception("failed to get 'diff {}'")
return 1
@@ -56,4 +64,10 @@ def add_parser(subparsers, parent_parser):
"that are under DVC control in the current working space."
),
)
diff_parser.add_argument(
"--json",
help=("Format the output into a JSON"),
action="store_true",
default=False,
)
diff_parser.set_defaults(func=CmdDiff)