Class: Arver::CommandWrapper
- Inherits:
-
Object
- Object
- Arver::CommandWrapper
- Defined in:
- lib/arver/command_wrapper.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arguments_array ⇒ Object
Returns the value of attribute arguments_array.
-
#command ⇒ Object
Returns the value of attribute command.
-
#output ⇒ Object
Returns the value of attribute output.
-
#return_value ⇒ Object
Returns the value of attribute return_value.
Class Method Summary collapse
- .create(cmd, args = []) ⇒ Object
-
.shellescape(str) ⇒ Object
copy from shellwords.rb.
Instance Method Summary collapse
- #escaped_command ⇒ Object
- #execute(input = "") ⇒ Object
- #run(command, input) ⇒ Object
- #shellescape(str) ⇒ Object
- #success? ⇒ Boolean
Instance Attribute Details
#arguments_array ⇒ Object
Returns the value of attribute arguments_array.
3 4 5 |
# File 'lib/arver/command_wrapper.rb', line 3 def arguments_array @arguments_array end |
#command ⇒ Object
Returns the value of attribute command.
3 4 5 |
# File 'lib/arver/command_wrapper.rb', line 3 def command @command end |
#output ⇒ Object
Returns the value of attribute output.
3 4 5 |
# File 'lib/arver/command_wrapper.rb', line 3 def output @output end |
#return_value ⇒ Object
Returns the value of attribute return_value.
3 4 5 |
# File 'lib/arver/command_wrapper.rb', line 3 def return_value @return_value end |
Class Method Details
.create(cmd, args = []) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/arver/command_wrapper.rb', line 5 def self.create( cmd, args = [] ) c = CommandWrapper.new c.command= cmd c.arguments_array= args c end |
.shellescape(str) ⇒ Object
copy from shellwords.rb
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/arver/command_wrapper.rb', line 17 def self.shellescape(str) str = str.to_s # An empty argument will be skipped, so return empty quotes. return "''" if str.empty? str = str.dup # Treat multibyte characters as is. It is caller's responsibility # to encode the string in the right encoding for the shell # environment. str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1") # A LF cannot be escaped with a backslash because a backslash + LF # combo is regarded as line continuation and simply ignored. str.gsub(/\n/, "'\n'") end |
Instance Method Details
#escaped_command ⇒ Object
35 36 37 |
# File 'lib/arver/command_wrapper.rb', line 35 def escaped_command "#{shellescape(command)} " + arguments_array.collect{|c| shellescape(c)}.join(" ") end |
#execute(input = "") ⇒ Object
39 40 41 42 |
# File 'lib/arver/command_wrapper.rb', line 39 def execute( input = "" ) Arver::Log.trace( "** Execute: "+self.escaped_command ) self.run( escaped_command, input ) end |
#run(command, input) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/arver/command_wrapper.rb', line 49 def run( command, input ) if( Arver::RuntimeConfig.instance.test_mode || Arver::RuntimeConfig.instance.dry_run ) self.output= "" self.return_value= 0 else IO.popen( command, "w+") do |pipe| pipe.puts( input ) unless input.empty? pipe.close_write self.output= pipe.read end self.return_value= $?.exitstatus end self.success? end |
#shellescape(str) ⇒ Object
12 13 14 |
# File 'lib/arver/command_wrapper.rb', line 12 def shellescape(str) CommandWrapper.shellescape(str) end |
#success? ⇒ Boolean
45 46 47 |
# File 'lib/arver/command_wrapper.rb', line 45 def success? return_value == 0 end |