Class: Rubu::ShellCommand

Inherits:
Move
  • Object
show all
Defined in:
lib/rubu.rb

Overview

Shell based command.

Instance Attribute Summary

Attributes inherited from Move

#errmsg, #output, #status, #subs

Instance Method Summary collapse

Methods inherited from Move

#display, #error, #host, #host_in, #host_out, #use, #warn

Constructor Details

#initialize(cmd) ⇒ ShellCommand

Returns a new instance of ShellCommand



128
129
130
131
# File 'lib/rubu.rb', line 128

def initialize( cmd )
    super()
    @cmd = cmd
end

Instance Method Details

#runObject

Execution content.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rubu.rb', line 134

def run
    begin
        stdout, stderr, status = Open3.capture3( @cmd ) unless Order[ :noop ]

        if Order[ :verbose ]
            STDOUT.puts @cmd
        end

        unless Order[ :noop ]
            if status.exitstatus == 0
                if Order[ :sh_warn ] && not( stderr.empty? )
                    warn( stderr )
                end
                @status = :success
            else
                @status = :error
                error( stderr )
            end
        end

    rescue

        error( "Invalid command: \"#{@cmd}\"..." )
        @status = :error

    end

    self
end