@@ -28,6 +28,8 @@ import { snapshot } from "./snapshot/mod.ts";
2828import { template } from "./template/mod.ts" ;
2929import { startupScript } from "./startup-script/mod.ts" ;
3030import { autoscalingGroup } from "./autoscaling-group/mod.ts" ;
31+ import { billingAccountStanding } from "../api/billing.ts" ;
32+ import { asserts } from "../lib/asserts.ts" ;
3133
3234/**
3335 * This variable is automatically generated by `zcli add`. Do not remove this
@@ -107,9 +109,13 @@ export const root = app
107109 }
108110 }
109111
112+ // requireInGoodStanding implies requireApiKey.
113+ const requireApiKey = ctx . cmd . meta . requireApiKey ||
114+ ctx . cmd . meta . requireInGoodStanding ;
115+
110116 // Check to see if this command requires an API key. If it does, we'll
111117 // check to see if one is set. If not, we'll throw an error.
112- if ( ctx . cmd . meta . requireApiKey && ! env . get ( "PAPERSPACE_API_KEY" ) ) {
118+ if ( requireApiKey && ! env . get ( "PAPERSPACE_API_KEY" ) ) {
113119 const availableTeams = Object . keys ( await credentials . get ( "keys" ) ) ;
114120 const hasTeams = availableTeams . length > 0 ;
115121 const loginHelper = ! hasTeams
@@ -130,6 +136,26 @@ export const root = app
130136
131137 throw new AppError ( { message : `${ selectMessage } \n${ loginHelper } ` } ) ;
132138 }
139+
140+ if ( ctx . cmd . meta . requireInGoodStanding ) {
141+ const accountStanding = await billingAccountStanding . get ( null ) ;
142+ asserts ( accountStanding . ok , accountStanding ) ;
143+
144+ if ( ! accountStanding . data . isInGoodStanding ) {
145+ const team = await appConfig . get ( "team" ) ;
146+
147+ asserts ( team , "Log in to continue." ) ;
148+
149+ const billingUrl = new URL (
150+ `/${ team } /settings/billing` ,
151+ env . get ( "PAPERSPACE_CONSOLE_URL" ) ,
152+ ) ;
153+
154+ throw new AppError ( {
155+ message : `Add a credit card to continue\n\n${ billingUrl } ` ,
156+ } ) ;
157+ }
158+ }
133159 } )
134160 // This function runs after every command.
135161 . persistentPostRun ( async function * ( { flags, ctx } ) {
0 commit comments