feat(main): Support output directories in template function.
This introduces a new command line flag `--output` (or `-o` for short) which makes it possible to template all specified resource sets into a folder (instead of to stdout) when using `kontemplate template`.
This commit is contained in:
		
							parent
							
								
									3ea3bed7ac
								
							
						
					
					
						commit
						84dcc294bf
					
				
					 1 changed files with 10 additions and 3 deletions
				
			
		
							
								
								
									
										13
									
								
								main.go
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								main.go
									
										
									
									
									
								
							|  | @ -38,8 +38,9 @@ var ( | |||
| 	excludes = app.Flag("exclude", "Resource sets to exclude explicitly").Short('e').Strings() | ||||
| 
 | ||||
| 	// Commands | ||||
| 	template     = app.Command("template", "Template resource sets and print them") | ||||
| 	templateFile = template.Arg("file", "Cluster configuration file to use").Required().String() | ||||
| 	template          = app.Command("template", "Template resource sets and print them") | ||||
| 	templateFile      = template.Arg("file", "Cluster configuration file to use").Required().String() | ||||
| 	templateOutputDir = template.Flag("output", "Output directory in which to save templated files instead of printing them").Short('o').String() | ||||
| 
 | ||||
| 	apply       = app.Command("apply", "Template resources and pass to 'kubectl apply'") | ||||
| 	applyFile   = apply.Arg("file", "Cluster configuration file to use").Required().String() | ||||
|  | @ -100,7 +101,13 @@ func templateCommand() { | |||
| 
 | ||||
| 		for _, r := range rs.Resources { | ||||
| 			fmt.Fprintf(os.Stderr, "Rendered file %s/%s:\n", rs.Name, r.Filename) | ||||
| 			fmt.Println(r.Rendered) | ||||
| 			if *templateOutputDir != "" { | ||||
| 				os.MkdirAll(*templateOutputDir, 0777) | ||||
| 				f, _ := os.Create(*templateOutputDir + "/" + r.Filename) | ||||
| 				fmt.Fprintf(f, r.Rendered) | ||||
| 			} else { | ||||
| 				fmt.Println(r.Rendered) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue