File: sub_command_ui.rb

package info (click to toggle)
ruby-compass 1.0.1~dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,152 kB
  • ctags: 1,795
  • sloc: ruby: 12,901; makefile: 127; perl: 43; xml: 14; sh: 4
file content (51 lines) | stat: -rw-r--r-- 1,273 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'compass/exec/global_options_parser'
require 'compass/exec/project_options_parser'

module Compass::Exec
  class SubCommandUI

    attr_accessor :args

    def initialize(args)
      self.args = args
    end

    def run!
      begin
        return perform!
      rescue Exception => e
        raise e if e.is_a? SystemExit
        if e.is_a?(::Compass::Error) || e.is_a?(OptionParser::ParseError)
          $stderr.puts e.message
        else
          ::Compass::Exec::Helpers.report_error(e, @options || {})
        end
        return 1
      end
    end
    
    protected
    
    def perform!
      $command = args.shift
      command_class = Compass::Commands[$command]
      unless command_class
        args.unshift($command)
        $command = "help"
        command_class = Compass::Commands::Default
      end
      @options = if command_class.respond_to?("parse_#{$command}!")
        command_class.send("parse_#{$command}!", args)
      else
        command_class.parse!(args)
      end
      cmd = command_class.new(Dir.getwd, @options)
      cmd.execute
      cmd.successful? ? 0 : 1
    rescue OptionParser::ParseError => e
      puts "Error: #{e.message}"
      puts command_class.usage if command_class.respond_to?(:usage)
    end
    
  end
end