(
bin: string,
options?: {
env?: Record<string, string | number | boolean>;
cwd?: string;
},
status: 'pending' | 'success' | 'failure' = 'pending',
)
| 10 | * @returns Formatted command string with colored status indicator. |
| 11 | */ |
| 12 | export function formatCommandStatus( |
| 13 | bin: string, |
| 14 | options?: { |
| 15 | env?: Record<string, string | number | boolean>; |
| 16 | cwd?: string; |
| 17 | }, |
| 18 | status: 'pending' | 'success' | 'failure' = 'pending', |
| 19 | ): string { |
| 20 | const cwd = options?.cwd && path.relative(process.cwd(), options.cwd); |
| 21 | const cwdPrefix = cwd ? ansis.blue(cwd) : ''; |
| 22 | const envString = |
| 23 | options?.env && Object.keys(options.env).length > 0 |
| 24 | ? Object.entries(options.env).map(([key, value]) => |
| 25 | ansis.gray(`${key}="${value}"`), |
| 26 | ) |
| 27 | : []; |
| 28 | const statusColor = |
| 29 | status === 'pending' |
| 30 | ? ansis.blue('$') |
| 31 | : status === 'success' |
| 32 | ? ansis.green('$') |
| 33 | : ansis.red('$'); |
| 34 | |
| 35 | return [ |
| 36 | ...(cwdPrefix ? [cwdPrefix] : []), |
| 37 | statusColor, |
| 38 | ...envString, |
| 39 | bin, |
| 40 | ].join(' '); |
| 41 | } |
no outgoing calls
no test coverage detected