ronantakizawa/codereview-bench huggingface dataset:
Repository: k3s-io/k3s
File: contrib/util/check-config.sh (Shell)

Code before:
  fi

  totalSwap=$(free | grep -i '^swap:' | awk '{ print $2 }')
  if [ "$totalSwap" != "0" ]; then
    wrap_warn '- swap' 'should be disabled'
  else
    wrap_good '- swap' 'disabled'
  fi

  if ip route | grep -v cni0 | grep -q -E '^10\.(42|43)\.'; then
    wrap_warn '- routes' 'default CIDRs 10.42.0.0/16 or 10.43.0.0/16 already routed'
  else
    wrap_good '- routes' 'ok'
  fi
}

SUDO=
[ $(id -u) -ne 0 ] && SUDO=sudo

check_firewall_ports() {
  ports="6443 10250 5001 2379 2380"
  blocked_ports=""

  for port in $ports; do
    if [ "$1" = "firewalld" ]; then
      if $SUDO firewall-cmd --list-ports | grep -q "$port/tcp"; then
        blocked_ports="$blocked_ports $port "
      fi
    elif [ "$1" = "ufw" ]; then
      if $SUDO ufw status | grep -q "$port/tcp\s\+DENY"; then
        blocked_ports="$blocked_ports $port "
      fi
    fi
  done
  
  if [ -n "$blocked_ports" ]; then
    for port in $blocked_ports; do
      wrap_bad "  - Port $port is blocked"
    done
  fi
}

if check_command firewall-cmd; then
  if $SUDO firewall-cmd --state >/dev/null 2>&1; then
    echo
    echo 'Firewall:'
    wrap_warn "- firewalld" "is enabled"
    check_firewall_ports "firewalld"
  fi
fi


Review comment (suggestion):
```suggestion
      if $SUDO firewall-cmd --list-ports | grep -qv "$port/tcp"; then
```

This is backwards, firewall-cmd shows a list of OPEN ports ...

Code after:
  fi

  totalSwap=$(free | grep -i '^swap:' | awk '{ print $2 }')
  if [ "$totalSwap" != "0" ]; then
    wrap_warn '- swap' 'should be disabled'
  else
    wrap_good '- swap' 'disabled'
  fi

  if ip route | grep -v cni0 | grep -q -E '^10\.(42|43)\.'; then
    wrap_warn '- routes' 'default CIDRs 10.42.0.0/16 or 10.43.0.0/16 already routed'
  else
    wrap_good '- routes' 'ok'
  fi
}

SUDO=
[ $(id -u) -ne 0 ] && SUDO=sudo

check_firewall_ports() {
  fw_prog="$1"
  tcp_ports="6443 10250 5001 2379 2380"
  udp_ports="8472 51820 51821"
  blocked_tcp_ports=""
  blocked_udp_ports=""
  open_ports=""

  # returns 0 if port is blocked
  is_blocked() {
    local port=$1 proto=$2
    if [ "$fw_prog" = "firewalld" ]; then
      ! $SUDO firewall-cmd --list-ports | grep -q "$port/$proto"
    elif [ "$fw_prog" = "ufw" ]; then
      $SUDO ufw status | grep -q "$port/$proto\s\+DENY"
    else
      warning "unknown firewall program: $fw_prog"
      return 1
    fi
  }
  
  for port in $tcp_ports; do
    if is_blocked "$port" "tcp"; then
      blocked_tcp_ports="$blocked_tcp_ports $port "
    else
      open_ports="$open_ports $port "
    fi
  done
  for port in $udp_ports; do
    if is_blocked "$port" "udp"; then
      blocked_udp_ports="$blocked_udp_ports $port "
    else
Repository: k3s-io/k3s
File: contrib/util/check-config.sh (Shell)

Code before:
      ! $SUDO firewall-cmd --list-ports | grep -q "$port/$proto"
    elif [ "$fw_prog" = "ufw" ]; then
      $SUDO ufw status | grep -q "$port/$proto\s\+DENY"
    else
      warning "unknown firewall program: $fw_prog"
      return 1
    fi
  }
  
  for port in $tcp_ports; do
    if is_blocked "$port" "tcp"; then
      blocked_tcp_ports="$blocked_tcp_ports $port "
    else
      open_ports="$open_ports $port "
    fi
  done
  for port in $udp_ports; do
    if is_blocked "$port" "udp"; then
      blocked_udp_ports="$blocked_udp_ports $port "
    else
      open_ports="$open_ports $port "
    fi
  done
  
  for port in $blocked_tcp_ports; do
    wrap_bad "  - Port $port is blocked"
  done
  for port in $blocked_udp_ports; do
    wrap_warn "  - Port $port is blocked" "Required for Flannel VXLAN/WireGuard"
  done
  for port in $open_ports; do
    wrap_good "  - Port $port is open" 'ok'
  done
}

if check_command firewall-cmd; then
  if $SUDO firewall-cmd --state >/dev/null 2>&1; then
    echo
    echo 'Firewall:'
    wrap_warn "- firewalld" "is enabled"
    check_firewall_ports "firewalld"
  fi
fi

# Check for ufw
if check_command ufw; then
  if $SUDO ufw status | grep -q "Status: active"; then
    echo
    echo 'Firewall:'
    wrap_warn "- ufw" "is enabled"
    check_firewall_ports "ufw"

Review comment (suggestion):
```suggestion
    wrap_bad "  - TCP Port $port is blocked"
```

Code after:
      ! $SUDO firewall-cmd --list-ports | grep -q "$port/$proto"
    elif [ "$fw_prog" = "ufw" ]; then
      $SUDO ufw status | grep -q "$port/$proto\s\+DENY"
    else
      warning "unknown firewall program: $fw_prog"
      return 1
    fi
  }
  
  for port in $tcp_ports; do
    if is_blocked "$port" "tcp"; then
      blocked_tcp_ports="$blocked_tcp_ports $port "
    else
      open_ports="$open_ports $port "
    fi
  done
  for port in $udp_ports; do
    if is_blocked "$port" "udp"; then
      blocked_udp_ports="$blocked_udp_ports $port "
    else
      open_ports="$open_ports $port "
    fi
  done
  
  for port in $blocked_tcp_ports; do
    wrap_bad "  - TCP Port $port is blocked"
  done
  for port in $blocked_udp_ports; do
    wrap_warn "  - UDP Port $port is blocked" "Required for Flannel VXLAN/WireGuard"
  done
  for port in $open_ports; do
    wrap_good "  - Port $port is open" 'ok'
  done
}

if check_command firewall-cmd; then
  if $SUDO firewall-cmd --state >/dev/null 2>&1; then
    echo
    echo 'Firewall:'
    wrap_warn "- firewalld" "is enabled"
    check_firewall_ports "firewalld"
  fi
fi

# Check for ufw
if check_command ufw; then
  if $SUDO ufw status | grep -q "Status: active"; then
    echo
    echo 'Firewall:'
    wrap_warn "- ufw" "is enabled"
    check_firewall_ports "ufw"
Repository: k3s-io/k3s
File: install.sh (Shell)

Code before:
#     Name of systemd service to create, will default from the k3s exec command
#     if not specified. If specified the name will be prefixed with 'k3s-'.
#
#   - INSTALL_K3S_TYPE
#     Type of systemd service to create, will default from the k3s exec command
#     if not specified.
#
#   - INSTALL_K3S_SELINUX_WARN
#     If set to true will continue if k3s-selinux policy is not found.
#
#   - INSTALL_K3S_SKIP_SELINUX_RPM
#     If set to true will skip automatic installation of the k3s RPM.
#
#   - INSTALL_K3S_CHANNEL_URL
#     Channel URL for fetching k3s download URL.
#     Defaults to 'https://update.k3s.io/v1-release/channels'.
#
#   - INSTALL_K3S_CHANNEL
#     Channel to use for fetching k3s download URL.
#     Defaults to 'stable'.

INSTALL_K3S_ARTIFACT_URL=${INSTALL_K3S_ARTIFACT_URL:-https://github.com/k3s-io/k3s/releases/download}

# GITHUB_URL was replaced by INSTALL_K3S_ARTIFACT_URL
if [ -n "$GITHUB_URL" ]; then
    echo "WARNING: 'GITHUB_URL' is deprecated and will be removed in a future release." >&2
    echo "Please use 'INSTALL_K3S_ARTIFACT_URL' instead." >&2
fi
GITHUB_ART_URL=""
DOWNLOADER=

# --- helper functions for logs ---
info()
{
    echo '[INFO] ' "$@"
}
warn()
{
    echo '[WARN] ' "$@" >&2
}
fatal()
{
    echo '[ERROR] ' "$@" >&2
    exit 1
}

# --- fatal if no systemd or openrc ---
verify_system() {
    if [ -x /sbin/openrc-run ]; then
        HAS_OPENRC=true
        return

Review comment (suggestion):
This isn't accurate - deprecated would indicate that it is outdated but still works. It doesn't work and support for it has already been removed.

Either make it work again, or correct the warning to indicate that support for it is CURRENTLY removed.

Code after:
#     Name of systemd service to create, will default from the k3s exec command
#     if not specified. If specified the name will be prefixed with 'k3s-'.
#
#   - INSTALL_K3S_TYPE
#     Type of systemd service to create, will default from the k3s exec command
#     if not specified.
#
#   - INSTALL_K3S_SELINUX_WARN
#     If set to true will continue if k3s-selinux policy is not found.
#
#   - INSTALL_K3S_SKIP_SELINUX_RPM
#     If set to true will skip automatic installation of the k3s RPM.
#
#   - INSTALL_K3S_CHANNEL_URL
#     Channel URL for fetching k3s download URL.
#     Defaults to 'https://update.k3s.io/v1-release/channels'.
#
#   - INSTALL_K3S_CHANNEL
#     Channel to use for fetching k3s download URL.
#     Defaults to 'stable'.

INSTALL_K3S_ARTIFACT_URL=${INSTALL_K3S_ARTIFACT_URL:-https://github.com/k3s-io/k3s/releases/download}
GITHUB_ART_URL=""
DOWNLOADER=

# --- helper functions for logs ---
info()
{
    echo '[INFO] ' "$@"
}
warn()
{
    echo '[WARN] ' "$@" >&2
}
fatal()
{
    echo '[ERROR] ' "$@" >&2
    exit 1
}

# --- fatal if no systemd or openrc ---
verify_system() {
    if [ -x /sbin/openrc-run ]; then
        HAS_OPENRC=true
        return
    fi
    if [ -x /bin/systemctl ] || type systemctl > /dev/null 2>&1; then
        HAS_SYSTEMD=true
        return
    fi
    fatal 'Can not find systemd or openrc to use as a process supervisor for k3s'
Repository: k3s-io/k3s
File: install.sh (Shell)

Code before:
#     Name of systemd service to create, will default from the k3s exec command
#     if not specified. If specified the name will be prefixed with 'k3s-'.
#
#   - INSTALL_K3S_TYPE
#     Type of systemd service to create, will default from the k3s exec command
#     if not specified.
#
#   - INSTALL_K3S_SELINUX_WARN
#     If set to true will continue if k3s-selinux policy is not found.
#
#   - INSTALL_K3S_SKIP_SELINUX_RPM
#     If set to true will skip automatic installation of the k3s RPM.
#
#   - INSTALL_K3S_CHANNEL_URL
#     Channel URL for fetching k3s download URL.
#     Defaults to 'https://update.k3s.io/v1-release/channels'.
#
#   - INSTALL_K3S_CHANNEL
#     Channel to use for fetching k3s download URL.
#     Defaults to 'stable'.

INSTALL_K3S_ARTIFACT_URL=${INSTALL_K3S_ARTIFACT_URL:-https://github.com/k3s-io/k3s/releases/download}

# GITHUB_URL was replaced by INSTALL_K3S_ARTIFACT_URL
if [ -n "$GITHUB_URL" ]; then
    echo "WARNING: 'GITHUB_URL' does not work anymore. Please use 'INSTALL_K3S_ARTIFACT_URL' instead." >&2
fi
GITHUB_ART_URL=""
DOWNLOADER=

# --- helper functions for logs ---
info()
{
    echo '[INFO] ' "$@"
}
warn()
{
    echo '[WARN] ' "$@" >&2
}
fatal()
{
    echo '[ERROR] ' "$@" >&2
    exit 1
}

# --- fatal if no systemd or openrc ---
verify_system() {
    if [ -x /sbin/openrc-run ]; then
        HAS_OPENRC=true
        return
    fi

Review comment (refactor):
We have info/warn/error helpers, use those:
```suggestion
    warn "'GITHUB_URL' does not work anymore. Please use 'INSTALL_K3S_ARTIFACT_URL' instead."
```

You'll need to move this down below the function definitions to do that - perhaps next to the `VERSION_URLSAFE` on line 390?

Code after:
#     Name of systemd service to create, will default from the k3s exec command
#     if not specified. If specified the name will be prefixed with 'k3s-'.
#
#   - INSTALL_K3S_TYPE
#     Type of systemd service to create, will default from the k3s exec command
#     if not specified.
#
#   - INSTALL_K3S_SELINUX_WARN
#     If set to true will continue if k3s-selinux policy is not found.
#
#   - INSTALL_K3S_SKIP_SELINUX_RPM
#     If set to true will skip automatic installation of the k3s RPM.
#
#   - INSTALL_K3S_CHANNEL_URL
#     Channel URL for fetching k3s download URL.
#     Defaults to 'https://update.k3s.io/v1-release/channels'.
#
#   - INSTALL_K3S_CHANNEL
#     Channel to use for fetching k3s download URL.
#     Defaults to 'stable'.

INSTALL_K3S_ARTIFACT_URL=${INSTALL_K3S_ARTIFACT_URL:-https://github.com/k3s-io/k3s/releases/download}
GITHUB_ART_URL=""
DOWNLOADER=

# --- helper functions for logs ---
info()
{
    echo '[INFO] ' "$@"
}
warn()
{
    echo '[WARN] ' "$@" >&2
}
fatal()
{
    echo '[ERROR] ' "$@" >&2
    exit 1
}

# --- fatal if no systemd or openrc ---
verify_system() {
    if [ -x /sbin/openrc-run ]; then
        HAS_OPENRC=true
        return
    fi
    if [ -x /bin/systemctl ] || type systemctl > /dev/null 2>&1; then
        HAS_SYSTEMD=true
        return
    fi
    fatal 'Can not find systemd or openrc to use as a process supervisor for k3s'
Repository: k3s-io/k3s
File: pkg/agent/flannel/flannel.go (Go)

Code before:
	if dir == "" {
		dir = "."
	}
	if err := os.MkdirAll(dir, 0755); err != nil {
		return err
	}

	// Preserve original file permissions if the file already exists
	perm := os.FileMode(0644)
	if info, err := os.Stat(path); err == nil {
		perm = info.Mode().Perm()
	}

	f, err := os.CreateTemp(dir, "."+name+".")
	if err != nil {
		return err
	}
	tempFile := f.Name()
	cleanup := func() {
		f.Close()
		_ = os.Remove(tempFile)
	}
	if err := f.Chmod(perm); err != nil {
		cleanup()
		return err
	}

	// Write out the first usable IP by incrementing
	// sn.IP by one
	sn := bn.Lease().Subnet
	sn.IP++
	if nm.IPv4Enabled() {
		if _, err := fmt.Fprintf(f, "FLANNEL_NETWORK=%s\n", nw); err != nil {
			cleanup()
			return err
		}
		if _, err := fmt.Fprintf(f, "FLANNEL_SUBNET=%s\n", sn); err != nil {
			cleanup()
			return err
		}
	}

	if nwv6.String() != emptyIPv6Network {
		snv6 := bn.Lease().IPv6Subnet
		snv6.IncrementIP()
		if _, err := fmt.Fprintf(f, "FLANNEL_IPV6_NETWORK=%s\n", nwv6); err != nil {
			cleanup()
			return err
		}
		if _, err := fmt.Fprintf(f, "FLANNEL_IPV6_SUBNET=%s\n", snv6); err != nil {
			cleanup()

Review comment (suggestion):
nit: pass the error through cleanup so that you can just call `return cleanup(err)` in your error handling below. Also, should we use `rancher/wrangler/pkg/merr` to include the errors from close/rename?
```suggestion
	cleanup := func(err error) error {
		return merr.NewErrors(err, f.Close(), os.Remove(tempFile))
	}
	if err := f.Chmod(perm); err != nil {
		return cleanup(err)
	}
```

Code after:
	dir, name := filepath.Split(path)
	if dir == "" {
		dir = "."
	}
	if err := os.MkdirAll(dir, 0755); err != nil {
		return err
	}

	// Preserve original file permissions if the file already exists
	perm := os.FileMode(0644)
	if info, err := os.Stat(path); err == nil {
		perm = info.Mode().Perm()
	}

	f, err := os.CreateTemp(dir, "."+name+".")
	if err != nil {
		return err
	}
	tempFile := f.Name()
	cleanupNoClose := func(err error) error {
		return merr.NewErrors(err, os.Remove(tempFile))
	}
	cleanup := func(err error) error {
		return merr.NewErrors(err, f.Close(), os.Remove(tempFile))
	}
	if err := f.Chmod(perm); err != nil {
		return cleanup(err)
	}

	// Write out the first usable IP by incrementing
	// sn.IP by one
	sn := bn.Lease().Subnet
	sn.IP++
	if nm.IPv4Enabled() {
		if _, err := fmt.Fprintf(f, "FLANNEL_NETWORK=%s\n", nw); err != nil {
			return cleanup(err)
		}
		if _, err := fmt.Fprintf(f, "FLANNEL_SUBNET=%s\n", sn); err != nil {
			return cleanup(err)
		}
	}

	if nwv6.String() != emptyIPv6Network {
		snv6 := bn.Lease().IPv6Subnet
		snv6.IncrementIP()
		if _, err := fmt.Fprintf(f, "FLANNEL_IPV6_NETWORK=%s\n", nwv6); err != nil {
			return cleanup(err)
		}
		if _, err := fmt.Fprintf(f, "FLANNEL_IPV6_SUBNET=%s\n", snv6); err != nil {
			return cleanup(err)
		}
Repository: k3s-io/k3s
File: install.sh (Shell)

Code before:
#
#   - INSTALL_K3S_NAME
#     Name of systemd service to create, will default from the k3s exec command
#     if not specified. If specified the name will be prefixed with 'k3s-'.
#
#   - INSTALL_K3S_TYPE
#     Type of systemd service to create, will default from the k3s exec command
#     if not specified.
#
#   - INSTALL_K3S_SELINUX_WARN
#     If set to true will continue if k3s-selinux policy is not found.
#
#   - INSTALL_K3S_SKIP_SELINUX_RPM
#     If set to true will skip automatic installation of the k3s RPM.
#
#   - INSTALL_K3S_CHANNEL_URL
#     Channel URL for fetching k3s download URL.
#     Defaults to 'https://update.k3s.io/v1-release/channels'.
#
#   - INSTALL_K3S_CHANNEL
#     Channel to use for fetching k3s download URL.
#     Defaults to 'stable'.

GITHUB_URL=${GITHUB_URL:-https://github.com/k3s-io/k3s/releases}
GITHUB_ART_URL=""
STORAGE_URL=https://k3s-ci-builds.s3.amazonaws.com
DOWNLOADER=

# --- helper functions for logs ---
info()
{
    echo '[INFO] ' "$@"
}
warn()
{
    echo '[WARN] ' "$@" >&2
}
fatal()
{
    echo '[ERROR] ' "$@" >&2
    exit 1
}

# --- fatal if no systemd or openrc ---
verify_system() {
    if [ -x /sbin/openrc-run ]; then
        HAS_OPENRC=true
        return
    fi
    if [ -x /bin/systemctl ] || type systemctl > /dev/null 2>&1; then
        HAS_SYSTEMD=true

Review comment (suggestion):
We should probably get rid of this since the bucket is gone. New one is `k3s-builds-ci` but we're not pushing to it yet.

Might also consider enabling ipv6 while we're here; I think that requires something like
```suggestion
STORAGE_URL=https://k3s-builds-ci.s3.dualstack.us-east-1.amazonaws.com
```

Code after:
#
#   - INSTALL_K3S_NAME
#     Name of systemd service to create, will default from the k3s exec command
#     if not specified. If specified the name will be prefixed with 'k3s-'.
#
#   - INSTALL_K3S_TYPE
#     Type of systemd service to create, will default from the k3s exec command
#     if not specified.
#
#   - INSTALL_K3S_SELINUX_WARN
#     If set to true will continue if k3s-selinux policy is not found.
#
#   - INSTALL_K3S_SKIP_SELINUX_RPM
#     If set to true will skip automatic installation of the k3s RPM.
#
#   - INSTALL_K3S_CHANNEL_URL
#     Channel URL for fetching k3s download URL.
#     Defaults to 'https://update.k3s.io/v1-release/channels'.
#
#   - INSTALL_K3S_CHANNEL
#     Channel to use for fetching k3s download URL.
#     Defaults to 'stable'.

GITHUB_URL=${GITHUB_URL:-https://github.com/k3s-io/k3s/releases}
GITHUB_ART_URL=""
DOWNLOADER=

# --- helper functions for logs ---
info()
{
    echo '[INFO] ' "$@"
}
warn()
{
    echo '[WARN] ' "$@" >&2
}
fatal()
{
    echo '[ERROR] ' "$@" >&2
    exit 1
}

# --- fatal if no systemd or openrc ---
verify_system() {
    if [ -x /sbin/openrc-run ]; then
        HAS_OPENRC=true
        return
    fi
    if [ -x /bin/systemctl ] || type systemctl > /dev/null 2>&1; then
        HAS_SYSTEMD=true
        return
Repository: kedro-org/kedro
File: kedro/framework/cli/utils.py (Python)

Code before:
                f"a key and a value separated by `:` or `=`."
            )
        key = items[0].strip()
        if not key:
            ctx.fail(
                f"Invalid format of `{param.name}` option: Parameter key "
                f"cannot be an empty string."
            )
        dot_list.append(item)
    conf = OmegaConf.from_dotlist(dot_list)
    return OmegaConf.to_container(conf)


def _split_load_versions(ctx, param, value):
    if not value:
        return {}

    lv_tuple = tuple(chain.from_iterable(value.split(",") for value in [value]))

    load_versions_dict = {}
    for load_version in lv_tuple:
        load_version = load_version.strip()  # noqa: PLW2901
        load_version_list = load_version.split(":", 1)
        if len(load_version_list) != 2:  # noqa: PLR2004
            raise KedroCliError(
                f"Expected the form of 'load_version' to be "
                f"'dataset_name:YYYY-MM-DDThh.mm.ss.sssZ',"
                f"found {load_version} instead"
            )
        load_versions_dict[load_version_list[0]] = load_version_list[1]

    return load_versions_dict


Review comment (suggestion):
This should be plural `load_versions` now right?
```suggestion
                f"Expected the form of 'load_versions' to be "
```

Code after:
                f"a key and a value separated by `:` or `=`."
            )
        key = items[0].strip()
        if not key:
            ctx.fail(
                f"Invalid format of `{param.name}` option: Parameter key "
                f"cannot be an empty string."
            )
        dot_list.append(item)
    conf = OmegaConf.from_dotlist(dot_list)
    return OmegaConf.to_container(conf)


def _split_load_versions(ctx, param, value):
    """Split and format the string coming from the --load-versions
    flag in kedro run, e.g.:
    "dataset1:time1,dataset2:time2" -> {"dataset1": "time1", "dataset2": "time2"}

    Args:
        value: the string with the contents of the --load-versions flag.

    Returns:
        A dictionary with the formatted load versions data.
    """
    if not value:
        return {}

    lv_tuple = tuple(chain.from_iterable(value.split(",") for value in [value]))

    load_versions_dict = {}
    for load_version in lv_tuple:
        load_version = load_version.strip()  # noqa: PLW2901
        load_version_list = load_version.split(":", 1)
        if len(load_version_list) != 2:  # noqa: PLR2004
            raise KedroCliError(
                f"Expected the form of 'load_versions' to be "
                f"'dataset_name:YYYY-MM-DDThh.mm.ss.sssZ',"
                f"found {load_version} instead"
            )
        load_versions_dict[load_version_list[0]] = load_version_list[1]

    return load_versions_dict
Repository: kedro-org/kedro
File: kedro/framework/cli/starters.py (Python)

Code before:
    KedroStarterSpec(
        "spaceflights-pandas-viz", _STARTERS_REPO, "spaceflights-pandas-viz"
    ),
    KedroStarterSpec("spaceflights-pyspark", _STARTERS_REPO, "spaceflights-pyspark"),
    KedroStarterSpec(
        "spaceflights-pyspark-viz", _STARTERS_REPO, "spaceflights-pyspark-viz"
    ),
    KedroStarterSpec("databricks-iris", _STARTERS_REPO, "databricks-iris"),
]
# Set the origin for official starters
for starter_spec in _OFFICIAL_STARTER_SPECS:
    starter_spec.origin = "kedro"

_OFFICIAL_STARTER_SPECS = {spec.alias: spec for spec in _OFFICIAL_STARTER_SPECS}


ADD_ONS_SHORTNAME_TO_NUMBER = {
    "lint": "1",
    "test": "2",
    "log": "3",
    "docs": "4",
    "data": "5",
    "pyspark": "6",
    "viz": "7",
}
NUMBER_TO_ADD_ONS_NAME = {
    "1": "Linting",
    "2": "Testing",
    "3": "Custom Logging",
    "4": "Documentation",
    "5": "Data Structure",
    "6": "Pyspark",
    "7": "Kedro Viz",
}

VALIDATION_PATTERNS = {
    "yes_no": {
        "regex": r"(?i)^\s*(y|yes|n|no)\s*$",
        "error_message": "|It must contain only y, n, YES, NO, case insensitive.",
    }
}


def _validate_regex(pattern_name, text):
    if not re.match(VALIDATION_PATTERNS[pattern_name]["regex"], text):
        click.secho(
            VALIDATION_PATTERNS[pattern_name]["error_message"],
            fg="red",
            err=True,
        )
        sys.exit(1)

Review comment (suggestion):
`_validate_regex` is maybe a bit of a misleading name, because it sounds like you can use this generically for regex patterns, but it's actually quite specific for the yes/no choice. I'd rename it to something like `_validate_yes_no` or `_validate_example_choice`

Code after:
    "test": "2",
    "log": "3",
    "docs": "4",
    "data": "5",
    "pyspark": "6",
    "viz": "7",
}
NUMBER_TO_ADD_ONS_NAME = {
    "1": "Linting",
    "2": "Testing",
    "3": "Custom Logging",
    "4": "Documentation",
    "5": "Data Structure",
    "6": "Pyspark",
    "7": "Kedro Viz",
}

VALIDATION_PATTERNS = {
    "yes_no": {
        "regex": r"(?i)^\s*(y|yes|n|no)\s*$",
        "error_message": "|It must contain only y, n, YES, NO, case insensitive.",
    }
}


def _validate_regex(pattern_name, text):
    if not re.match(VALIDATION_PATTERNS[pattern_name]["regex"], text):
        click.secho(
            VALIDATION_PATTERNS[pattern_name]["error_message"],
            fg="red",
            err=True,
        )
        sys.exit(1)


def _parse_yes_no_to_bool(value):
    return value.strip().lower() in ["y", "yes"] if value is not None else None


# noqa: missing-function-docstring
@click.group(context_settings=CONTEXT_SETTINGS, name="Kedro")
def create_cli():  # pragma: no cover
    pass


@create_cli.group()
def starter():
    """Commands for working with project starters."""


@command_with_verbosity(create_cli, short_help="Create a new kedro project.")