class LadderDrive::CLI

Public Instance Methods

create(name) click to toggle source
# File lib/ladder_drive/cli.rb, line 33
def create(name)
  if File.exist? name
    puts "ERROR: #{name} already exists."
    exit(-1)
  end

  # copy from template file
  root_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
  template_path = File.join(root_dir, "template", "ladder_drive")
  cp_r template_path, name

  # copy plc directory
  temlate_plc_path = File.join(root_dir, "lib", "plc")
  cp_r temlate_plc_path, name
  # remove unnecessary file from plc directory
  %w(plc.rb emulator).each do |fn|
    rm_r File.join(name, "plc", fn)
  end
  puts "#{name} was successfully created."
end
plugin(name) click to toggle source
# File lib/ladder_drive/cli.rb, line 55
def plugin(name)
  root_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))

  # copy plugin
  plugins_dir = File.join(root_dir, "plugins")
  plugin_path = File.join(plugins_dir, "#{name}_plugin.rb")
  if File.exist? plugin_path
    mkdir_p "plugins"
    cp plugin_path, "plugins/#{name}_plugin.rb"
  end

  # copy sample settings
  config_dir = File.join(plugins_dir, "config")
  config_path = File.join(config_dir, "#{name}.yaml.example")
  if File.exist? config_path
    dst_dir = "config/plugins"
    mkdir_p dst_dir
    dst_path = "config/plugins/#{name}.yaml.example"
    cp config_path, dst_path unless File.exist? dst_path
  end
end