Sha256: 704b9517096286e72a0339ae45e2a6447c7ca514bf0374dbce3d6adfee08dd06
Contents?: true
Size: 1.29 KB
Versions: 6
Compression:
Stored size: 1.29 KB
Contents
# # Command # module VCSRuby class Command attr_reader :name def initialize name, command @name = name @command = which(command) @available = !!@command end def available? @available end def execute parameter, streams = 0, no_error = false raise "Command '#{name}' not available" unless available? puts "#{@command} #{parameter}" if Configuration.instance.verbose? result = nil if Tools::windows? streams = '2> nul' if streams === 0 result = `cmd /S /C ""#{@command}" #{parameter} #{streams}"` else streams = "2> /dev/null" if streams === 0 result =`"#{@command}" #{parameter} #{streams}` end raise "#{@command} failed with return value '#{$?}'" unless $?.to_i == 0 || no_error return result end private # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby def which cmd exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") if File.executable?(exe) && !File.directory?(exe) return exe end end end return nil end end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
vcs_ruby-1.1.16 | lib/command.rb |
vcs_ruby-1.1.15 | lib/command.rb |
vcs_ruby-1.1.14 | lib/command.rb |
vcs_ruby-1.1.13 | lib/command.rb |
vcs_ruby-1.1.12 | lib/command.rb |
vcs_ruby-1.1.11 | lib/command.rb |