Try 07
This commit is contained in:
parent
80ae7500b3
commit
2810cb2f5f
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue