lib/poolparty/helpers/optioner.rb in auser-poolparty-1.0.0 vs lib/poolparty/helpers/optioner.rb in auser-poolparty-1.1.1

- old
+ new

@@ -1,33 +1,36 @@ require 'optparse' require "poolparty" require "poolpartycl" -require 'rdoc/usage' +# require 'rdoc/usage' require 'ostruct' require 'date' module PoolParty class Optioner - include Configurable - include MethodMissingSugar + include Dslify + default_options(:verbose => false, + :quiet => false, + :cloudname => false, + :poolname => false) + def initialize(args=[], opts={}, &block) boolean_args << opts[:boolean_args] if opts.has_key?(:boolean_args) - + @arguments = parse_args(args) @extra_help = opts.has_key?(:extra_help) ? opts[:extra_help] : "" @abstract = opts.has_key?(:abstract) ? opts[:abstract] : false @load_pools = opts.has_key?(:load_pools) ? opts[:load_pools] : !@abstract @parse_options = opts.has_key?(:parse_options) ? opts[:parse_options] : true @command = opts.has_key?(:command) ? opts[:command] : false parse_options(&block) if @parse_options - set_default_options self end def daemonizeable - @opts.on('-d', '--daemonize', 'Daemonize starting the cloud') { self.daemon true } + @opts.on('-D', '--daemonize', 'Daemonize starting the cloud') { self.daemon true } end def cloudnames @opts.on('-n cloudname', '--name name', 'Start cloud by this name') { |c| self.cloudname c } end def unflagged_args @@ -61,33 +64,36 @@ i+=1 end args end + # def parent + # self + # end + def parent self end - def set_default_options - self.verbose false - self.quiet false - end - def parse_options(&blk) + self.spec = nil + self.num = nil + progname = $0.include?("-") ? "#{::File.basename($0[/(\w+)-/, 1])} #{::File.basename($0[/-(.*)/, 1])}" : ::File.basename($0) @opts = OptionParser.new + @opts.extend(Dslify) @opts.banner = "Usage: #{progname} #{@abstract ? "[command] " : ""}[options]" @opts.separator "" unless @abstract @opts.separator "Options:" - @opts.on('-v', '--verbose', 'Be verbose') { self.verbose true } - @opts.on('', "--debug", "Debug setting") {self.debugging true} - @opts.on('-s [file]', '--spec-file [file]', 'Set the spec file') { |file| self.spec file.chomp } - @opts.on('-t', '--test', 'Testing mode') { self.testing true } + @opts.on('-v', '--verbose', 'Be verbose') { self.verbose true } + @opts.on('-d', "--debug", "Debug setting") { self.debugging true } + @opts.on('-s [file]', '--spec-file [file]', 'Set the spec file') { |file| self.spec file.chomp } + @opts.on('-t', '--test', 'Testing mode') { self.testing true } blk.call(@opts, self) if blk end @opts.on('-V', '--version', 'Display the version') { output_version ; exit 0 } @@ -101,29 +107,30 @@ process_options output_options if verbose if @load_pools - self.loaded_pool load_pool(self.spec || Binary.get_existing_spec_location) - + self.loaded_pool load_pool( spec? ? spec : Binary.get_existing_spec_location) self.loaded_clouds extract_cloud_from_options(self) self.loaded_pools extract_pool_from_options(self) reject_junk_options! raise CloudNotFoundException.new("Please specify your cloud with -s, move it to ./clouds.rb or in your POOL_SPEC environment variable") unless loaded_clouds && !loaded_clouds.empty? loaded_pools.each do |pl| - pl.configure(self.options) + pl.options(self.options) end loaded_clouds.each do |cl| - cl.configure(self.options) + cl.options(self.options) end end end + def reject_junk_options! %w(loaded_pool cloudname extract_pool_from_options).each do |opt| - @options.delete(opt.to_sym) + @dsl_options.delete(opt.to_sym) end end + def process_options end def output_version puts ::PoolParty::Version \ No newline at end of file