Class: Lucie::Commands::CommandsHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/lucie-cmd/commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandsHelper



58
59
60
61
62
# File 'lib/lucie-cmd/commands.rb', line 58

def initialize
  @stderr = $stderr
  @pwd = Dir.pwd
  @opts = []
end

Instance Attribute Details

#pwdObject

Returns the value of attribute pwd.



56
57
58
# File 'lib/lucie-cmd/commands.rb', line 56

def pwd
  @pwd
end

Instance Method Details

#outputObject



84
85
86
# File 'lib/lucie-cmd/commands.rb', line 84

def output
  @output
end

#set(opts = []) ⇒ Object



96
97
98
# File 'lib/lucie-cmd/commands.rb', line 96

def set(opts = [])
  @opts = @opts | opts
end

#sh(*args) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/lucie-cmd/commands.rb', line 64

def sh(*args)
  command = args.join(" ")

  if @opts.include? :show_command
    puts "$ #{command}"
  end

  @status = Open4::popen4("cd \"#{pwd}\" && #{command}") do |pid, stdin, stdout, stderr|
    @stdin, @stderr, @pid = stdin, stderr, pid
    @output = ""
    if !stdout.eof()
      new_content = stdout.read
      if @opts.include? :live_output
        print new_content
      end
      @output << new_content
    end
  end
end

#statusObject



88
89
90
# File 'lib/lucie-cmd/commands.rb', line 88

def status
  @status.exitstatus.to_i % 255
end

#unset(opts = []) ⇒ Object



100
101
102
# File 'lib/lucie-cmd/commands.rb', line 100

def unset(opts = [])
  opts.each { |opt| @opts.delete(opt) }
end