-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow template to be a whole directory #57
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the README with details on how this work? If a dir is passed in, does it just create the new generated file in the dest dir using the name of file in the src dir as the template?
@jwilder just updated the README. |
@jwilder is there still something missing for this PR to be merged? |
I am also loking for this feature simply because i have sites_enabled in my nginx, and everyone of them i need to transform into a template. Glad there is PR already. |
@jwilder would love to get some feedback. |
@jwilder I have updated the README, as you asked me to do. how do you want me to proceed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@breml Sorry for the long delay. A few small nits, but otherwise looks good.
log.Fatalf("unable to stat %s, error: %s", template, err) | ||
} | ||
if fi.IsDir() { | ||
if dest != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this whole block L241-L262 to a separate func like generateDir
?
|
||
for _, file := range files { | ||
if dest == "" { | ||
generateFile(template+string(os.PathSeparator)+file.Name(), "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use filepath.Join(template, file.Name)
here
if dest == "" { | ||
generateFile(template+string(os.PathSeparator)+file.Name(), "") | ||
} else { | ||
generateFile(template+string(os.PathSeparator)+file.Name(), dest+string(os.PathSeparator)+file.Name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: file path.Join(...)
for these.
Use filepath.Join Implement review feedback from jwilder
@jwilder just implemented your suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Thanks @breml! |
Use-case: process complete conf.d directories without the need to list every file separately.