Skip to content

Commit

Permalink
(PDK-577) Add info line that task metadata was also generated
Browse files Browse the repository at this point in the history
```
david@davids:~/git/pdk/foo$ ~/git/pdk/bin/pdk new task bar2
pdk (INFO): Creating '/home/david/git/pdk/foo/tasks/bar2.sh' from template.
pdk (INFO): Creating '/home/david/git/pdk/foo/tasks/bar2.json' from template.
david@davids:~/git/pdk/foo$
```
  • Loading branch information
DavidS committed Oct 6, 2017
1 parent 7efeb47 commit 5aa5846
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
23 changes: 22 additions & 1 deletion lib/pdk/generators/puppet_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,29 @@ def run
#
# @api private
def render_file(dest_path, template_path, data)
write_file(dest_path) do
PDK::TemplateFile.new(template_path, data).render
end
end

# Write the result of the block to disk.
#
# @param dest_path [String] The path that the rendered file should be
# written to. Any necessary directories will be automatically created.
# @param &block [String] The content to be written
#
# @raise [PDK::CLI::FatalError] if the parent directories to `dest_path`
# do not exist and could not be created.
# @raise [PDK::CLI::FatalError] if the rendered file could not be written
# to `dest_path`.
#
# @return [void]
#
# @api private
def write_file(dest_path)
PDK.logger.info(_("Creating '%{file}' from template.") % { file: dest_path })
file_content = PDK::TemplateFile.new(template_path, data).render

file_content = yield

begin
FileUtils.mkdir_p(File.dirname(dest_path))
Expand Down
9 changes: 4 additions & 5 deletions lib/pdk/generators/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ def check_if_task_already_exists
#
# @api private
def write_task_metadata
task_metadata = template_data.dup
task_metadata.delete(:name)

File.open(File.join(module_dir, 'tasks', "#{task_name}.json"), 'w') do |f|
f.write(JSON.pretty_generate(task_metadata))
write_file(File.join(module_dir, 'tasks', "#{task_name}.json")) do
task_metadata = template_data.dup
task_metadata.delete(:name)
JSON.pretty_generate(task_metadata)
end
end

Expand Down

0 comments on commit 5aa5846

Please sign in to comment.