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:



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

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

def parse!
  # rubocop:disable RescueException
  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
  # rubocop:enable RescueException
end

#to_sString

Returns A description of the executable

Returns:

  • (String)

    A description of the executable



58
59
60
# File '.ruby-sass/lib/sass/exec/base.rb', line 58

def to_s
  @opts.to_s
end