11import { intro , log , outro } from '@clack/prompts'
22import { program } from 'commander'
3+ import pico from 'picocolors'
4+ import { getRegistry } from '../registry/registry'
5+ import { Registry , RegistrySection } from '../registry/validate-registry'
36import { findTemplate , listTemplates , Template } from '../templates/templates'
47import { AppInfo } from './get-app-info'
58import { GetArgsResult } from './get-args-result'
@@ -19,6 +22,7 @@ export async function getArgs(argv: string[], app: AppInfo, pm: PackageManager =
1922 . option ( '-d, --dry-run' , help ( 'Dry run (default: false)' ) )
2023 . option ( '-t, --template <template-name>' , help ( 'Use a template' ) )
2124 . option ( '--list-templates' , help ( 'List available templates' ) )
25+ . option ( '--list-registry' , help ( 'List the templates in the registry' ) )
2226 . option ( '--list-versions' , help ( 'Verify your versions of Anchor, AVM, Rust, and Solana' ) )
2327 . option ( '--skip-git' , help ( 'Skip git initialization' ) )
2428 . option ( '--skip-init' , help ( 'Skip running the init script' ) )
@@ -42,10 +46,16 @@ Examples:
4246 // Get the options from the command line
4347 const result = input . opts ( )
4448
49+ const registry = await getRegistry ( )
50+
4551 if ( result . listVersions ) {
4652 listVersions ( )
4753 process . exit ( 0 )
4854 }
55+ if ( result . listRegistry ) {
56+ listRegistry ( registry )
57+ process . exit ( 0 )
58+ }
4959 if ( result . listTemplates ) {
5060 listTemplates ( )
5161 outro (
@@ -116,3 +126,35 @@ function help(text: string) {
116126
117127 ${ text } `
118128}
129+
130+ function listRegistry ( registry : Registry ) {
131+ const { default : defaultRegistry , ...otherRegistries } = registry
132+
133+ printRegistrySection ( defaultRegistry )
134+
135+ const others = Object . keys ( otherRegistries )
136+
137+ for ( const key of others ) {
138+ printRegistrySection ( otherRegistries [ key ] )
139+ }
140+ }
141+
142+ function printRegistrySection ( section : RegistrySection ) {
143+ console . log ( ` === ${ section . id } === ` )
144+ console . log ( `Name: ${ section . name } ` )
145+ // console.log(`Description: ${section.description}`) // TODO: add description to index.json and the validation
146+ console . log ( `Groups: ${ section . groups . length } ` )
147+
148+ for ( const group of section . groups ) {
149+ console . log ( ` === ${ group . id } === ` )
150+ console . log ( `Name: ${ group . name } ` )
151+ console . log ( pico . gray ( `Description: ${ group . description } ` ) )
152+ console . log ( pico . gray ( `Templates: ${ group . templates . length } ` ) )
153+
154+ for ( const template of group . templates ) {
155+ console . log ( ` ${ template . name } ` )
156+ console . log ( pico . gray ( ` Description: ${ template . description } ` ) )
157+ console . log ( pico . gray ( ` Repository: ${ template . repository } ` ) )
158+ }
159+ }
160+ }
0 commit comments