make it possible to call DSL script
This commit is contained in:
parent
2578cd7a6d
commit
9c77ae9d2c
2 changed files with 75 additions and 0 deletions
4
bin/dat
4
bin/dat
|
@ -56,6 +56,10 @@ when :make
|
||||||
puts "making..."
|
puts "making..."
|
||||||
require 'make'
|
require 'make'
|
||||||
Make.command(options)
|
Make.command(options)
|
||||||
|
when :execute
|
||||||
|
puts "Ececuting: #{options.name}"
|
||||||
|
require 'execute'
|
||||||
|
Execute.file(options)
|
||||||
when :goto
|
when :goto
|
||||||
Dir.chdir(ENV["DAT_ROOT"])
|
Dir.chdir(ENV["DAT_ROOT"])
|
||||||
when :vm
|
when :vm
|
||||||
|
|
71
lib/execute.rb
Normal file
71
lib/execute.rb
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
|
||||||
|
module Execute
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
require 'rubygems'
|
||||||
|
require 'ostruct'
|
||||||
|
|
||||||
|
# dat execute progress
|
||||||
|
# dat execute < default Configfile
|
||||||
|
|
||||||
|
module Execute
|
||||||
|
def dependency(name)
|
||||||
|
puts "Checking for #{name}..."
|
||||||
|
|
||||||
|
unless gem_installed?(name)
|
||||||
|
puts "Installing #{name}..."
|
||||||
|
system("gem install #{name}")
|
||||||
|
else
|
||||||
|
puts "#{name} is already installed."
|
||||||
|
end
|
||||||
|
|
||||||
|
require name
|
||||||
|
rescue LoadError => e
|
||||||
|
puts "Failed to load #{name}: #{e.message}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def gem_installed?(name)
|
||||||
|
Gem::Specification::find_all_by_name(name).any?
|
||||||
|
end
|
||||||
|
|
||||||
|
def postgres
|
||||||
|
require 'setup/postgresql'
|
||||||
|
puts 'installing postgres'
|
||||||
|
Setup::PostgreSQL.install
|
||||||
|
end
|
||||||
|
|
||||||
|
def service(name)
|
||||||
|
if block_given?
|
||||||
|
context = OpenStruct.new
|
||||||
|
output = yield context
|
||||||
|
puts output
|
||||||
|
puts "context: #{context}"
|
||||||
|
else
|
||||||
|
puts "No block provided"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def user(name)
|
||||||
|
puts "Creating user: #{name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def install(*packages)
|
||||||
|
packages.each do |pkg|
|
||||||
|
puts "Installing #{pkg}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.file(options)
|
||||||
|
puts "options: #{options}"
|
||||||
|
dsl = Object.new
|
||||||
|
dsl.extend(Execute)
|
||||||
|
# Configfile
|
||||||
|
path = File.join(Dir.pwd, options.name || "./Configfile")
|
||||||
|
dsl.instance_eval(File.read(path), path)
|
||||||
|
# Execute the config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue