Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions gto/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def make_ready_to_serialize(
)


def _format_line_value(value):
return str(value).rstrip("\r\n")


def format_echo(result, format, format_table=None, if_empty="", missing_value="-"):
if format == "yaml":
yaml.dump(make_ready_to_serialize(result), sys.stdout)
Expand All @@ -69,9 +73,9 @@ def format_echo(result, format, format_table=None, if_empty="", missing_value="-
elif format == "lines":
if result:
for line in result:
click.echo(line)
click.echo(_format_line_value(line))
elif format == "line":
if result:
click.echo(result)
click.echo(_format_line_value(result))
else:
raise NotImplementedError(f"Format {format} is not implemented")
8 changes: 8 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,14 @@ def test_show_line_flag_empty_result():
_check_successful_cmd("show", ["-r", ".", "m5#missing", "--version"], "")


def test_show_line_flags_strip_value_newlines():
output = ([{"ref": "rf@v1.2.4\n", "version": "v1.2.4\r\n"}], "keys")
with mock.patch("gto.api.show", return_value=output):
_check_successful_cmd("show", ["-r", ".", "rf@latest", "--ref"], "rf@v1.2.4\n")
with mock.patch("gto.api.show", return_value=output):
_check_successful_cmd("show", ["-r", ".", "rf@latest", "--version"], "v1.2.4\n")


def test_history_json_empty(repo_with_commit: str):
_check_successful_cmd("history", ["-r", repo_with_commit, "--json"], "[]\n")

Expand Down
Loading