Check if command starts with a forbidden standalone command. Returns (forbidden_command, recommendation) if found, None otherwise.
(command: str)
| 109 | |
| 110 | |
| 111 | def is_forbidden_command(command: str) -> tuple[str, str] | None: |
| 112 | """ |
| 113 | Check if command starts with a forbidden standalone command. |
| 114 | |
| 115 | Returns (forbidden_command, recommendation) if found, None otherwise. |
| 116 | """ |
| 117 | # Remove leading/trailing whitespace |
| 118 | command = command.strip() |
| 119 | |
| 120 | # Check if command starts with any forbidden command as a standalone word |
| 121 | for forbidden in FORBIDDEN_COMMANDS: |
| 122 | # Match forbidden command at start, followed by whitespace or nothing |
| 123 | pattern = rf"^{re.escape(forbidden)}(\s|$)" |
| 124 | if re.match(pattern, command): |
| 125 | recommendation = COMMAND_RECOMMENDATIONS.get( |
| 126 | forbidden, f'set environment variable "{OVERRIDE_ENV_VAR}"' |
| 127 | ) |
| 128 | return (forbidden, recommendation) |
| 129 | |
| 130 | return None |
| 131 | |
| 132 | |
| 133 | def check_forbidden_pattern(command: str) -> tuple[bool, str] | None: |