Skip to content

Commit

Permalink
Issue RiotGamesMinions#32 - Use mixlib-shellout for a better time she…
Browse files Browse the repository at this point in the history
…lling out
  • Loading branch information
Pairing committed Feb 24, 2014
1 parent 18e4fc9 commit 085c591
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
25 changes: 8 additions & 17 deletions lib/thor-scmversion/shell_utils.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
require 'mixlib/shellout'

module ThorSCMVersion
class ShellUtils
class << self
def secure_password
password = String.new

while password.length < 20
password << ::OpenSSL::Random.random_bytes(1).gsub(/\W/, '')
end
password
end

def sh(cmd, dir = '.', &block)
out, code = sh_with_excode(cmd, dir, &block)
code == 0 ? out : raise(out.empty? ? "Running `#{cmd}` failed. Run this command directly for more detailed output." : out)
end

def sh_with_excode(cmd, dir = '.', &block)
cmd << " 2>&1"
output = ""
status = nil
Dir.chdir(dir) {
stdin, stdout, stderr, wait_thr = Open3::popen3(cmd)

status = wait_thr.value
output = stdout.readlines.join

if status.to_i == 0
block.call(output) if block
end
}
[ output, status ]
def sh_with_excode(cmd, dir = '.', &block)
command = Mixlib::ShellOut.new(cmd << " 2>&1", :cwd => dir)
command.run_command
[command.stdout, command.exitstatus]
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion thor-scmversion.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = ThorSCMVersion::VERSION

gem.add_dependency 'thor'
gem.add_dependency 'thor'
gem.add_dependency 'mixlib-shellout'

gem.add_development_dependency 'webmock'
gem.add_development_dependency 'geminabox'
gem.add_development_dependency 'spork'
Expand Down

0 comments on commit 085c591

Please sign in to comment.