push: improve 'no remote specified' hint

Fixes #3121
This commit is contained in:
Fábio Santos
2020-01-22 17:09:00 +00:00
parent 74bbc3bc04
commit abbe29e58e
2 changed files with 18 additions and 8 deletions
+15 -7
View File
@@ -24,13 +24,21 @@ class ConfigError(DvcException):
class NoRemoteError(ConfigError):
def __init__(self, command):
msg = (
"no remote specified. Setup default remote with\n"
" dvc remote default <name>\n"
"or use:\n"
" dvc {} -r <name>\n".format(command)
)
def __init__(self, command, *, has_any_remote=True):
if has_any_remote:
msg = (
"no remote specified. Setup default remote with\n"
" dvc remote default <remote name>\n"
"or use:\n"
" dvc {} -r <remote name>".format(command)
)
else:
msg = (
"no remote specified. Create a remote with\n"
" dvc remote add <remote name> <remote url>\n"
"To create a default remote use the -d flag:\n"
" dvc remote add -d <remote name> <remote url>\n"
)
super().__init__(msg)
+3 -1
View File
@@ -39,7 +39,9 @@ class DataCloud(object):
if remote:
return self._init_remote(remote)
raise NoRemoteError(command)
has_any_remote = any(key.startswith("remote ") for key in self._config)
raise NoRemoteError(command, has_any_remote=has_any_remote)
def _init_remote(self, remote):
return Remote(self.repo, name=remote)