(command)
| 184 | } |
| 185 | |
| 186 | function shellPythonWriteDestination(command) { |
| 187 | if (!/\bpython(?:3)?\b/.test(command || '')) return ''; |
| 188 | const directPath = firstMatch(command, /(?:^|[^\w.])(?:pathlib\.)?Path\(\s*(["'])(.*?)\1\s*\)\s*\.write_text\s*\(/); |
| 189 | if (directPath) return directPath; |
| 190 | |
| 191 | const pathsByVar = new Map(); |
| 192 | const assignmentRe = /\b([A-Za-z_]\w*)\s*=\s*(?:pathlib\.)?Path\(\s*(["'])(.*?)\2\s*\)/g; |
| 193 | let assignment; |
| 194 | while ((assignment = assignmentRe.exec(command))) { |
| 195 | pathsByVar.set(assignment[1], assignment[3]); |
| 196 | } |
| 197 | |
| 198 | const writeVarRe = /\b([A-Za-z_]\w*)\.write_text\s*\(/g; |
| 199 | let writeVar; |
| 200 | while ((writeVar = writeVarRe.exec(command))) { |
| 201 | const candidate = pathsByVar.get(writeVar[1]); |
| 202 | if (candidate) return candidate; |
| 203 | } |
| 204 | |
| 205 | return firstMatch(command, /\bopen\(\s*(["'])(.*?)\1\s*,\s*(["'])[wax](?:\+)?b?\3/); |
| 206 | } |
| 207 | |
| 208 | function firstMatch(value, re) { |
| 209 | const match = String(value || '').match(re); |
no test coverage detected