( command: string, simulatedSedEditFilePath?: string, )
| 369 | * because grep patterns and sed scripts rarely resemble file extensions. |
| 370 | */ |
| 371 | export function getFileExtensionsFromBashCommand( |
| 372 | command: string, |
| 373 | simulatedSedEditFilePath?: string, |
| 374 | ): AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS | undefined { |
| 375 | if (!command.includes('.') && !simulatedSedEditFilePath) return undefined |
| 376 | |
| 377 | let result: string | undefined |
| 378 | const seen = new Set<string>() |
| 379 | |
| 380 | if (simulatedSedEditFilePath) { |
| 381 | const ext = getFileExtensionForAnalytics(simulatedSedEditFilePath) |
| 382 | if (ext) { |
| 383 | seen.add(ext) |
| 384 | result = ext |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | for (const subcmd of command.split(COMPOUND_OPERATOR_REGEX)) { |
| 389 | if (!subcmd) continue |
| 390 | const tokens = subcmd.split(WHITESPACE_REGEX) |
| 391 | if (tokens.length < 2) continue |
| 392 | |
| 393 | const firstToken = tokens[0]! |
| 394 | const slashIdx = firstToken.lastIndexOf('/') |
| 395 | const baseCmd = slashIdx >= 0 ? firstToken.slice(slashIdx + 1) : firstToken |
| 396 | if (!FILE_COMMANDS.has(baseCmd)) continue |
| 397 | |
| 398 | for (let i = 1; i < tokens.length; i++) { |
| 399 | const arg = tokens[i]! |
| 400 | if (arg.charCodeAt(0) === 45 /* - */) continue |
| 401 | const ext = getFileExtensionForAnalytics(arg) |
| 402 | if (ext && !seen.has(ext)) { |
| 403 | seen.add(ext) |
| 404 | result = result ? result + ',' + ext : ext |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | if (!result) return undefined |
| 410 | return result as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Environment context metadata |
no test coverage detected