(
cmd: string,
env?:
| Record<string, string | undefined>
| ((key: string) => string | undefined),
)
| 22 | | { success: false; error: string } |
| 23 | |
| 24 | export function tryParseShellCommand( |
| 25 | cmd: string, |
| 26 | env?: |
| 27 | | Record<string, string | undefined> |
| 28 | | ((key: string) => string | undefined), |
| 29 | ): ShellParseResult { |
| 30 | try { |
| 31 | const tokens = |
| 32 | typeof env === 'function' |
| 33 | ? shellQuoteParse(cmd, env) |
| 34 | : shellQuoteParse(cmd, env) |
| 35 | return { success: true, tokens } |
| 36 | } catch (error) { |
| 37 | if (error instanceof Error) { |
| 38 | logError(error) |
| 39 | } |
| 40 | return { |
| 41 | success: false, |
| 42 | error: error instanceof Error ? error.message : 'Unknown parse error', |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | export function tryQuoteShellArgs(args: unknown[]): ShellQuoteResult { |
| 48 | try { |
no test coverage detected