diff --git a/src/snowflake/cli/_plugins/init/commands.py b/src/snowflake/cli/_plugins/init/commands.py index dc3de59c28..2dcb569e52 100644 --- a/src/snowflake/cli/_plugins/init/commands.py +++ b/src/snowflake/cli/_plugins/init/commands.py @@ -68,7 +68,8 @@ def _path_argument_callback(path: str) -> str: show_default=False, ) SourceOption = typer.Option( - default=DEFAULT_SOURCE, + DEFAULT_SOURCE, + "--template-source", help=f"local path to template directory or URL to git repository with templates.", ) VariablesOption = variables_option( @@ -132,13 +133,13 @@ def _fetch_remote_template( return template_root -def _read_template_metadata(template_root: SecurePath) -> Template: +def _read_template_metadata(template_root: SecurePath, args_error_msg: str) -> Template: """Parse template.yml file.""" template_metadata_path = template_root / TEMPLATE_METADATA_FILE_NAME log.debug("Reading template metadata from %s", template_metadata_path.path) if not template_metadata_path.exists(): raise InvalidTemplate( - f"Template does not have {TEMPLATE_METADATA_FILE_NAME} file." + f"File {TEMPLATE_METADATA_FILE_NAME} not found. {args_error_msg}" ) with template_metadata_path.open(read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB) as fd: yaml_contents = yaml.safe_load(fd) or {} @@ -203,6 +204,7 @@ def init( is_remote = any( template_source.startswith(prefix) for prefix in ["git@", "http://", "https://"] # type: ignore ) + args_error_msg = f"Check whether {TemplateOption.param_decls[0]} and {SourceOption.param_decls[0]} arguments are correct." # copy/download template into tmpdir, so it is going to be removed in case command ends with an error with SecurePath.temporary_directory() as tmpdir: @@ -217,7 +219,9 @@ def init( destination=tmpdir, ) - template_metadata = _read_template_metadata(template_root) + template_metadata = _read_template_metadata( + template_root, args_error_msg=args_error_msg + ) if template_metadata.minimum_cli_version: _validate_cli_version(template_metadata.minimum_cli_version) diff --git a/tests/test_init.py b/tests/test_init.py index a5ccac6ab0..15ae2b5437 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -63,7 +63,11 @@ def test_error_missing_template_yml(runner, test_projects_path, temp_dir): ] ) assert result.exit_code == 1 - assert "Template does not have template.yml file." in result.output + assert ( + "File template.yml not found. Check whether --template and --template-source" + in result.output + ) + assert "arguments are correct." in result.output assert not Path(project_name).exists() diff --git a/tests_integration/test_init.py b/tests_integration/test_init.py index 4116b03f56..90893ffd19 100644 --- a/tests_integration/test_init.py +++ b/tests_integration/test_init.py @@ -51,7 +51,11 @@ def test_missing_template_yml(runner, temporary_working_directory): result = runner.invoke(["init", path, "--template-source", url]) assert result.exit_code == 1 assert "Error" in result.output - assert f"Template does not have template.yml file." in result.output + assert ( + "File template.yml not found. Check whether --template and --template-source" + in result.output + ) + assert "arguments are correct" in result.output @pytest.mark.integration