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

Returns a new instance of CommandsHelper.



89
90
91
92
93
# File 'lib/lucie-cmd/commands.rb', line 89

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

Instance Attribute Details

#pwdObject

Returns the value of attribute pwd.



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

def pwd
  @pwd
end

Instance Method Details

#outputObject



118
119
120
# File 'lib/lucie-cmd/commands.rb', line 118

def output
  @output
end

#set(opts = []) ⇒ Object



133
134
135
# File 'lib/lucie-cmd/commands.rb', line 133

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

#sh(*args) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/lucie-cmd/commands.rb', line 95

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

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

  @output = ""

  Open3.popen3("cd \"#{pwd}\" && #{command}") {|stdin, stdout, stderr, wait_thr|
    @pid = wait_thr.pid # pid of the started process.

    if @opts.include? :live_output
      puts stdout.read if !stdout.eof
      @stderr << stderr.read if !stderr.eof
    end
    @output << stdout.read if !stdout.eof
    @output << stderr.read if !stderr.eof

    @status = wait_thr.value # Process::Status object returned.
  }
end

#statusObject



122
123
124
# File 'lib/lucie-cmd/commands.rb', line 122

def status
  @status.exitstatus.to_i % 255
end

#unset(opts = []) ⇒ Object



137
138
139
# File 'lib/lucie-cmd/commands.rb', line 137

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