Skip to content

Commit 71991b0

Browse files
committed
give feedback on env var commands
1 parent 4e2c87a commit 71991b0

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

env.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Command } from "@cliffy/command";
22
import { getAppFromConfig, readConfig } from "./config.ts";
3-
import { withApp } from "./util.ts";
3+
import { error, withApp } from "./util.ts";
44
import { createTrpcClient } from "./auth.ts";
55

66
interface EnvVar {
@@ -39,6 +39,11 @@ export const envListCommand = new Command<EnvCommandContext>()
3939
app: orgAndApp.app,
4040
});
4141

42+
if (envVars.length === 0) {
43+
console.log("There are no environmental variables set on this application.");
44+
return;
45+
}
46+
4247
// deno-lint-ignore no-explicit-any
4348
const contexts: Context[] = await (trpcClient.envVarsContexts as any)
4449
.listContexts
@@ -127,6 +132,8 @@ export const envAddCommand = new Command<EnvCommandContext>()
127132
update: [],
128133
remove: [],
129134
});
135+
136+
console.log(`Environmental variable '${variable}' has been successfully set.`);
130137
});
131138

132139
export const envUpdateValueCommand = new Command<EnvCommandContext>()
@@ -153,7 +160,7 @@ export const envUpdateValueCommand = new Command<EnvCommandContext>()
153160
const envVar = envVars.find((envVar) => envVar.key === variable);
154161

155162
if (!envVar) {
156-
throw new Error(`Environment variable "${variable}" not found`);
163+
error(`Environment variable '${variable}' not found`);
157164
}
158165

159166
// deno-lint-ignore no-explicit-any
@@ -166,12 +173,14 @@ export const envUpdateValueCommand = new Command<EnvCommandContext>()
166173
}],
167174
remove: [],
168175
});
176+
177+
console.log(`The value of the environmental variable '${variable}' has been successfully updated.`);
169178
});
170179

171180
export const envUpdateContextsCommand = new Command<EnvCommandContext>()
172181
.description(
173182
`Update the contexts of an environmental variable in the application
174-
You can define no contexts and it will set the value to "All"`,
183+
You can define no contexts, which is the equivalent to "All"`,
175184
)
176185
.arguments("variable:string [new-contexts...:string]")
177186
.action(async (options, variable, ...newContexts) => {
@@ -193,7 +202,7 @@ You can define no contexts and it will set the value to "All"`,
193202
const envVar = envVars.find((envVar) => envVar.key === variable);
194203

195204
if (!envVar) {
196-
throw new Error(`Environment variable "${variable}" not found`);
205+
error(`Environment variable '${variable}' not found`);
197206
}
198207

199208
// deno-lint-ignore no-explicit-any
@@ -208,7 +217,7 @@ You can define no contexts and it will set the value to "All"`,
208217
for (const newContext of newContexts) {
209218
const context = contexts.find((context) => context.name === newContext);
210219
if (!context) {
211-
throw new Error(`Context "${newContext}" not found`);
220+
error(`Context "${newContext}" not found`);
212221
}
213222

214223
contextIds.push(context.id);
@@ -224,6 +233,8 @@ You can define no contexts and it will set the value to "All"`,
224233
}],
225234
remove: [],
226235
});
236+
237+
console.log(`The contexts of the environmental variable '${variable}' have been successfully updated`);
227238
});
228239

229240
export const envDeleteCommand = new Command<EnvCommandContext>()
@@ -248,7 +259,7 @@ export const envDeleteCommand = new Command<EnvCommandContext>()
248259
const envVar = envVars.find((envVar) => envVar.key === variable);
249260

250261
if (!envVar) {
251-
throw new Error(`Environment variable "${variable}" not found`);
262+
throw new Error(`Environment variable '${variable}' not found`);
252263
}
253264

254265
// deno-lint-ignore no-explicit-any
@@ -258,4 +269,6 @@ export const envDeleteCommand = new Command<EnvCommandContext>()
258269
update: [],
259270
remove: [envVar.id],
260271
});
272+
273+
console.log(`Environmental variable '${variable}' has been successfully deleted`);
261274
});

0 commit comments

Comments
 (0)