Class: Lucie::Commands::CommandsHelper
- Inherits:
-
Object
- Object
- Lucie::Commands::CommandsHelper
- Defined in:
- lib/lucie-cmd/commands.rb
Instance Attribute Summary collapse
-
#pwd ⇒ Object
Returns the value of attribute pwd.
Instance Method Summary collapse
-
#initialize ⇒ CommandsHelper
constructor
A new instance of CommandsHelper.
- #output ⇒ Object
- #set(opts = []) ⇒ Object
- #sh(*args) ⇒ Object
- #status ⇒ Object
- #unset(opts = []) ⇒ Object
Constructor Details
#initialize ⇒ CommandsHelper
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
#pwd ⇒ Object
Returns the value of attribute pwd.
87 88 89 |
# File 'lib/lucie-cmd/commands.rb', line 87 def pwd @pwd end |
Instance Method Details
#output ⇒ Object
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 |
#status ⇒ Object
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 |