from typing import Optional
from typing import List


def build_aws_cmd(
    profile: Optional[str], repo: str, subcommand: str, aws_args: Optional[List[str]] = None
) -> List[str]:
    """Build up an AWS ECR command from a subcommand and optional parts."""
    aws_cmd = ["aws", "ecr"]
    if profile:
        aws_cmd.append(f"--profile={profile}")
    aws_cmd.extend([f"--repository-name={repo}", "--output=json", subcommand])
    if aws_args:
        aws_cmd.extend(aws_args)
    return aws_cmd