mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 23:10:24 +01:00
command: Show dvc list output with pretty JSON format if output to tty (#6647)
1. update ls __init__.py to output pretty JSON format 2. introduce write_json function into ui __init__.py Co-authored-by: Zhenyu Gao <[email protected]>
This commit is contained in:
@@ -35,9 +35,7 @@ class CmdList(CmdBaseNoRepo):
|
||||
dvc_only=self.args.dvc_only,
|
||||
)
|
||||
if self.args.show_json:
|
||||
import json
|
||||
|
||||
ui.write(json.dumps(entries))
|
||||
ui.write_json(entries)
|
||||
elif entries:
|
||||
entries = _prettify(entries, with_color=True)
|
||||
ui.write("\n".join(entries))
|
||||
|
||||
@@ -82,6 +82,20 @@ class Console:
|
||||
styled=styled,
|
||||
)
|
||||
|
||||
def write_json(
|
||||
self,
|
||||
data: Any,
|
||||
indent: int = 2,
|
||||
) -> None:
|
||||
if sys.stdout.isatty():
|
||||
from rich.json import JSON
|
||||
|
||||
j = JSON.from_data(data, indent=indent)
|
||||
return self.write(j, styled=True)
|
||||
import json
|
||||
|
||||
return self.write(json.dumps(data))
|
||||
|
||||
def write(
|
||||
self,
|
||||
*objects: Any,
|
||||
|
||||
@@ -34,7 +34,7 @@ tabulate>=0.8.7
|
||||
pygtrie>=2.3.2
|
||||
dpath>=2.0.2,<3
|
||||
shtab>=1.3.4,<2
|
||||
rich>=10.0.0
|
||||
rich>=10.9.0
|
||||
dictdiffer>=0.8.1
|
||||
python-benedict>=0.21.1
|
||||
pyparsing==2.4.7
|
||||
|
||||
Reference in New Issue
Block a user