lib/blender/cli/mix.rb in server-blender-0.0.14 vs lib/blender/cli/mix.rb in server-blender-0.0.15
- old
+ new
@@ -1,89 +1,89 @@
-def parse_options
- options = {}
- opts = OptionParser.new do |opts|
- opts.banner = "Usage: blender mix [OPTIONS] [DIR] HOST"
- opts.separator "Options:"
+require 'blender/cli'
- opts.on("-r", "--recipe RECIPE", "if RECIPE is not specified blender will first look for <directory_name>.rb and then for blender-recipe.rb") do |val|
- options[:recipe] = val
- end
+class Blender::Cli::Mix < Blender::Cli
- opts.on("-N", "--node NODE", "force NODE as the current nodename") do |val|
- options[:node] = val
- end
+ def parse_options(args)
+ options = {}
+ opts = OptionParser.new do |opts|
+ opts.banner = "Usage: blender mix [OPTIONS] [DIR] HOST"
+ opts.separator "Options:"
- opts.on("-R", "--roles ROLES", "comma delimited list of roles that should execute") do |val|
- options[:roles] = val
- end
+ opts.on("-r", "--recipe RECIPE", "if RECIPE is not specified blender will first look for <directory_name>.rb and then for blender-recipe.rb") do |val|
+ options[:recipe] = val
+ end
- opts.separator ""
- opts.separator "Common options:"
+ opts.on("-N", "--node NODE", "force NODE as the current nodename") do |val|
+ options[:node] = val
+ end
- opts.on("-h", "--help", "Show this message") do
- raise(opts.to_s)
- end
+ opts.on("-R", "--roles ROLES", "comma delimited list of roles that should execute") do |val|
+ options[:roles] = val
+ end
- opts.separator ""
- opts.separator "Notes:"
- opts.separator ' "." used if DIR not specified'
+ opts.separator ""
+ opts.separator "Common options:"
- end
- opts.parse!
+ opts.on("-h", "--help", "Show this message") do
+ raise(opts.to_s)
+ end
- options[:usage] = opts.to_s
+ opts.separator ""
+ opts.separator "Notes:"
+ opts.separator ' "." used if DIR not specified'
- dir = ARGV.shift
- host = ARGV.shift
- raise("unexpected: #{ARGV*" "}\n#{opts}") unless ARGV.empty?
+ end
+ opts.parse!(args)
- if host.nil?
- host = dir
- dir = "."
- end
+ options[:usage] = opts.to_s
- raise(opts.to_s) unless dir && host
+ dir = args.shift
+ host = args.shift
+ raise("unexpected: #{args*" "}\n#{opts}") unless args.empty?
- raise("#{dir} is not a directory\n#{opts}") unless File.directory?(dir)
+ if host.nil?
+ host = dir
+ dir = "."
+ end
- options.merge(:dir => dir, :host => host)
-end
+ raise(opts.to_s) unless dir && host
+ raise("#{dir} is not a directory\n#{opts}") unless File.directory?(dir)
-def find_recipe(options)
- # check for recipe, recipe.rb, directory_name.rb, and default.rb
- recipes = []
- if rname = options[:recipe]
- recipes << rname << "#{rname}.rb"
+ options.merge(:dir => dir, :host => host)
end
- recipes << "#{File.basename(File.expand_path(options[:dir]))}.rb" << "blender-recipe.rb"
- recipe = recipes.detect {|r| File.file?(File.join(options[:dir], r))} ||
- raise("recipe not found (looking for #{recipes * ' '})\n#{options[:usage]}")
-end
-def run(*cmd)
- STDERR.puts ">> #{cmd * ' '}"
- system(*cmd)
-end
+ def find_recipe(options)
+ # check for recipe, recipe.rb, directory_name.rb, and blender-recipe.rb
+ if rname = options[:recipe]
+ recipes = [rname, "#{rname}.rb"]
+ else
+ recipes = ["#{File.basename(File.expand_path(options[:dir]))}.rb", "blender-recipe.rb"]
+ end
+ recipe = recipes.detect {|r| File.file?(File.join(options[:dir], r))} ||
+ raise("recipe not found (looking for #{recipes * ' '})\n#{options[:usage]}")
+ end
-def run_recipe(recipe, options)
- run "cat #{File.expand_path("files/init.sh", Blender::ROOT)} | ssh #{options[:host]} /bin/bash -l" or raise("failed init.sh")
+ def run_recipe(recipe, options)
+ run "cat #{File.expand_path("files/init.sh", Blender::ROOT)} | ssh #{options[:host]} /bin/bash -l" or raise("failed init.sh")
- run("rsync -qazP --delete --exclude '.*' #{options[:dir]}/ #{options[:host]}:/var/lib/blender/recipes") or raise("failed rsync")
+ run("rsync -qazP --delete --exclude '.*' #{options[:dir]}/ #{options[:host]}:/var/lib/blender/recipes") or raise("failed rsync")
- env_config = "RECIPE=#{recipe}"
- env_config << " NODE=#{options[:node]}" if options[:node]
- env_config << " ROLES=#{options[:roles]}" if options[:roles]
+ env_config = "RECIPE=#{recipe}"
+ env_config << " NODE=#{options[:node]}" if options[:node]
+ env_config << " ROLES=#{options[:roles]}" if options[:roles]
- run "cat #{File.expand_path("files/mix.sh", Blender::ROOT)} | ssh #{options[:host]} #{env_config} /bin/bash -l" or raise("failed mix.sh")
-end
+ run "cat #{File.expand_path("files/mix.sh", Blender::ROOT)} | ssh #{options[:host]} #{env_config} /bin/bash -l" or raise("failed mix.sh")
+ end
-def main
- options = parse_options
- recipe = find_recipe(options)
- run_recipe(recipe, options)
+ def execute
+ options = parse_options(@args)
+ recipe = find_recipe(options)
+ run_recipe(recipe, options)
-rescue => e
- abort(e.to_s)
+ rescue => e
+ abort(e.to_s)
+ end
+
end