Class: Quadtone::Tool
- Inherits:
-
Object
- Object
- Quadtone::Tool
- Defined in:
- lib/quadtone/tool.rb
Direct Known Subclasses
Quadtone::Tools::AddPrinter, Quadtone::Tools::Characterize, Quadtone::Tools::Chart, Quadtone::Tools::Check, Quadtone::Tools::Dir, Quadtone::Tools::Edit, Quadtone::Tools::Init, Quadtone::Tools::Install, Quadtone::Tools::Linearize, Quadtone::Tools::List, Quadtone::Tools::Print, Quadtone::Tools::PrinterOptions, Quadtone::Tools::Rename, Quadtone::Tools::Render, Quadtone::Tools::Rewrite, Quadtone::Tools::Separate, Quadtone::Tools::Show, Quadtone::Tools::Test
Instance Attribute Summary collapse
-
#profile ⇒ Object
Returns the value of attribute profile.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
Instance Method Summary collapse
-
#load_profile ⇒ Object
subclass can override this to avoid requirement of profile being set.
- #parse_global_option(option, args) ⇒ Object
- #parse_option(option, args) ⇒ Object
- #process_environment ⇒ Object
Instance Attribute Details
#profile ⇒ Object
Returns the value of attribute profile.
7 8 9 |
# File 'lib/quadtone/tool.rb', line 7 def profile @profile end |
#verbose ⇒ Object
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/quadtone/tool.rb', line 8 def verbose @verbose end |
Class Method Details
.process_args(args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |
Instance Method Details
#load_profile ⇒ Object
subclass can override this to avoid requirement of profile being set
55 56 57 |
# File 'lib/quadtone/tool.rb', line 55 def load_profile raise ToolUsageError, "No profile set" unless @profile end |
#parse_global_option(option, args) ⇒ Object
40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
49 50 51 |
# File 'lib/quadtone/tool.rb', line 49 def parse_option(option, args) # overridden by subclass end |