Skip to content

Commit

Permalink
Merge pull request #16 from skylerto/cleanup
Browse files Browse the repository at this point in the history
conditional logging
  • Loading branch information
skylerto committed May 2, 2018
2 parents 6cbec88 + ffba619 commit b13b86f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ sudo: true
language: ruby
rvm:
- 2.5.0
env:
- USE_SUDO: true
before_install:
- gem install bundler -v 1.16.1
- bundle install
Expand Down
29 changes: 20 additions & 9 deletions lib/litterbox/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,37 @@ module Litterbox
# CLI Command operations
class Command
attr_accessor :stdout, :stderr, :process
def initialize(cmd)
def initialize(cmd, log = ENV['LITTERBOX_LOG'])
@cmd = cmd
@cmd = "sudo #{@cmd}" if ENV['USE_SUDO']
@stdout = ''
@stderr = ''
@log = log
end

def run_command
Open3.popen3(@cmd) do |_, out, err, thr|
while (line = err.gets)
@stderr << line unless line.nil?
puts(line)
end
while (lines = out.gets)
@stdout << lines unless lines.nil?
puts(lines)
end
capture_stderr err
capture_stdout out
@process = thr.value
return @stdout, @stderr, @process
end
end

private

def capture_stderr(err)
while (line = err.gets)
@stderr << line unless line.nil?
puts(line) if @log
end
end

def capture_stdout(out)
while (lines = out.gets)
@stdout << lines unless lines.nil?
puts(lines) if @log
end
end
end
end

0 comments on commit b13b86f

Please sign in to comment.