11import { InstanceCommand } from '@salesforce/b2c-tooling/cli'
2+ import { t } from '../../i18n/index.js'
23
34interface SitesResponse {
45 _v : string
@@ -12,7 +13,7 @@ interface SitesResponse {
1213}
1314
1415export default class SitesList extends InstanceCommand < typeof SitesList > {
15- static description = ' List sites on a B2C Commerce instance'
16+ static description = t ( 'commands.sites.list.description' , ' List sites on a B2C Commerce instance')
1617
1718 static examples = [
1819 '<%= config.bin %> <%= command.id %>' ,
@@ -24,37 +25,46 @@ export default class SitesList extends InstanceCommand<typeof SitesList> {
2425 this . requireOAuthCredentials ( )
2526
2627 const instance = this . createApiInstance ( )
28+ const hostname = this . resolvedConfig . hostname !
2729
28- this . log ( ` Fetching sites from ${ this . resolvedConfig . hostname } ...` )
30+ this . log ( t ( 'commands.sites.list.fetching' , ' Fetching sites from {{ hostname}} ...' , { hostname } ) )
2931
3032 try {
3133 const response = await instance . ocapiDataRequest ( 'sites?select=(**)' )
3234
3335 if ( ! response . ok ) {
3436 const errorText = await response . text ( )
35- this . error ( `Failed to fetch sites: ${ response . status } ${ response . statusText } \n${ errorText } ` )
37+ this . error (
38+ t ( 'commands.sites.list.fetchFailed' , 'Failed to fetch sites: {{status}} {{statusText}}\n{{error}}' , {
39+ status : response . status ,
40+ statusText : response . statusText ,
41+ error : errorText ,
42+ } )
43+ )
3644 }
3745
3846 const data = ( await response . json ( ) ) as SitesResponse
3947
4048 if ( data . count === 0 ) {
41- this . log ( ' No sites found.')
49+ this . log ( t ( 'commands.sites.list.noSites' , ' No sites found.') )
4250 return
4351 }
4452
45- this . log ( `\nFound ${ data . count } site(s):\n` )
53+ this . log ( '' )
54+ this . log ( t ( 'commands.sites.list.foundSites' , 'Found {{count}} site(s):' , { count : data . count } ) )
55+ this . log ( '' )
4656
4757 for ( const site of data . data ) {
4858 const displayName = site . display_name ?. default || site . id
4959 const status = site . status || 'unknown'
5060 this . log ( ` ${ site . id } ` )
51- this . log ( ` Display Name: ${ displayName } ` )
52- this . log ( ` Status: ${ status } ` )
61+ this . log ( ` ${ t ( 'commands.sites.list.displayName' , ' Display Name: {{name}}' , { name : displayName } ) } ` )
62+ this . log ( ` ${ t ( 'commands.sites.list.status' , ' Status: {{ status}}' , { status } ) } ` )
5363 this . log ( '' )
5464 }
5565 } catch ( error ) {
5666 if ( error instanceof Error ) {
57- this . error ( ` Failed to fetch sites: ${ error . message } ` )
67+ this . error ( t ( 'commands.sites.list.error' , ' Failed to fetch sites: {{message}}' , { message : error . message } ) )
5868 }
5969 throw error
6070 }
0 commit comments