Commit dc74dacd authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Print filename warnings under windows using backslashes.

Internally UNIX style filenames are always used, but for printing
out it makes sense to use the platform-specific notation.

Added small helper class to detect OS.
parent f77e2894
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
require 'singleton'
require 'jsduck/os'

module JsDuck

@@ -28,7 +29,13 @@ module JsDuck
    #
    # Optionally filename and line number will be inserted to message.
    def warn(msg, filename=nil, line=0)
      msg = filename ? "#{filename}:#{line}:Warning: #{msg}" : "Warning: #{msg}"
      if filename
        filename.gsub!('/', '\\') if OS::windows?
        msg = "#{filename}:#{line}:Warning: #{msg}"
      else
        msg = "Warning: #{msg}"
      end

      if @warnings && !@shown_warnings[msg]
        $stderr.puts msg
        @shown_warnings[msg] = true

lib/jsduck/os.rb

0 → 100644
+11 −0
Original line number Diff line number Diff line
require 'rbconfig'

module JsDuck

  # Simple helper class to detect operating system
  class OS
    def self.windows?
      RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
    end
  end
end