class Quadtone::Tool
Attributes
profile[RW]
verbose[RW]
Public Class Methods
process_args(args)
click to toggle source
# File lib/quadtone/tool.rb, line 10 def self.process_args(args) begin name = args.shift or raise ToolUsageError, "No subcommand specified" klass_name = 'Quadtone::Tools::' + name.split('-').map { |p| p.capitalize }.join begin klass = Kernel.const_get(klass_name) raise NameError unless klass.respond_to?(:process_args) rescue NameError => e raise ToolUsageError, "Unknown subcommand specified: #{name.inspect} (#{klass_name})" end tool = klass.new tool.process_environment tool.load_profile while args.first && args.first[0] == '-' option = args.shift tool.parse_global_option(option, args) or tool.parse_option(option, args) or raise ToolUsageError, "Unknown option for #{name.inspect} tool: #{option}" end tool.run(*args) rescue ToolUsageError => e warn e exit 1 end end
Public Instance Methods
load_profile()
click to toggle source
subclass can override this to avoid requirement of profile being set
# File lib/quadtone/tool.rb, line 55 def load_profile raise ToolUsageError, "No profile set" unless @profile end
parse_global_option(option, args)
click to toggle source
# File lib/quadtone/tool.rb, line 40 def parse_global_option(option, args) case option when '--verbose' @verbose = true when '--profile' @profile = Profile.load(args.shift) end end
parse_option(option, args)
click to toggle source
# File lib/quadtone/tool.rb, line 49 def parse_option(option, args) # overridden by subclass end
process_environment()
click to toggle source
# File lib/quadtone/tool.rb, line 34 def process_environment if (profile_name = ENV['PROFILE']) @profile = Profile.load(profile_name) end end