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'
@@ -20,6 +23,7 @@ export async function getArgs(argv: string[], app: AppInfo, pm: PackageManager =
2023 . option ( '-d, --dry-run' , help ( 'Dry run (default: false)' ) )
2124 . option ( '-t, --template <template-name>' , help ( 'Use a template' ) )
2225 . option ( '--list-templates' , help ( 'List available templates' ) )
26+ . option ( '--list-registry' , help ( 'List the templates in the registry' ) )
2327 . option ( '--list-versions' , help ( 'Verify your versions of Anchor, AVM, Rust, and Solana' ) )
2428 . option ( '--skip-git' , help ( 'Skip git initialization' ) )
2529 . option ( '--skip-init' , help ( 'Skip running the init script' ) )
@@ -43,10 +47,16 @@ Examples:
4347 // Get the options from the command line
4448 const result = input . opts ( )
4549
50+ const registry = await getRegistry ( )
51+
4652 if ( result . listVersions ) {
4753 listVersions ( )
4854 process . exit ( 0 )
4955 }
56+ if ( result . listRegistry ) {
57+ listRegistry ( registry )
58+ process . exit ( 0 )
59+ }
5060 if ( result . listTemplates ) {
5161 listTemplates ( )
5262 outro (
@@ -121,3 +131,35 @@ function help(text: string) {
121131
122132 ${ text } `
123133}
134+
135+ function listRegistry ( registry : Registry ) {
136+ const { default : defaultRegistry , ...otherRegistries } = registry
137+
138+ printRegistrySection ( defaultRegistry )
139+
140+ const others = Object . keys ( otherRegistries )
141+
142+ for ( const key of others ) {
143+ printRegistrySection ( otherRegistries [ key ] )
144+ }
145+ }
146+
147+ function printRegistrySection ( section : RegistrySection ) {
148+ console . log ( ` === ${ section . id } === ` )
149+ console . log ( `Name: ${ section . name } ` )
150+ // console.log(`Description: ${section.description}`) // TODO: add description to index.json and the validation
151+ console . log ( `Groups: ${ section . groups . length } ` )
152+
153+ for ( const group of section . groups ) {
154+ console . log ( ` === ${ group . id } === ` )
155+ console . log ( `Name: ${ group . name } ` )
156+ console . log ( pico . gray ( `Description: ${ group . description } ` ) )
157+ console . log ( pico . gray ( `Templates: ${ group . templates . length } ` ) )
158+
159+ for ( const template of group . templates ) {
160+ console . log ( ` ${ template . name } ` )
161+ console . log ( pico . gray ( ` Description: ${ template . description } ` ) )
162+ console . log ( pico . gray ( ` Repository: ${ template . repository } ` ) )
163+ }
164+ }
165+ }
0 commit comments