@@ -32,11 +32,20 @@ type Writer interface {
3232 // 2. The output directory where the template will be materialized.
3333 Configure (ctx context.Context , configPath , outputDir string ) error
3434
35+ // Finalize walks the template file tree, persists files to disk, and prints the success message.
36+ Finalize (ctx context.Context ) error
37+
3538 // Materialize the template to the local file system.
3639 Materialize (ctx context.Context , r Reader ) error
3740
3841 // Log telemetry for the template initialization event.
3942 LogTelemetry (ctx context.Context )
43+
44+ // SetConfig sets a value in the template's config.
45+ SetConfig (key string , value any )
46+
47+ // PromptForInput prompts the user for any missing config values.
48+ PromptForInput (ctx context.Context , reader Reader ) error
4049}
4150
4251type defaultWriter struct {
@@ -49,6 +58,13 @@ type defaultWriter struct {
4958 renderer * renderer
5059}
5160
61+ // SetConfig sets a value in the template's config.
62+ func (tmpl * defaultWriter ) SetConfig (key string , value any ) {
63+ if tmpl .renderer != nil {
64+ tmpl .renderer .config [key ] = value
65+ }
66+ }
67+
5268func constructOutputFiler (ctx context.Context , outputDir string ) (filer.Filer , error ) {
5369 outputDir , err := filepath .Abs (outputDir )
5470 if err != nil {
@@ -81,7 +97,7 @@ func (tmpl *defaultWriter) Configure(ctx context.Context, configPath, outputDir
8197 return nil
8298}
8399
84- func (tmpl * defaultWriter ) promptForInput (ctx context.Context , reader Reader ) error {
100+ func (tmpl * defaultWriter ) PromptForInput (ctx context.Context , reader Reader ) error {
85101 readerFs , err := reader .FS (ctx )
86102 if err != nil {
87103 return err
@@ -143,15 +159,10 @@ func (tmpl *defaultWriter) printSuccessMessage(ctx context.Context) error {
143159 return nil
144160}
145161
146- func (tmpl * defaultWriter ) Materialize (ctx context.Context , reader Reader ) error {
147- err := tmpl .promptForInput (ctx , reader )
148- if err != nil {
149- return err
150- }
162+ func (tmpl * defaultWriter ) Finalize (ctx context.Context ) error {
163+ // Walk the template file tree and compute in-memory representations of the output files.
151164
152- // Walk the template file tree and compute in-memory representations of the
153- // output files.
154- err = tmpl .renderer .walk ()
165+ err := tmpl .renderer .walk ()
155166 if err != nil {
156167 return err
157168 }
@@ -165,6 +176,15 @@ func (tmpl *defaultWriter) Materialize(ctx context.Context, reader Reader) error
165176 return tmpl .printSuccessMessage (ctx )
166177}
167178
179+ func (tmpl * defaultWriter ) Materialize (ctx context.Context , reader Reader ) error {
180+ err := tmpl .PromptForInput (ctx , reader )
181+ if err != nil {
182+ return err
183+ }
184+
185+ return tmpl .Finalize (ctx )
186+ }
187+
168188func (tmpl * defaultWriter ) LogTelemetry (ctx context.Context ) {
169189 telemetry .Log (ctx , protos.DatabricksCliLog {
170190 BundleInitEvent : & protos.BundleInitEvent {
@@ -178,6 +198,10 @@ type writerWithFullTelemetry struct {
178198 defaultWriter
179199}
180200
201+ func (tmpl * writerWithFullTelemetry ) SetConfig (key string , value any ) {
202+ tmpl .defaultWriter .SetConfig (key , value )
203+ }
204+
181205func (tmpl * writerWithFullTelemetry ) LogTelemetry (ctx context.Context ) {
182206 var args []protos.BundleInitTemplateEnumArg
183207 for k , v := range tmpl .config .values {
@@ -216,3 +240,7 @@ func (tmpl *writerWithFullTelemetry) LogTelemetry(ctx context.Context) {
216240 },
217241 })
218242}
243+
244+ func (tmpl * writerWithFullTelemetry ) Finalize (ctx context.Context ) error {
245+ return tmpl .defaultWriter .Finalize (ctx )
246+ }
0 commit comments