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.
70 71 72 73 74 |
# File 'lib/lucie-cmd/commands.rb', line 70 def initialize @stderr = $stderr @pwd = Dir.pwd @opts = [] end |
Instance Attribute Details
#pwd ⇒ Object
Returns the value of attribute pwd.
68 69 70 |
# File 'lib/lucie-cmd/commands.rb', line 68 def pwd @pwd end |
Instance Method Details
#output ⇒ Object
96 97 98 |
# File 'lib/lucie-cmd/commands.rb', line 96 def output @output end |
#set(opts = []) ⇒ Object
108 109 110 |
# File 'lib/lucie-cmd/commands.rb', line 108 def set(opts = []) @opts = @opts | opts end |
#sh(*args) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/lucie-cmd/commands.rb', line 76 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 |
#status ⇒ Object
100 101 102 |
# File 'lib/lucie-cmd/commands.rb', line 100 def status @status.exitstatus.to_i % 255 end |
#unset(opts = []) ⇒ Object
112 113 114 |
# File 'lib/lucie-cmd/commands.rb', line 112 def unset(opts = []) opts.each { |opt| @opts.delete(opt) } end |