@@ -5,6 +5,10 @@ import { info, printJson, handleApproval, renderNextActions } from '../util.js'
55export const SERVICE_TYPES = [ 'postgres' , 'storage' , 'compute' ] as const
66export type ServiceType = ( typeof SERVICE_TYPES ) [ number ]
77
8+ export function q ( branch ?: string ) : string {
9+ return branch ? `?branch=${ encodeURIComponent ( branch ) } ` : ''
10+ }
11+
812// ---- pure, unit-tested helpers (throw plain Errors; the CLI guard turns them into clean output) ----
913
1014// Validate a service-type argument against the allowed set for a command.
@@ -41,40 +45,43 @@ export function resolveComputeServiceId(services: Array<{ id: string; type: stri
4145
4246// ---- commands ----
4347
44- export async function servicesAdd ( type : string , name : string , opts : { public ?: boolean } = { } ) : Promise < void > {
48+ export async function servicesAdd ( type : string , name : string , opts : { branch ?: string ; public ?: boolean } = { } ) : Promise < void > {
4549 assertType ( type )
4650 if ( opts . public && type !== 'storage' ) throw new Error ( '--public is only valid for storage services' )
4751 const api = await ApiClient . load ( )
4852 const p = await requireProject ( )
49- const res = await api . rawRequest ( 'POST' , `/projects/${ p . projectId } /services` , { type, name, public : ! ! opts . public } )
53+ const branch = opts . branch ?? p . branch
54+ const res = await api . rawRequest ( 'POST' , `/projects/${ p . projectId } /services` , { type, name, ...( branch ? { branch } : { } ) , public : ! ! opts . public } )
5055 if ( handleApproval ( res ) ) return
5156 const svc = res . body . service
5257 const access = svc . type === 'storage' ? ` [${ svc . public ? 'public' : 'private' } ]` : ''
53- info ( `added ${ type } service ${ name } (${ svc . id } )${ access } ${ svc . domain ? ` — ${ svc . domain } ` : '' } ` )
58+ info ( `added ${ type } service ${ name } on ${ branch ?? 'default' } (${ svc . id } )${ access } ${ svc . domain ? ` — ${ svc . domain } ` : '' } ` )
5459 renderNextActions ( res . body . nextActions )
5560}
5661
57- export async function servicesList ( opts : { json ?: boolean } ) : Promise < void > {
62+ export async function servicesList ( opts : { json ?: boolean ; branch ?: string } ) : Promise < void > {
5863 const api = await ApiClient . load ( )
5964 const p = await requireProject ( )
60- const { services } = await api . request ( 'GET' , `/projects/${ p . projectId } /services` )
65+ const branch = opts . branch ?? p . branch
66+ const { services } = await api . request ( 'GET' , `/projects/${ p . projectId } /services${ q ( branch ) } ` )
6167 if ( opts . json ) return printJson ( services )
62- if ( ! services . length ) return info ( ' (no services — add one with `insta services add <postgres|storage|compute> <name>`)' )
68+ if ( ! services . length ) return info ( ` (no services on ${ branch ?? 'default' } — add one with \ `insta services add <postgres|storage|compute> <name>\`)` )
6369 for ( const s of services ) {
6470 const extra = s . type === 'compute' ? ` x${ s . machine_count } ` : s . type === 'storage' ? ` ${ s . public ? 'public' : 'private' } ` : ''
6571 info ( `${ s . type } /${ s . name } [${ s . status } ]${ extra } ${ s . domain ? ` ${ s . domain } ` : '' } ${ s . id } ` )
6672 }
6773}
6874
69- export async function servicesRemove ( type : string , name : string ) : Promise < void > {
75+ export async function servicesRemove ( type : string , name : string , opts : { branch ?: string } = { } ) : Promise < void > {
7076 assertType ( type )
7177 const api = await ApiClient . load ( )
7278 const p = await requireProject ( )
73- const { services } = await api . request ( 'GET' , `/projects/${ p . projectId } /services` )
79+ const branch = opts . branch ?? p . branch
80+ const { services } = await api . request ( 'GET' , `/projects/${ p . projectId } /services${ q ( branch ) } ` )
7481 const id = resolveServiceId ( services , type , name )
7582 const res = await api . rawRequest ( 'DELETE' , `/projects/${ p . projectId } /services/${ id } ` )
7683 if ( handleApproval ( res ) ) return
77- info ( `removed ${ type } service ${ name } ` )
84+ info ( `removed ${ type } service ${ name } from ${ branch ?? 'default' } ` )
7885}
7986
8087// Validate a bucket access-mode argument.
@@ -90,7 +97,7 @@ export async function servicesSetAccess(type: string, name: string, access: stri
9097 const isPublic = parseAccess ( access )
9198 const api = await ApiClient . load ( )
9299 const p = await requireProject ( )
93- const { services } = await api . request ( 'GET' , `/projects/${ p . projectId } /services` )
100+ const { services } = await api . request ( 'GET' , `/projects/${ p . projectId } /services${ q ( p . branch ) } ` )
94101 const id = resolveServiceId ( services , type , name )
95102 const res = await api . rawRequest ( 'PUT' , `/projects/${ p . projectId } /services/${ id } /access` , { public : isPublic } )
96103 if ( handleApproval ( res ) ) return
@@ -99,12 +106,12 @@ export async function servicesSetAccess(type: string, name: string, access: stri
99106}
100107
101108// insta services scale compute <name> <number> [region]
102- export async function servicesScale ( type : string , name : string , number : string , region : string | undefined , _opts : { json ?: boolean } ) : Promise < void > {
109+ export async function servicesScale ( type : string , name : string , number : string , region : string | undefined , _opts : { json ?: boolean ; branch ?: string } ) : Promise < void > {
103110 assertType ( type , [ 'compute' ] )
104111 const machineCount = parseCount ( number )
105112 const api = await ApiClient . load ( )
106113 const p = await requireProject ( )
107- const { services } = await api . request ( 'GET' , `/projects/${ p . projectId } /services` )
114+ const { services } = await api . request ( 'GET' , `/projects/${ p . projectId } /services${ q ( _opts . branch ?? p . branch ) } ` )
108115 const id = resolveServiceId ( services , type , name )
109116 const res = await api . rawRequest ( 'POST' , `/projects/${ p . projectId } /services/${ id } /scale` , { machineCount, region } )
110117 if ( handleApproval ( res ) ) return
@@ -113,11 +120,11 @@ export async function servicesScale(type: string, name: string, number: string,
113120}
114121
115122// insta services upgrade <compute|postgres> <name> <new-spec>
116- export async function servicesUpgrade ( type : string , name : string , spec : string , _opts : { json ?: boolean } ) : Promise < void > {
123+ export async function servicesUpgrade ( type : string , name : string , spec : string , _opts : { json ?: boolean ; branch ?: string } ) : Promise < void > {
117124 assertType ( type , [ 'compute' , 'postgres' ] )
118125 const api = await ApiClient . load ( )
119126 const p = await requireProject ( )
120- const { services } = await api . request ( 'GET' , `/projects/${ p . projectId } /services` )
127+ const { services } = await api . request ( 'GET' , `/projects/${ p . projectId } /services${ q ( _opts . branch ?? p . branch ) } ` )
121128 const id = resolveServiceId ( services , type , name )
122129 const res = await api . rawRequest ( 'POST' , `/projects/${ p . projectId } /services/${ id } /upgrade` , { spec } )
123130 if ( handleApproval ( res ) ) return
0 commit comments