This commit is contained in:
Philippe Caseiro 2022-06-30 10:10:26 +02:00
parent 80ae7500b3
commit 2810cb2f5f
3 changed files with 7 additions and 6 deletions

View File

@ -10,6 +10,7 @@ func main() {
var args struct { var args struct {
Config string `arg:"-c,--config,env:CONFIG" help:"Configuration values file or directory path" default:"./data/config"` 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"` 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) arg.MustParse(&args)
@ -20,7 +21,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if err = hostConfig.ManageServices(); err != nil { if err = hostConfig.ManageServices(args.RootDirectory); err != nil {
panic(err) panic(err)
} }
} }

View File

@ -75,9 +75,9 @@ func (tc *TemplaterConfig) New(confpath string, templateDir string) error {
return nil return nil
} }
func (tc *TemplaterConfig) ManageServices() error { func (tc *TemplaterConfig) ManageServices(rootDir string) error {
for _, svr := range tc.Services { for _, svr := range tc.Services {
if err := svr.Manage(tc.TemplateDirectory); err != nil { if err := svr.Manage(tc.TemplateDirectory, rootDir); err != nil {
return err return err
} }
} }

View File

@ -41,7 +41,7 @@ func (s *Service) manageRepos(repos map[string]Repository) error {
return nil return nil
} }
func (s *Service) Manage(templateDir string) error { func (s *Service) Manage(templateDir string, rootDir string) error {
// Manage packages repositories // Manage packages repositories
log.Printf("Managing package repositories") log.Printf("Managing package repositories")
@ -61,7 +61,7 @@ func (s *Service) Manage(templateDir string) error {
} }
log.Printf("Generating configuration files\n") log.Printf("Generating configuration files\n")
err = processConfigFiles(s.ConfigFiles, s.Vars, templateDir) err = processConfigFiles(s.ConfigFiles, s.Vars, templateDir, rootDir)
if err != nil { if err != nil {
return fmt.Errorf("ProcessingTemplatesFailed with error: %v", err) return fmt.Errorf("ProcessingTemplatesFailed with error: %v", err)
} }
@ -76,7 +76,7 @@ func (s *Service) Manage(templateDir string) error {
return nil 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) values, err := json.Marshal(variables)
if err != nil { if err != nil {
return fmt.Errorf("Error unmarshaling values on template process; %v", err) return fmt.Errorf("Error unmarshaling values on template process; %v", err)