Class: Sass::Exec::Base

Inherits:
Object
  • Object
show all
Defined in:
.ruby-sass/lib/sass/exec/base.rb

Overview

The abstract base class for Sass executables.

Direct Known Subclasses

SassConvert, SassScss

Direct Known Subclasses

SassConvert, SassScss

Constant Summary

Instance Method Summary (collapse)

Constructor Details

#initialize(args) ⇒ Base

Returns a new instance of Base

Parameters:

  • args (Array<String>)

    The command-line arguments



7
8
9
10
# File '.ruby-sass/lib/sass/exec/base.rb', line 7

def initialize(args)
  @args = args
  @options = {}
end

Constructor Details

#initialize(args) ⇒ Base

Returns a new instance of Base

Parameters:

  • args (Array<String>)

    The command-line arguments



7
8
9
10
# File '.ruby-sass/lib/sass/exec/base.rb', line 7

def initialize(args)
  @args = args
  @options = {}
end

Instance Method Details

#parseObject

Parses the command-line arguments and runs the executable. This does not handle exceptions or exit the program.

See Also:



46
47
48
49
50
51
52
53
# File '.ruby-sass/lib/sass/exec/base.rb', line 46

def parse
  @opts = OptionParser.new(&method(:set_opts))
  @opts.parse!(@args)

  process_result

  @options
end

#parse!Object

Parses the command-line arguments and runs the executable. Calls `Kernel#exit` at the end, so it never returns.

See Also:



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
# File '.ruby-sass/lib/sass/exec/base.rb', line 16

def parse!
  begin
    parse
  rescue Exception => e
    # Exit code 65 indicates invalid data per
    # http://www.freebsd.org/cgi/man.cgi?query=sysexits. Setting it via
    # at_exit is a bit of a hack, but it allows us to rethrow when --trace
    # is active and get both the built-in exception formatting and the
    # correct exit code.
    at_exit {exit Sass::Util.windows? ? 13 : 65} if e.is_a?(Sass::SyntaxError)

    raise e if @options[:trace] || e.is_a?(SystemExit)

    if e.is_a?(Sass::SyntaxError)
      $stderr.puts e.sass_backtrace_str("standard input")
    else
      $stderr.print "#{e.class}: " unless e.class == RuntimeError
      $stderr.puts e.message.to_s
    end
    $stderr.puts "  Use --trace for backtrace."

    exit 1
  end
  exit 0
end

#to_sString

Returns A description of the executable

Returns:

  • (String)

    A description of the executable



56
57
58
# File '.ruby-sass/lib/sass/exec/base.rb', line 56

def to_s
  @opts.to_s
end