mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 07:18:27 +01:00
experiments: add --show-json for exp show (#4689)
This commit is contained in:
@@ -3,7 +3,7 @@ import io
|
||||
import logging
|
||||
import os
|
||||
from collections import OrderedDict
|
||||
from datetime import date
|
||||
from datetime import date, datetime
|
||||
from itertools import groupby
|
||||
from typing import Iterable, Optional
|
||||
|
||||
@@ -255,6 +255,12 @@ def _show_experiments(all_experiments, console, **kwargs):
|
||||
console.print(table)
|
||||
|
||||
|
||||
def _format_json(item):
|
||||
if isinstance(item, (date, datetime)):
|
||||
return item.isoformat()
|
||||
raise TypeError
|
||||
|
||||
|
||||
class CmdExperimentsShow(CmdBase):
|
||||
def run(self):
|
||||
from rich.console import Console
|
||||
@@ -272,6 +278,12 @@ class CmdExperimentsShow(CmdBase):
|
||||
sha_only=self.args.sha,
|
||||
)
|
||||
|
||||
if self.args.show_json:
|
||||
import json
|
||||
|
||||
logger.info(json.dumps(all_experiments, default=_format_json))
|
||||
return 0
|
||||
|
||||
if self.args.no_pager:
|
||||
console = Console()
|
||||
else:
|
||||
@@ -530,6 +542,12 @@ def add_parser(subparsers, parent_parser):
|
||||
default=False,
|
||||
help="Always show git commit SHAs instead of branch/tag names.",
|
||||
)
|
||||
experiments_show_parser.add_argument(
|
||||
"--show-json",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Print output in JSON format instead of a human-readable table.",
|
||||
)
|
||||
experiments_show_parser.set_defaults(func=CmdExperimentsShow)
|
||||
|
||||
EXPERIMENTS_CHECKOUT_HELP = "Checkout experiments."
|
||||
|
||||
Reference in New Issue
Block a user