refactor(sandbox): extract formatters into separate module
Move formatting utilities to sandbox-formatters.ts: - formatStatus, formatSimpleStatus, formatImageMatch, formatAge - countRunning, countMismatches helper functions - ContainerItem type definition Improves modularity and reusability. 49 LOC.
This commit is contained in:
committed by
Peter Steinberger
parent
6ca34c1259
commit
dd0104290e
49
src/commands/sandbox-formatters.ts
Normal file
49
src/commands/sandbox-formatters.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* Formatting utilities for sandbox CLI output
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function formatStatus(running: boolean): string {
|
||||||
|
return running ? "🟢 running" : "⚫ stopped";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatSimpleStatus(running: boolean): string {
|
||||||
|
return running ? "running" : "stopped";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatImageMatch(matches: boolean): string {
|
||||||
|
return matches ? "✓" : "⚠️ mismatch";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatAge(ms: number): string {
|
||||||
|
const seconds = Math.floor(ms / 1000);
|
||||||
|
const minutes = Math.floor(seconds / 60);
|
||||||
|
const hours = Math.floor(minutes / 60);
|
||||||
|
const days = Math.floor(hours / 24);
|
||||||
|
|
||||||
|
if (days > 0) return `${days}d ${hours % 24}h`;
|
||||||
|
if (hours > 0) return `${hours}h ${minutes % 60}m`;
|
||||||
|
if (minutes > 0) return `${minutes}m`;
|
||||||
|
return `${seconds}s`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type guard and counter utilities
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type ContainerItem = {
|
||||||
|
running: boolean;
|
||||||
|
imageMatch: boolean;
|
||||||
|
containerName: string;
|
||||||
|
sessionKey: string;
|
||||||
|
image: string;
|
||||||
|
createdAtMs: number;
|
||||||
|
lastUsedAtMs: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function countRunning<T extends { running: boolean }>(items: T[]): number {
|
||||||
|
return items.filter((item) => item.running).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function countMismatches<T extends { imageMatch: boolean }>(items: T[]): number {
|
||||||
|
return items.filter((item) => !item.imageMatch).length;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user