Module Tap::Utils
In: lib/tap/utils.rb

Windows

MSDOS has command line length limits specific to the version of Windows being run (from www.ss64.com/nt/cmd.html):

Windows NT:256 characters
Windows 2000:2046 characters
Windows XP:8190 characters

Commands longer than these limits fail, usually with something like: ‘the input line is too long‘

Methods

set_env   sh   sh_escape   shellsplit   with_env  

Public Instance methods

Sets the specified ENV variables and returns the current env. If replace is true, current ENV variables are replaced; otherwise the new env variables are simply added to the existing set.

[Source]

    # File lib/tap/utils.rb, line 38
38:     def set_env(env={}, replace=false)
39:       current_env = {}
40:       ENV.each_pair do |key, value|
41:         current_env[key] = value
42:       end
43:       
44:       ENV.clear if replace
45:       
46:       env.each_pair do |key, value|
47:         if value.nil?
48:           ENV.delete(key)
49:         else
50:           ENV[key] = value
51:         end
52:       end if env
53:       
54:       current_env
55:     end

Run the command with system and raise an error if it fails.

[Source]

    # File lib/tap/utils.rb, line 79
79:     def sh(*cmd)
80:       system(*cmd) or raise "Command failed with status (#{$?.exitstatus}): [#{cmd.join(' ')}]"
81:     end

[Source]

    # File lib/tap/utils.rb, line 74
74:     def sh_escape(str)
75:       str.to_s.gsub("'", "\\\\'").gsub(";", '\\;')
76:     end

[Source]

    # File lib/tap/utils.rb, line 19
19:     def shellsplit(line, comment="#")
20:       words = []
21:       field = ''
22:       line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do
23:         |word, sq, dq, esc, garbage, sep|
24:         raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage
25:         break if word == comment
26:         field << (word || sq || (dq || esc).gsub(/\\(?=.)/, ''))
27:         if sep
28:           words << field
29:           field = ''
30:         end
31:       end
32:       words
33:     end

Sets the specified ENV variables for the duration of the block. If replace is true, current ENV variables are replaced; otherwise the new env variables are simply added to the existing set.

Returns the block return.

[Source]

    # File lib/tap/utils.rb, line 62
62:     def with_env(env={}, replace=false)
63:       current_env = nil
64:       begin
65:         current_env = set_env(env, replace)
66:         yield
67:       ensure
68:         if current_env
69:           set_env(current_env, true)
70:         end
71:       end
72:     end

[Validate]