Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/datacustomcode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
Expand Down Expand Up @@ -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
)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_sf_cli_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
Loading