File: default.rb

package info (click to toggle)
ruby-compass 1.0.3~dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,184 kB
  • ctags: 1,789
  • sloc: ruby: 12,904; makefile: 100; perl: 43; xml: 14; sh: 4
file content (50 lines) | stat: -rw-r--r-- 1,336 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
module Compass
  module Commands
    module DefaultOptionsParser
      def set_options(opts)
        opts.on("--trace") do
          self.options[:trace] = true
        end
        opts.on("-?", "-h", "--help") do
          self.options[:command] = Proc.new do
            Help.new(working_path, options.merge(:help_command => "help"))
          end
        end
        opts.on("-q", "--quiet") do
          self.options[:quiet] = true
        end
        opts.on("-v", "--version") do
          self.options[:command] = Proc.new do
            PrintVersion.new(working_path, options)
          end
        end
        super
      end
    end
    class Default < Base
      
      class << self
        def option_parser(arguments)
          parser = Compass::Exec::CommandOptionParser.new(arguments)
          parser.extend(DefaultOptionsParser)
        end
        # def usage
        #   $stderr.puts caller.join("\n")
        #   "XXX"
        # end
        def parse!(arguments)
          parser = option_parser(arguments)
          parser.parse!
          parser.options[:command] ||= Proc.new do
            Help.new(working_path, options.merge(:help_command => "help"))
          end
          parser.options
        end
      end

      def execute
        instance_eval(&options[:command]).execute
      end
    end
  end
end