11import { Command } from "@cliffy/command" ;
22import { getAppFromConfig , readConfig } from "./config.ts" ;
3- import { withApp } from "./util.ts" ;
3+ import { error , withApp } from "./util.ts" ;
44import { createTrpcClient } from "./auth.ts" ;
55
66interface 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
132139export 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
171180export 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
229240export 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