| 84 | } |
| 85 | |
| 86 | const formatUptime = (uptimeSeconds: number | null): string => { |
| 87 | if (uptimeSeconds === null) { |
| 88 | return 'unavailable' |
| 89 | } |
| 90 | |
| 91 | const days = Math.floor(uptimeSeconds / 86400) |
| 92 | const hours = Math.floor((uptimeSeconds % 86400) / 3600) |
| 93 | const minutes = Math.floor((uptimeSeconds % 3600) / 60) |
| 94 | const seconds = uptimeSeconds % 60 |
| 95 | |
| 96 | const segments = [] |
| 97 | if (days > 0) { |
| 98 | segments.push(`${days}d`) |
| 99 | } |
| 100 | if (hours > 0 || days > 0) { |
| 101 | segments.push(`${hours}h`) |
| 102 | } |
| 103 | if (minutes > 0 || hours > 0 || days > 0) { |
| 104 | segments.push(`${minutes}m`) |
| 105 | } |
| 106 | segments.push(`${seconds}s`) |
| 107 | return segments.join(' ') |
| 108 | } |
| 109 | |
| 110 | const writeJson = (value: unknown): void => { |
| 111 | process.stdout.write(`${JSON.stringify(value, null, 2)}\n`) |