diff --git a/conans/client/command.py b/conans/client/command.py index f1021810a54..a5deb03f6b4 100644 --- a/conans/client/command.py +++ b/conans/client/command.py @@ -564,7 +564,7 @@ def config(self, *args): install_subparser.add_argument("--verify-ssl", nargs="?", default="True", help='Verify SSL connection when downloading file') - install_subparser.add_argument("--type", "-t", choices=["git"], + install_subparser.add_argument("--type", "-t", choices=["git", "dir", "file", "url"], help='Type of remote config') install_subparser.add_argument("--args", "-a", help='String with extra arguments for "git clone"') diff --git a/conans/client/conf/config_installer.py b/conans/client/conf/config_installer.py index 4a78558b909..72ea8f0c7e7 100644 --- a/conans/client/conf/config_installer.py +++ b/conans/client/conf/config_installer.py @@ -87,6 +87,8 @@ def _filecopy(src, filename, dst): def _process_folder(config, folder, cache, output): + if not os.path.isdir(folder): + raise ConanException("No such directory: '%s'" % str(folder)) if config.source_folder: folder = os.path.join(folder, config.source_folder) for root, dirs, files in walk(folder): diff --git a/conans/test/functional/command/config_install_test.py b/conans/test/functional/command/config_install_test.py index 1d91122c520..1effcbf91de 100644 --- a/conans/test/functional/command/config_install_test.py +++ b/conans/test/functional/command/config_install_test.py @@ -205,21 +205,23 @@ def build(self): self.client.run("create . Pkg/0.1@user/testing") self.assertIn("A is 3", self.client.out) - def install_file_test(self): + def test_install_file_test(self): """ should install from a file in current dir """ zippath = self._create_zip() - self.client.run('config install "%s"' % zippath) - self._check("file, %s, True, None" % zippath) - self.assertTrue(os.path.exists(zippath)) + for type in ["", "--type=file"]: + self.client.run('config install "%s" %s' % (zippath, type)) + self._check("file, %s, True, None" % zippath) + self.assertTrue(os.path.exists(zippath)) - def install_dir_test(self): + def test_install_dir_test(self): """ should install from a dir in current dir """ folder = self._create_profile_folder() self.assertTrue(os.path.isdir(folder)) - self.client.run('config install "%s"' % folder) - self._check("dir, %s, True, None" % folder) + for type in ["", "--type=dir"]: + self.client.run('config install "%s" %s' % (folder, type)) + self._check("dir, %s, True, None" % folder) def install_source_target_folders_test(self): folder = temp_folder() @@ -302,20 +304,21 @@ def test_without_profile_folder(self): self.assertEqual(load(os.path.join(self.client.cache.profiles_path, "linux")).splitlines(), linux_profile.splitlines()) - def install_url_test(self): + def test_install_url(self): """ should install from a URL """ - def my_download(obj, url, filename, **kwargs): # @UnusedVariable - self._create_zip(filename) + for type in ["", "--type=url"]: + def my_download(obj, url, filename, **kwargs): # @UnusedVariable + self._create_zip(filename) - with patch.object(FileDownloader, 'download', new=my_download): - self.client.run("config install http://myfakeurl.com/myconf.zip") - self._check("url, http://myfakeurl.com/myconf.zip, True, None") + with patch.object(FileDownloader, 'download', new=my_download): + self.client.run("config install http://myfakeurl.com/myconf.zip %s" % type) + self._check("url, http://myfakeurl.com/myconf.zip, True, None") - # repeat the process to check - self.client.run("config install http://myfakeurl.com/myconf.zip") - self._check("url, http://myfakeurl.com/myconf.zip, True, None") + # repeat the process to check + self.client.run("config install http://myfakeurl.com/myconf.zip %s" % type) + self._check("url, http://myfakeurl.com/myconf.zip, True, None") def install_change_only_verify_ssl_test(self): def my_download(obj, url, filename, **kwargs): # @UnusedVariable @@ -390,11 +393,28 @@ def install_custom_args_test(self): check_path = os.path.join(folder, ".git") self._check("git, %s, True, -c init.templateDir=value" % check_path) - def force_git_type_test(self): + def test_force_git_type(self): client = TestClient() client.run('config install httpnonexisting --type=git', assert_error=True) self.assertIn("Can't clone repo", client.out) + def test_force_dir_type(self): + client = TestClient() + client.run('config install httpnonexisting --type=dir', assert_error=True) + self.assertIn("ERROR: Failed conan config install: No such directory: 'httpnonexisting'", + client.out) + + def test_force_file_type(self): + client = TestClient() + client.run('config install httpnonexisting --type=file', assert_error=True) + self.assertIn("No such file or directory: 'httpnonexisting'", client.out) + + def test_force_url_type(self): + client = TestClient() + client.run('config install httpnonexisting --type=url', assert_error=True) + self.assertIn("Error downloading file httpnonexisting: 'Invalid URL 'httpnonexisting'", + client.out) + def reinstall_error_test(self): """ should use configured URL in conan.conf """