@@ -34,26 +34,6 @@ func (d *DryccCmd) BuildsInfo(appID string, version int) error {
3434 table .Append ([]string {"Updated:" , build .Updated })
3535 table .Render ()
3636
37- if len (build .Dockerfile ) != 0 {
38- table = d .getDefaultFormatTable ([]string {})
39- table .Append ([]string {"Dockerfile:" })
40- table .Append ([]string {d .indentString (build .Dockerfile , 2 )})
41- table .Render ()
42- }
43-
44- if len (build .Procfile ) != 0 {
45- table = d .getDefaultFormatTable ([]string {})
46- table .Append ([]string {"Procfile:" })
47- table .Append ([]string {d .indentString (d .toYamlString (build .Procfile , 2 ), 2 )})
48- table .Render ()
49- }
50-
51- if len (build .Dryccfile ) != 0 {
52- table = d .getDefaultFormatTable ([]string {})
53- table .Append ([]string {"Dryccfile:" })
54- table .Append ([]string {d .indentString (d .toYamlString (build .Dryccfile , 2 ), 2 )})
55- table .Render ()
56- }
5737 return nil
5838}
5939
@@ -102,7 +82,7 @@ func (d *DryccCmd) BuildsCreate(appID, image, stack, procfile, dryccpath, confir
10282 return nil
10383}
10484
105- func (d * DryccCmd ) BuildsFetch (appID string , version int , procfile , dryccpath , confirm string ) error {
85+ func (d * DryccCmd ) BuildsFetch (appID string , version int , procfile , dryccpath , confirm string , save bool ) error {
10686 s , appID , err := load (d .ConfigFile , appID )
10787 if err != nil {
10888 return err
@@ -113,33 +93,66 @@ func (d *DryccCmd) BuildsFetch(appID string, version int, procfile, dryccpath, c
11393 return err
11494 }
11595 // Confirm again
116- err = buildFetchConfirmAction (confirm , procfile , dryccpath )
96+ dockerfile := "Dockerfile"
97+ err = buildFetchConfirmAction (confirm , dockerfile , procfile , dryccpath , save )
11798 if err != nil {
11899 return err
119100 }
120- os .Remove (procfile )
121- os .ReadDir (dryccpath )
101+ if len (build .Dockerfile ) != 0 {
102+ err := writeDockerfileToPath (d , dockerfile , build .Dockerfile , save )
103+ if err != nil {
104+ return fmt .Errorf ("failed to write Dockerfile: %w" , err )
105+ }
106+ }
107+
122108 if len (build .Procfile ) != 0 {
123- err := os . WriteFile ( procfile , [] byte ( d . toYamlString ( build .Procfile , 2 )), 0755 )
109+ err := writeProcfileToPath ( d , procfile , build .Procfile , save )
124110 if err != nil {
125111 return fmt .Errorf ("failed to write Procfile: %w" , err )
126112 }
127113 }
128114
129115 if len (build .Dryccfile ) != 0 {
130- err := writeDryccfileToPath (dryccpath , build .Dryccfile )
116+ err := writeDryccfileToPath (d , dryccpath , build .Dryccfile , save )
131117 if err != nil {
132118 return fmt .Errorf ("failed to write Dryccfile: %w" , err )
133119 }
134120 }
135- d .Println ("done" )
121+ if save {
122+ d .Println ("done" )
123+ }
124+ return nil
125+ }
136126
127+ func writeDockerfileToPath (d * DryccCmd , dockerfile string , dockerinfo string , save bool ) error {
128+ if save {
129+ os .Remove (dockerfile )
130+ err := os .WriteFile (dockerfile , []byte (dockerinfo ), 0664 )
131+ return err
132+ }
133+ d .Println ("# Source:" , dockerfile )
134+ d .Println (dockerinfo )
137135 return nil
138136
139137}
140138
141- func writeDryccfileToPath (dryccpath string , dryccfile map [string ]interface {}) error {
139+ func writeProcfileToPath (d * DryccCmd , procfile string , Procinfo map [string ]string , save bool ) error {
140+ if save {
141+ os .Remove (procfile )
142+ err := os .WriteFile (procfile , []byte (d .toYamlString (Procinfo , 2 )), 0664 )
143+ return err
144+ }
145+ d .Println ("# Source:" , procfile )
146+ d .Println (d .toYamlString (Procinfo , 2 ))
147+ return nil
148+ }
149+
150+ func writeDryccfileToPath (d * DryccCmd , dryccpath string , dryccfile map [string ]interface {}, save bool ) error {
142151 // Create the directory if it doesn't exist
152+ if save {
153+ os .Remove (dryccpath )
154+ }
155+ os .ReadDir (dryccpath )
143156 err := os .MkdirAll (dryccpath , os .ModePerm )
144157 if err != nil {
145158 return fmt .Errorf ("failed to create directory: %w" , err )
@@ -161,9 +174,14 @@ func writeDryccfileToPath(dryccpath string, dryccfile map[string]interface{}) er
161174 content += fmt .Sprintf ("%s=%v\n " , k , v )
162175 }
163176 // Write accumulated content once
164- err := os .WriteFile (envFilePath , []byte (content ), 0755 )
165- if err != nil {
166- return fmt .Errorf ("failed to write env file: %w" , err )
177+ if save {
178+ err := os .WriteFile (envFilePath , []byte (content ), 0664 )
179+ if err != nil {
180+ return fmt .Errorf ("failed to write env file: %w" , err )
181+ }
182+ } else {
183+ d .Println ("# Source:" , envFilePath )
184+ d .Println (content )
167185 }
168186 }
169187 }
@@ -179,9 +197,14 @@ func writeDryccfileToPath(dryccpath string, dryccfile map[string]interface{}) er
179197 return fmt .Errorf ("failed to marshal pipeline config: %w" , err )
180198 }
181199 yamlContent := buf .Bytes ()
182- err = os .WriteFile (filePath , yamlContent , 0755 )
183- if err != nil {
184- return fmt .Errorf ("failed to write pipeline file: %w" , err )
200+ if save {
201+ err = os .WriteFile (filePath , yamlContent , 0664 )
202+ if err != nil {
203+ return fmt .Errorf ("failed to write pipeline file: %w" , err )
204+ }
205+ } else {
206+ d .Println ("# Source:" , filePath )
207+ d .Println (string (yamlContent ))
185208 }
186209 }
187210 }
@@ -215,13 +238,13 @@ func buildConfirmAction(c *drycc.Client, appID string, procfileMap map[string]st
215238 return nil
216239}
217240
218- func buildFetchConfirmAction (confirm , procfile , dryccpath string ) error {
241+ func buildFetchConfirmAction (confirm , dockerfile , procfile , dryccpath string , save bool ) error {
219242
220- if confirm == "" || confirm != "yes" {
243+ if save && ( confirm == "" || confirm != "yes" ) {
221244 // hint
222245 msg := fmt .Sprintf (" ! WARNING: Potentially Build Fetch Action\n " +
223- " ! This operation will first rm the current \x1b [1m%s\x1b [0m and \x1b [1m%s\x1b [0m locally\n " +
224- " ! To proceed, type \" yes\" !\n \n > " , procfile , dryccpath )
246+ " ! This operation will overwrite the current \x1b [1m%s\x1b [0m, \x1b [1m%s \x1b [0m or \x1b [1m%s\x1b [0m locally\n " +
247+ " ! To proceed, type \" yes\" !\n \n > " , dockerfile , procfile , dryccpath )
225248
226249 fmt .Print (msg )
227250 fmt .Scanln (& confirm )
0 commit comments