diff --git a/cmd/bootstraper/main.go b/cmd/bootstraper/main.go index 150f28f..68f0732 100644 --- a/cmd/bootstraper/main.go +++ b/cmd/bootstraper/main.go @@ -10,6 +10,7 @@ func main() { var args struct { Config string `arg:"-c,--config,env:CONFIG" help:"Configuration values file or directory path" default:"./data/config"` TemplateDirectory string `arg:"-t,--template-dir,env:TEMPLATE_DIR" help:"Template directory path" default:"./data/templates"` + RootDirectory string `arg:"-r,--root-dir,env:ROOT_DIR" help:"Generate files with this root instead of /" default:"/"` } arg.MustParse(&args) @@ -20,7 +21,7 @@ func main() { if err != nil { panic(err) } - if err = hostConfig.ManageServices(); err != nil { + if err = hostConfig.ManageServices(args.RootDirectory); err != nil { panic(err) } } diff --git a/pkg/templater/main.go b/pkg/templater/main.go index b918772..e390e3a 100644 --- a/pkg/templater/main.go +++ b/pkg/templater/main.go @@ -75,9 +75,9 @@ func (tc *TemplaterConfig) New(confpath string, templateDir string) error { return nil } -func (tc *TemplaterConfig) ManageServices() error { +func (tc *TemplaterConfig) ManageServices(rootDir string) error { for _, svr := range tc.Services { - if err := svr.Manage(tc.TemplateDirectory); err != nil { + if err := svr.Manage(tc.TemplateDirectory, rootDir); err != nil { return err } } diff --git a/pkg/templater/services.go b/pkg/templater/services.go index d1e3135..bca11cb 100644 --- a/pkg/templater/services.go +++ b/pkg/templater/services.go @@ -41,7 +41,7 @@ func (s *Service) manageRepos(repos map[string]Repository) error { return nil } -func (s *Service) Manage(templateDir string) error { +func (s *Service) Manage(templateDir string, rootDir string) error { // Manage packages repositories log.Printf("Managing package repositories") @@ -61,7 +61,7 @@ func (s *Service) Manage(templateDir string) error { } log.Printf("Generating configuration files\n") - err = processConfigFiles(s.ConfigFiles, s.Vars, templateDir) + err = processConfigFiles(s.ConfigFiles, s.Vars, templateDir, rootDir) if err != nil { return fmt.Errorf("ProcessingTemplatesFailed with error: %v", err) } @@ -76,7 +76,7 @@ func (s *Service) Manage(templateDir string) error { return nil } -func processConfigFiles(tpls []ConfigFile, variables map[string]interface{}, templateDir string) error { +func processConfigFiles(tpls []ConfigFile, variables map[string]interface{}, templateDir string, rootDir string) error { values, err := json.Marshal(variables) if err != nil { return fmt.Errorf("Error unmarshaling values on template process; %v", err)