|
1 | 1 | import { Command } from "@cliffy/command"; |
2 | 2 | import { parse as dotEnvParse } from "@std/dotenv"; |
3 | 3 | import { getAppFromConfig, readConfig } from "./config.ts"; |
4 | | -import { error, withApp } from "./util.ts"; |
| 4 | +import { error, tablePrinter, withApp } from "./util.ts"; |
5 | 5 | import { createTrpcClient } from "./auth.ts"; |
6 | 6 | import type { GlobalOptions } from "./main.ts"; |
7 | 7 |
|
@@ -61,51 +61,33 @@ export const envListCommand = new Command<EnvCommandContext>() |
61 | 61 | org: orgAndApp.org, |
62 | 62 | }); |
63 | 63 |
|
64 | | - const processed = envVars.map((envVar) => { |
65 | | - const contextNames = []; |
66 | | - |
67 | | - if (envVar.context_ids) { |
68 | | - for (const contextId of envVar.context_ids) { |
69 | | - contextNames.push( |
70 | | - contexts.find((context) => context.id === contextId)!.name, |
71 | | - ); |
72 | | - } |
73 | | - } else { |
74 | | - contextNames.push("All"); |
75 | | - } |
76 | | - |
77 | | - return { |
78 | | - key: envVar.key, |
79 | | - value: envVar.value ?? "***", |
80 | | - contexts: contextNames.join(", "), |
81 | | - }; |
82 | | - }); |
83 | | - |
84 | | - const contextTitle = `Contexts (${ |
| 64 | + const contextTitle = `CONTEXTS (${ |
85 | 65 | contexts.map((context) => context.name).join(", ") |
86 | 66 | })`; |
87 | 67 |
|
88 | | - let keyLength = 3; |
89 | | - let valueLength = 5; |
90 | | - |
91 | | - for (const processedElement of processed) { |
92 | | - keyLength = Math.max(keyLength, processedElement.key.length); |
93 | | - valueLength = Math.max(valueLength, processedElement.value.length); |
94 | | - } |
| 68 | + tablePrinter( |
| 69 | + ["KEY", "VALUE", contextTitle], |
| 70 | + envVars, |
| 71 | + (envVar) => { |
| 72 | + const contextNames = []; |
| 73 | + |
| 74 | + if (envVar.context_ids) { |
| 75 | + for (const contextId of envVar.context_ids) { |
| 76 | + contextNames.push( |
| 77 | + contexts.find((context) => context.id === contextId)!.name, |
| 78 | + ); |
| 79 | + } |
| 80 | + } else { |
| 81 | + contextNames.push("All"); |
| 82 | + } |
95 | 83 |
|
96 | | - console.log( |
97 | | - `${"Key".padEnd(keyLength)} ${ |
98 | | - "Value".padEnd(valueLength) |
99 | | - } ${contextTitle}`, |
| 84 | + return [ |
| 85 | + envVar.key, |
| 86 | + envVar.value ?? "***", |
| 87 | + contextNames.join(", "), |
| 88 | + ]; |
| 89 | + }, |
100 | 90 | ); |
101 | | - |
102 | | - for (const env of processed) { |
103 | | - console.log( |
104 | | - `${env.key.padEnd(keyLength)} ${ |
105 | | - env.value.padEnd(valueLength) |
106 | | - } ${env.contexts}`, |
107 | | - ); |
108 | | - } |
109 | 91 | }); |
110 | 92 |
|
111 | 93 | export const envAddCommand = new Command<EnvCommandContext>() |
|
0 commit comments