diff --git a/src/datacustomcode/cli.py b/src/datacustomcode/cli.py index 84da911..e283995 100644 --- a/src/datacustomcode/cli.py +++ b/src/datacustomcode/cli.py @@ -198,6 +198,11 @@ def zip(path: str, network: str): default=None, help="SF CLI org alias or username. Fetches credentials via `sf org display`.", ) +@click.option( + "--use-in-feature", + default="SearchIndexChunking", + help="Feature where this function will be used.", +) def deploy( path: str, name: str, @@ -207,6 +212,7 @@ def deploy( profile: str, network: str, sf_cli_org: Optional[str], + use_in_feature: Optional[str], ): from datacustomcode.constants import USE_IN_FEATURE_MAPPING_FOR_CONNECT_API from datacustomcode.deploy import ( @@ -242,20 +248,18 @@ def deploy( ) if package_type == "function": - # Infer use_in_feature from function signature + # Try to infer use_in_feature from function signature; fall back to + # the explicit flag value (defaults to SearchIndexChunking) entrypoint_path = os.path.join(path, ENTRYPOINT_FILE) - use_in_feature = infer_use_in_feature(entrypoint_path) - if use_in_feature: + inferred = infer_use_in_feature(entrypoint_path) + if inferred: + use_in_feature = inferred logger.info(f"Inferred use_in_feature: {use_in_feature}") else: - click.secho( - "Error: Could not infer function invoke options. " - "Please provide --use-in-feature", - fg="red", - ) - raise click.Abort() + logger.info(f"Using use_in_feature: {use_in_feature}") - # Map user-provided feature names to API names + assert use_in_feature is not None + # Map feature names to Connect API names mapped_feature = USE_IN_FEATURE_MAPPING_FOR_CONNECT_API.get( use_in_feature, use_in_feature ) diff --git a/tests/test_sf_cli_contract.py b/tests/test_sf_cli_contract.py index f53123e..61f7f15 100644 --- a/tests/test_sf_cli_contract.py +++ b/tests/test_sf_cli_contract.py @@ -188,6 +188,26 @@ def test_accepts_network_flag( result = runner.invoke(deploy, [*self._BASE_ARGS, "--network", "custom"]) assert result.exit_code != 2, result.output + @patch("datacustomcode.token_provider.SFCLITokenProvider") + @patch("datacustomcode.deploy.deploy_full") + @patch("datacustomcode.cli.find_base_directory") + @patch("datacustomcode.cli.get_package_type") + def test_accepts_use_in_feature_flag( + self, mock_pkg_type, mock_find_base, mock_deploy_full, mock_sf_cli_provider + ): + mock_find_base.return_value = "payload" + mock_pkg_type.return_value = "function" + mock_provider_instance = mock_sf_cli_provider.return_value + mock_provider_instance.get_token.return_value = AccessTokenResponse( + access_token="tok", instance_url="https://example.com" + ) + runner = CliRunner() + result = runner.invoke( + deploy, + [*self._BASE_ARGS, "--use-in-feature", "SearchIndexChunking"], + ) + assert result.exit_code != 2, result.output + class TestRunArgContract: """