Skip to content

Commit e455ee6

Browse files
authored
remote: show default when run "dvc remote list" (#10711)
* remote: show default when run "dvc remote list" Fixes #10708 * Indent other remotes if there is a default remote Now regardless of whether there is a default remote or not, all remotes are equally indented * stricter test for listing remotes shows default * Rewrite dvc remote list implemetation - Default remote is indicated at end of the output and colored green - Remotes no longer reordered to show default first - Test updated to reflect changes and remove need for function escape_ansi. --------- Co-authored-by: RMCrean <RMCrean@users.noreply.github.com>
1 parent 31270c1 commit e455ee6

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

dvc/commands/remote.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,16 @@ def run(self):
110110
class CmdRemoteList(CmdRemote):
111111
def run(self):
112112
conf = self.config.read(self.args.level)
113+
default_remote = conf["core"].get("remote")
114+
113115
for name, remote_conf in conf["remote"].items():
114-
ui.write(name, remote_conf["url"], sep="\t")
116+
if name == default_remote:
117+
text = f"{name}\t{remote_conf['url']}\t(default)"
118+
color = "green"
119+
else:
120+
text = f"{name}\t{remote_conf['url']}"
121+
color = ""
122+
ui.write(ui.rich_text(text, style=color), styled=True)
115123
return 0
116124

117125

tests/func/test_remote.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ def test_show_default(dvc, capsys):
115115
assert out == "foo\n"
116116

117117

118+
def test_list_shows_default(dvc, capsys):
119+
default_remote = "foo"
120+
other_remote = "bar"
121+
bucket_url = "s3://bucket/name"
122+
assert main(["remote", "add", default_remote, bucket_url]) == 0
123+
assert main(["remote", "add", other_remote, bucket_url]) == 0
124+
assert main(["remote", "default", default_remote]) == 0
125+
assert main(["remote", "list"]) == 0
126+
out, _ = capsys.readouterr()
127+
out_lines = out.splitlines()
128+
assert out_lines[0].split() == [default_remote, bucket_url, "(default)"]
129+
assert out_lines[1].split() == [other_remote, bucket_url]
130+
131+
118132
def test_upper_case_remote(tmp_dir, dvc, local_cloud):
119133
remote_name = "UPPERCASEREMOTE"
120134

0 commit comments

Comments
 (0)