35 lines
972 B
TypeScript
35 lines
972 B
TypeScript
import type { V1EnvVar } from "@kubernetes/client-node";
|
|
import type { Service } from "../schema/docker.d";
|
|
|
|
function toTable(args: Record<string, string | number | undefined>[]): string {
|
|
return new Table(
|
|
Object.keys(args[0] ?? {}).map((e) => e.toUpperCase()),
|
|
...args.map((e) => Object.values(e)),
|
|
).toString();
|
|
}
|
|
|
|
function toEnvVars(
|
|
environment: Service["environment"],
|
|
): V1EnvVar[] | undefined {
|
|
if (!environment) return;
|
|
|
|
if (Array.isArray(environment)) {
|
|
return environment.map((entry) => {
|
|
const separator = entry.indexOf("=");
|
|
const name = separator === -1 ? entry : entry.slice(0, separator);
|
|
return {
|
|
name,
|
|
value: separator === -1 ? undefined : entry.slice(separator + 1),
|
|
};
|
|
});
|
|
}
|
|
|
|
return Object.entries(environment).map(([name, value]) => ({
|
|
name,
|
|
value: value === null ? undefined : String(value),
|
|
}));
|
|
}
|
|
|
|
export { toEnvVars, toTable };
|
|
import { Table } from "@cliffy/table";
|