lib/wire/commands/init_command.rb
# Given a model structure and a target dir, this method
# ensures that targetdir exists and structure contents
# are written to individual files
Given a model structure and a target dir, this method
ensures that targetdir exists and structure contents
are written to individual files
Given a model structure and a target dir this method ensures that targetdir exists and structure contents are written to individual files
def export_model_file(model_data, target_dir)
      puts "Target dir is #{target_dir}"
      if File.exist?(target_dir)
        if File.directory?(target_dir)
          $stdout.puts "Writing output to #{target_dir}"
        else
          $stderr.puts "ERROR: Target dir #{target_dir} exists, " \
                       'but is not a directory.'
          exit Wire.cli_exitcode(:init_dir_error)
        end
      else
        begin
          FileUtils.mkdir_p(target_dir)
        rescue => excpt
          $stderr.puts "ERROR: Unable to create #{target_dir}: #{excpt}"
          exit Wire.cli_exitcode(:init_dir_error)
        end
      end
      [:zones, :networks].each do |element_sym|
        element = model_data[element_sym]
        export_element_file element_sym, element, target_dir
      end
    end
def export_model_file ( model_data , target_dir ) puts "Target dir is #{target_dir}" if File . exist? ( target_dir ) if File . directory? ( target_dir ) $stdout . puts "Writing output to #{target_dir}" else $stderr . puts "ERROR: Target dir #{target_dir} exists, " 'but is not a directory.' exit Wire . cli_exitcode ( :init_dir_error ) end else begin FileUtils . mkdir_p ( target_dir ) rescue => excpt $stderr . puts "ERROR: Unable to create #{target_dir}: #{excpt}" exit Wire . cli_exitcode ( :init_dir_error ) end end [ :zones , :networks ] . each do | element_sym | element = model_data [ element_sym ] export_element_file element_sym , element , target_dir end end
Given a model structure and a target dir, this method
ensures that targetdir exists and structure contents
are written to individual files
Given a model structure and a target dir this method ensures that targetdir exists and structure contents are written to individual files
# ensure target_dir exists
model_data
<not_specific>
target_dir
<not_specific>